• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auto selecting value in dropdown using JSTL

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
<html:option value="0"> </html:option>
<c:forEach var="paymentType" items="${paymentFrequencies}">
<html:option value="${paymentType.paymentFrequencyID}">${paymentType.paymentFrequencyDesc}</html:option>
</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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic