aspose file tools*
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 Spring in Action 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
Author

Getting selected values from Struts combo box

Josue Ramirez
Greenhorn

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"
class="com.anmex.javabeans.LlenaComboExamenes"
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++) {
if(fillCombo.getRows()[i0].getEXAM_EXAID().toString().equals(retexamen)){
%>
<html ption value="<%=fillCombo.getRows()[i0].getEXAID().toString()%>">
<%=fillCombo.getRows()[i0].getEXADSC().toString()%>
</html ption>
<%}
else{%>
<html ption value="<%=fillCombo.getRows()[i0].getEXAID().toString()%>">
<%=fillCombo.getRows()[i0].getEXADSC().toString()%>
</html ption>
<%}
}
}%>
</html:select></TD>

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
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Josue,
Welcome to JavaRanch!

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting selected values from Struts combo box