Connecting Tech Pros Worldwide Forums | Help | Site Map

Drop Down list issues in jsp

Newbie
 
Join Date: Jan 2008
Posts: 12
#1: Jan 26 '08
Hi all,
I am not able to populate a drop down list in jsp...i am pasting the code here for someone to please suggest. I am new to struts and dont know whats going wrong...

JSP PAGE:
<html>
<body>
<h1>JSP Page</h1>

<html:form action="/test">

<html:select property="flavour">
<html:options name="FLAVOURS"/>
</html:select>
</html:form>
</body>
</html>

ACTION CLASS:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

ArrayList flavours = new ArrayList();
flavours.add(new LabelValueBean("Vanilla", "0"));
flavours.add(new LabelValueBean("Strawberry", "1"));
flavours.add(new LabelValueBean("Chocolate", "2"));
flavours.add(new LabelValueBean("Neopolitan", "3"));
request.setAttribute("FLAVOURS", flavours);

return mapping.findForward(SUCCESS);

}

Action Form:

public class testActionForm extends org.apache.struts.action.ActionForm {
private String flavour;
private int number;

public String getflavour() {
return flavour;
}

public void setflavour(String string) {
flavour = string;
}

public testActionForm() {
super();
// TODO Auto-generated constructor stub
}

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getflavour() == null || getflavour().length() < 1) {
errors.add("name", new ActionMessage("error.name.required"));
// TODO: add 'error.name.required' key to your resources
}
return errors;
}
}


I want the drop down to be populated when i open the page. basically on page load. When i test with the above code, tomcat return me with an error ...cannot find bean FLAVOURS...not sure what going wrong here...

Thanks
Ashish

Reply