aspose file tools*
The moose likes Struts and the fly likes Auto selecting value in dropdown using JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Auto selecting value in dropdown using JSTL" Watch "Auto selecting value in dropdown using JSTL" New topic
Author

Auto selecting value in dropdown using JSTL

sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Hi all,

I am using JSTL for displaying the dropdown. After selecting value, I am saving selected value in dropdown. When I retrieve it from the data base, I need to auto select that value from could someone help please. Thanks.

<html:select property="paymentFrequency">
<htmlption value="0"> </htmlption>
<c:forEach var="paymentType" items="${paymentFrequencies}">
<htmlption value="${paymentType.paymentFrequencyID}">${paymentType.paymentFrequencyDesc}</htmlption>
</c:forEach>
</html:select>

Ex: value =1 display value is "Monthly". So from the databse if the value I am geting as 1, I need to auto populate that value in the dropdown.

Thanks.
Sudhakar
Rudy Gireyev
Ranch Hand

Joined: May 03, 2011
Posts: 39
There are several ways of accomplishing preselection of a row in STRUTS. It looks like the option you have chosen is to loop through your Collection yourself and build your select box manually. In this case you have to place the conditional statement, which I believe is another logic tag, that tests whether the value you'd like to preselect has been reached in the loop, and if so you'll have to output the option line with the selected attribute set.

Other options are using the the html:options or html:optionsCollection STRUTS tags and using their api to preselect the value for you.
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Thanks Rudy. Actually I did not change anny code in jsp. I just passed the value from the database and JSTL took care of pre-selecting.

Note : I have a conditional statement in FormBean.

Thanks
Sudhakar
 
Don't get me started about those stupid light bulbs.
 
subject: Auto selecting value in dropdown using JSTL
 
Similar Threads
how to get both value and text of selected item in action class
JSTL conversion for struts 1.1 code
DynaValidatorActionForm not working
Error in printing arraylist using jstl
I need a simple drop down list of numbers