This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes how to preselect value in dropdownlist in jsp struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to preselect value in dropdownlist in jsp struts" Watch "how to preselect value in dropdownlist in jsp struts" New topic
Author

how to preselect value in dropdownlist in jsp struts

zoheb siddiqui
Greenhorn

Joined: May 08, 2008
Posts: 11
i am working web application on struts 1.3 in netbeans i have two dropdownlist say A and B now i have no probl1em in populating these dropdowns on jsp load ,now user select one value from say dropdown A and value user selected say it is 1 and for another dropdown say B user selected value which is 2 and now user will save these values in database now my requirement is that when we go in edit mode for that when page loads dropdownlist A should have value 1 as preselected and dropdownlist B should have value 2 as preselected. and these values are coming from database my jsp page

1 dropdown

<tr>
<td> <html:select name="RoomForm" property="location"onchange="getFloorDropdown(this.value);" >
<htmlption value="0">Select Location</htmlption>
<htmlptionsCollection name="RoomForm"
property="list" value="id" label="name" />
</html:select>
<td>
</tr>

RoomForm:-name of my form bean in requst scope list:-Arraylist collection
id:-it is property in Arraylist which is list having getter and setter in bean
name:-it is property in Arraylist which is list having getter and setter in bean

2 dropdown

<select name="floor" >
<option value="0">Select Floor</option>
</select>

how should i do how select a preselected values in both downdroplist when this form opens in edit mode
any hint will be a great help for me
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Zoheb,
It should work fine if you pre-populate the value before painting the JSP i.e. in your action class itself you set the form bean value, struts should handle this for example, in your scenario set "location" attribute value in "RoomForm" to the desired one and then forward to the JSP.


Have Fun with Java
little,little.. little by little makes a lot..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to preselect value in dropdownlist in jsp struts
 
Similar Threads
html:select and html:options or html:optionsCollection
Need help selected text fields visible for particular option from drop down list in JSP(struts)
struts html list drop down question
Dependent drop down list using Struts 1.2 with Ajax DWR
how to get both value and text of selected item in action class