It's not a secret anymore!
The moose likes Struts and the fly likes Getting selected values from Struts combo box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting selected values from Struts combo box" Watch "Getting selected values from Struts combo box" New topic

Getting selected values from Struts combo box

Josue Ramirez

Joined: Jul 07, 2006
Posts: 1
Hello everybody.

I have a JSP to get 2 input data, one field is a combo and other is a text.

I fill the combo through a javabean:

<jsp:useBean id="fillCombo" scope="session"
type="com.anmex.javabeans.LlenaComboExamenes" />

<html:form action="/SearchEvaluation">

<%/* Manda ejecutarse el bean que trae los cursos */%>
<%llenaComboExamenesBean.execute("", "");%>

<html:select property="examen">
<html ption value="">SELECCIONE UN CURSO DE LA LISTA</html ption>
<%if (fillCombo.getRows()!= null) {
for (int i0=0; i0<fillCombo.getRows().length; i0++) {
<html ption value="<%=fillCombo.getRows()[i0].getEXAID().toString()%>">
</html ption>
<html ption value="<%=fillCombo.getRows()[i0].getEXAID().toString()%>">
</html ption>

After submit the form to validate data, i return back to the same page for show the errors founded into FormBean or ActionForm...

Also, i return back the values to the JSP from ActionForm with the initial values, all it's rigth, but as you can see, into the JSP i separated the options SELECTED and all others, to be able to show the selected values when the JSP is showed again.

How can i tell to Struts tags, wich one option was selected since the first send.

I mean, do exist some attribute for Struts tag <html ption> like selected for <OPTION> HTML tag???

Thanks a lot.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32815

Welcome to JavaRanch!

The options exist for Struts equivalent to those in HTML. You can see them documented in the Struts reference.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Checking the "Disable smilies in this post" checkbox and surrounding your code with a code block will make it much easier to read.

I cannot quite tell exactly what you are doing with all the Javascript code, but I think it is not needed. If examen is a property on your form, then whatever option value with the matching id will be selected for you. This is all handled by the html tags. Check out the html: optionsCollection tag. Your code might just need to look like this:

- Brent
I agree. Here's the link:
subject: Getting selected values from Struts combo box
jQuery in Action, 3rd edition