• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting multiple values out of an html:select option box

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
tim hay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.... I will check out the exercises.
Tim
 
tim hay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Gran Roguismo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic