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
A+
-
Help with <html:select options> tag (6 messages)
- Posted by: Atlas Casa
- Posted on: February 20 2003 18:58 EST
Threaded Messages (6)
- ArrayList by brad gallagher on February 20 2003 19:55 EST
- Clarification: ArrayList of LabelValueBeans by brad gallagher on February 20 2003 20:02 EST
- Clarification: ArrayList of LabelValueBeans by Atlas Casa on February 21 2003 11:34 EST
-
Clarification: ArrayList of LabelValueBeans by Atlas Casa on February 21 2003 04:33 EST
-
Two different properties by brad gallagher on February 22 2003 05:19 EST
- Thank you by Atlas Casa on February 24 2003 09:41 EST
-
Two different properties by brad gallagher on February 22 2003 05:19 EST
- Clarification: ArrayList of LabelValueBeans by brad gallagher on February 20 2003 20:02 EST
-
ArrayList[ Go to top ]
- Posted by: brad gallagher
- Posted on: February 20 2003 19:55 EST
- in response to Atlas Casa
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? -
Clarification: ArrayList of LabelValueBeans[ Go to top ]
- Posted by: brad gallagher
- Posted on: February 20 2003 20:02 EST
- in response to brad gallagher
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. -
Clarification: ArrayList of LabelValueBeans[ Go to top ]
- Posted by: Atlas Casa
- Posted on: February 21 2003 11:34 EST
- in response to brad gallagher
brad,
thank you for your quick reply. I will try it out -
Clarification: ArrayList of LabelValueBeans[ Go to top ]
- Posted by: Atlas Casa
- Posted on: February 21 2003 16:33 EST
- in response to brad gallagher
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
A+ -
Two different properties[ Go to top ]
- Posted by: brad gallagher
- Posted on: February 22 2003 17:19 EST
- in response to Atlas Casa
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 ) { this.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 -
Thank you[ Go to top ]
- Posted by: Atlas Casa
- Posted on: February 24 2003 09:41 EST
- in response to brad gallagher
Brad,
Thank you very much, with your help it took me 5 minutes to get it to work.
have a wonderful day
A