How to set default value using <html:select>
843840Jan 13 2009 — edited Jan 16 2009Hi,
I want to set a value as default from the available options, but it showing the first element as selected by default.
here is the snippet of JSP code:
<html:form action="Test" name="testform" type="com.TestForm" >
<b>Aircraft Type</b>
<html:select property="selectedType" size="1" tabindex="1" style="width:50%" >
<logic:iterate id="type" property="airType" name="testform">
<option value="<bean:write name="type" property="key"/>" >
<bean:write name="type" property="value"/>
</option>
</logic:iterate>
</html:select>
<html:submit property="updateBtn" value="Update" style="WIDTH: 71px; HEIGHT: 24px" />
</html:form>
And my TestForm class is:
public class TestForm extends ActionForm{
private static final long serialVersionUID = 1L;
public String selectedType=null;
private Map<String, String> airType = null;
public TestForm(){
airType = new HashMap<String, String>();
airType.put("AA", "AA");
airType.put("BB", "BB");
airType.put("CC", "CC");
setSelectedType("BB");
}
public String getSelectedType() {
return this.selectedType;
}
public void setSelectedType(String selectedType) {
this.selectedType = selectedType;
}
public Map<String, String> getAirType() {
return this.airType;
}
public void setAirType(Map<String, String> airType) {
this.airType = airType;
}
}
I want to set Default Value as "BB" but it showing the first data "AA' as selected.
I have tried many possible solutions but it doesnt works.
Please help me to solve this issue.
Thanks,
Bhanu