File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to preselect value in dropdownlist in jsp struts

 
zoheb siddiqui
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic