tags:

views:

145

answers:

1

Hi everyone,

In my JSP I have a dropdownlist and a submit button when clicking the submit button I lose the value already selected in my list. I am using the jstl because i need to construct other table corresponding the value selected in my list.For that I must call a submit button but the problem; it reset the value selected

I want to know if there is a way to save the value selected in my list even I click a submit button. I work with JSP and eclipse environment.
Thank you for your help.

+1  A: 

You need to preset the inputs with the request parameter values. You can access parameter values in EL by ${param.name}. In case of dropdowns rendered by HTML <select> element, you need to set the selected attribute of the HTML <option> element in question. You can make use of the ternary operator in EL to print the selected attribute whenever the option value matches the request parameter value.

Basic example:

<select name="foo">
   <c:forEach items="${options}" var="option">
       <option ${param.foo == option ? 'selected' : ''}>${option}</option>
   </c:forEach>
</select>
BalusC
the problem I found is exactly in the attribut items of the tag forEach because I use a class java to build my options dynamicallyso I have not the options from the begining to put them in the items I tried the following:<c:forEach items='<%HtmlListActivityConstruct h=new HtmlListActivityConstruct();%> <%=h.ConstructListActivity("Activity","SELECT from Activityopc activityopc".toString()) %>' var="option">but it doesn't work.Thanks
kawtousse
so I found myself writing java code in the items attribute.and this provoques many problems when running.
kawtousse
I've posted many answers on your questions before how to use a servlet to preprocess a request for a JSP. Reread them. http://stackoverflow.com/questions/2682069/from-servlet-to-jsp, http://stackoverflow.com/questions/2577918/how-to-send-httpservletresponse-in-the-printwriter-having-an-html-structure-to-a, etc. You don't seem to actually learn from them. Try to work on that as well. I suggest to forget about this all and concentrate you on actually **learning and understanding** how the stuff works. This is a good starting point: http://courses.coreservlets.com/Course-Materials/csajsp2.html
BalusC