vino09
asked on
Set Default Value in html:optionsCollection
Hello,
I'm using LabelValueBean Struts Util class to set drop down list (HTML:SELECT) values in my JSP. I reterive customer state code from the database, while rendering the JSP , I need to set this customer state as a default value in the dropdown list box. Please advice me on how to achive this.
Action Code: Reterives all the states from DB
Collection options = new ArrayList();
while (cursor.next())
{
String value = cursor.getString(cursor.ge tMetaData( ).getColum nName(1).t oString()) ;
String label = cursor.getString(cursor.ge tMetaData( ).getColum nName(2).t oString()) ;
LabelValueBean option = new LabelValueBean(value, label);
options.add(option);
In JSP
<html:select property="attnCustState" >
<html:optionsCollection name="listOfValuesState" />
</html:select>
If the customer has AZ as his state setup in DB, while reteriving the data, the list box must point to this state.
Thanks for your help in advance.
I'm using LabelValueBean Struts Util class to set drop down list (HTML:SELECT) values in my JSP. I reterive customer state code from the database, while rendering the JSP , I need to set this customer state as a default value in the dropdown list box. Please advice me on how to achive this.
Action Code: Reterives all the states from DB
Collection options = new ArrayList();
while (cursor.next())
{
String value = cursor.getString(cursor.ge
String label = cursor.getString(cursor.ge
LabelValueBean option = new LabelValueBean(value, label);
options.add(option);
In JSP
<html:select property="attnCustState" >
<html:optionsCollection name="listOfValuesState" />
</html:select>
If the customer has AZ as his state setup in DB, while reteriving the data, the list box must point to this state.
Thanks for your help in advance.
is it OK ?
ASKER
Thanks Laes, for your possible solution. I could not implement this solution. Is there an alternate approch to create a dropdown list topoint to a default code while rendering the JSP.
Thanks,
Dinesh
Thanks,
Dinesh
if u want to preserve the mvc pattern, struts form associated with an actionForm
that is the solution
unless you want to code it with jsp tag <%..., the worst thing !
personally, a developped it as mentioned
that is the solution
unless you want to code it with jsp tag <%..., the worst thing !
personally, a developped it as mentioned
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
property="List1" value="col1" label="col2" />
</html:select>
a assume that u define an actionform form1
in witch u define an arraylist List1 with getter and setter
in the getter method of the arraylist : u do like this, sure its not recommended , but its a solution
public java.util.List<classe1> getList1() {
if (List1.isEmpty()) {
List1.add(new classe1(id, label));
List1.add(new classe1(id,label));
..... etc
//or u call the code u put in the action , to get the different options
}
return List1;
}