Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set default value using <html:select>

843840Jan 13 2009 — edited Jan 16 2009
Hi,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2009
Added on Jan 13 2009
12 comments
2,118 views