Hi all,
I'm developing an application in Struts, where I need to have drop downs in my jsp. I'm using treemap in my form bean's reset() to populate the drop down in the jsp. the problem is, how can I get to the individual values in the drop down? here's my code..
jsp:
-----
<tr>
<td>Select your hobby:</td>
<td>
<html:select property="hobby">
<html:options property="keySetHobby" labelProperty="hobbyList"></html:options>
</html:select>
</td>
</tr>
form:
--------
public class LoginForm extends org.apache.struts.action.ActionForm {
private String hobby;
private Collection hobbyList;
private Set keySetHobby;
private String key;
private Map hobbyMap;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Map getHobbyMap() {
return hobbyMap;
}
public void setHobbyMap(Map hobbyMap) {
this.hobbyMap = hobbyMap;
}
public Set getKeySetHobby() {
return keySetHobby;
}
public void setKeySetHobby(Set keySetHobby) {
this.keySetHobby = keySetHobby;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public Collection getHobbyList() {
return hobbyList;
}
public void setHobbyList(Collection hobbyList) {
this.hobbyList = hobbyList;
}
public LoginForm() {
super();
// TODO Auto-generated constructor stub
}
@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
Map<String,String> hobbyTempMap=new TreeMap<String,String>();
hobbyTempMap.put("-1","Select");
hobbyTempMap.put("0","Eating");
hobbyTempMap.put("1","Sleeping");
hobbyTempMap.put("2","Drinking");
this.setHobbyMap(hobbyTempMap);
this.setHobbyList(hobbyTempMap.values());
Set keys=hobbyTempMap.keySet();
this.keySetHobby=keys;
}
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
if (this.getHobby().equals("Select"))
errors.add("keySetHobby", new ActionMessage("error.KeySetHobby.required"));
return errors;
}
}
I'm keenly looking forward for help.
regards,
Ash.