aspose file tools*
The moose likes Struts and the fly likes getting multiple values out of an html:select option box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "getting multiple values out of an html:select option box" Watch "getting multiple values out of an html:select option box" New topic
Author

getting multiple values out of an html:select option box

tim hay
Greenhorn

Joined: Jan 24, 2002
Posts: 6
I have an multiple option box that is being populated dynamically. I can get the first item out without any problems. How do I get all of the values?
thanks
tim
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
request.getParameterValues(java.lang.String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.


Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
tim hay
Greenhorn

Joined: Jan 24, 2002
Posts: 6
Will that work within the Struts framework? If so, how do i convert request.getParameterValues into the get/set from within the struts?
thanks
tim
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Could maybe use a bit more info.
When you talk of get and set methods, are you referring to an ActionForm?
And assuming you are using ActionForm objects then are you using the struts tags in your jsp?
If you are using the struts tags in your jsp, have you checked out <html ptions>?
tim hay
Greenhorn

Joined: Jan 24, 2002
Posts: 6
Sorry...
Yes i am using an ActionForm to populate a user info bean. Currently only the first of the selected items is being populate on my bean. I have look at the docs and didn't find them much help.

tim
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I haven't had to actually do this... but it seems this has been addressed in the struts-exercise-taglib.war that comes with struts. Pay particular attention to TestBean.java and html-select.jsp.
Also try this link:
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg38248.html
tim hay
Greenhorn

Joined: Jan 24, 2002
Posts: 6
Thanks.... I will check out the exercises.
Tim
tim hay
Greenhorn

Joined: Jan 24, 2002
Posts: 6
got it working. On my gets and sets i was not account for an array, public String get() and public void set(string) instead of public String[] get() and public void set(string[])
thanks for all of your help!
tim
Gran Roguismo
Ranch Hand

Joined: Mar 10, 2005
Posts: 77
I am having this same problem, but the formbean that I am using already has the variable as an array of strings. Here is my setup

BEGIN JSP:
<html:select name='reportForm' property='items_right' multiple='true' size='10' style='width:225px;'>
<html ptions collection='paramSelect' property='paramName' labelProperty='paramDesc' />
</html:select>
END JSP

BEGIN ACTION:
log.warn("items_right: " + rf.getItems_right());
log.warn("test: " + request.getParameterValues("items_right"));
END ACTION

BEGIN FORM:
public String[] getItems_right() {
return items_right;
}
public void setItems_right(String[] items_right) {
this.items_right = items_right;
}
END FORM

the options are being populated from the action and that is working.
I am getting other values from my form, but this one is not being getting anything back for some reason.
any ideas? Need more information?
thanks


EOL
Gran Roguismo
Ranch Hand

Joined: Mar 10, 2005
Posts: 77
alright, so I see my problem now, and it wasn't what I thought I was dealing with. The thing that I was doing with the list was really that I had two lists: one that has the full list of items, and the second that has a list of things you want to include. You use arrows to move things from one list to the other and submit the form. The problem is that when they are on the second list, they are still not "selected". They are simply options on a second list. How can I make the page select all items on the list when it's going to submit?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Gran Roguismo:
You use arrows to move things from one list to the other and submit the form.


Do the arrows use Javascript to move the items? If so, you'll use Javascript to add those as selected parameters to the form when the form is submitted.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting multiple values out of an html:select option box