Drop Down list issues in jsp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashishc
    New Member
    • Jan 2008
    • 12

    Drop Down list issues in jsp

    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="flavo ur">
    <html:options name="FLAVOURS"/>
    </html:select>
    </html:form>
    </body>
    </html>

    ACTION CLASS:
    public ActionForward execute(ActionM apping mapping, ActionForm form,
    HttpServletRequ est request, HttpServletResp onse response)
    throws Exception {

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

    return mapping.findFor ward(SUCCESS);

    }

    Action Form:

    public class testActionForm extends org.apache.stru ts.action.Actio nForm {
    private String flavour;
    private int number;

    public String getflavour() {
    return flavour;
    }

    public void setflavour(Stri ng string) {
    flavour = string;
    }

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

    public ActionErrors validate(Action Mapping mapping, HttpServletRequ est request) {
    ActionErrors errors = new ActionErrors();
    if (getflavour() == null || getflavour().le ngth() < 1) {
    errors.add("nam e", new ActionMessage(" error.name.requ ired"));
    // TODO: add 'error.name.req uired' 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
Working...