Help with <html:select options> tag


Web tier: servlets, JSP, Web frameworks: Help with <html:select options> tag

  1. Help with <html:select options> tag (6 messages)

    basically I am dispalying an empty form to the user where one of the fields is a drop down menu. I am also using a Value Object that sets/gets all the fields in the form bean to transfer Data between presentation and business tier.

    I have no idea how to do write the setters and getters for this Collection property. thus, I was thinking about storing the collection in the session then use the <bean:iterate> tag in the jsp, while keeping the rest of the form the unchanged.

    I would like some clarification in this subject. thank you in advance


    Threaded Messages (6)

  2. ArrayList[ Go to top ]

    Since you are using a drop down menu, you most likely want something with a key/value mapping. Our getter/setter methods look like this:
    public Collection getXXX() { return.fooArrayList; }
    public void setXXX(Collection fooArrayList) { this.fooArrayList = fooArrayList; }

    You can then call them from the jsp with something similar to:
    <html:select property="...">
       <html:optionsCollection property="XXX"/>

    Hope this helps?
  3. When I re-read my reply, I realized I was not being very clear. We create an ArrayList of LabelValueBeans (Beans with Labels/Values)and populate an ArrayList with those. We then pass the ArrayList to our form class through the setter method. When you iterate using the html:optionsCollection tag I gave, you will have a drop down with labels/values.
  4. brad,

    thank you for your quick reply. I will try it out
  5. Brad,

    I now can display a list of of names to the user to choose from. however, when the user makes his selection and submits the form I get a javax.servlet.ServletException: BeanUtils.populate. I understand from this that there's a problem populating one of the fileds of the FormBean, which in this case is the XXX property (setXXX(Collection list)). well, I am not sure how to do this. some more help will be apreciated. thanks in advance
  6. Two different properties[ Go to top ]

    You should be dealing with two different properties here. Since you are able to populate your page with a drop down, we now know that your getter/setter methods work for the collection property. The problem may be with your select property - this will not be the same property as the Collection you are looping over to create the drop down. This will be a different property - a String property.

    Let's say I want a drop down with names, I'd do something similar to
    -Create Collection (we've already done this in the above replies and it seems things work OK)

    -Create name property. In your Form class, do something similar to this:
    private String name = null;
    public String getName() { return name; }
    public void setName( String name ) { = name; }

    -Iterate over Collection (you are already doing this)

    -Use name property to capture user's input

    Your jsp would look something like
    <html:select property="name">
       <html:optionsCollection property="names"/>

    names = your collection
    name = user's choice
  7. Thank you[ Go to top ]

    Thank you very much, with your help it took me 5 minutes to get it to work.

    have a wonderful day