Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting selected values from Struts combo box

 
Josue Ramirez
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josue,
Welcome to JavaRanch!

The options exist for Struts equivalent to those in HTML. You can see them documented in the Struts reference.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic