wood burning stoves 2.0*
The moose likes Struts and the fly likes Retrieving contents from a select multiple=true input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieving contents from a select multiple=true input" Watch "Retrieving contents from a select multiple=true input" New topic
Author

Retrieving contents from a select multiple=true input

Steven Ash
Greenhorn

Joined: Dec 06, 2004
Posts: 1
Hi,

I have a form that has 2 select boxes where the multiple option is set to true. I am passing some values from the first box to the second box using javascript. This all works fine as the values transfer properly and everything.

Once I press submit I am going to an action where I try and collect the values from the second select box.

I have tried to retrieve them using:

request.getParameterValues("target")

but this always returned null.

Just to test I tried to return the values from the first box but this also returns null so I'm not sure what's going on. It collects the values from all other parameters on the form, just not for this one.

Anyone ever done this before? Know how to make it work?

Thanks
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5018
    
    8

Could you post the relevant parts of your JSP?


Junilu - [How to Ask Questions] [How to Answer Questions]
John Smith
Ranch Hand

Joined: Sep 02, 2004
Posts: 61
I've done that and had it work, what you need to do is assign a String [] to your second select box (the one you're trying to get the data from) and replace the submit button with a standard html:button with an onclick event. The onclick event should iterate through the select box entries in javascript and set them all to selected then do your forms[0].submit.click();

Struts doesn't update the array used in your html ptions tags so if it was null before you'll still get null when trying to access the data afterwards. You might like to use an event handler to catch the enter key press and ignore it on that page too so the hidden submit button it only accessable by you through your javascript.

Hope this helps, let me know if you didn't understand any of it
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
I would love to see how you did this, I'm working on something similiar but I was trying not use any javascript.

I have two multi-select boxes and I want to beable to remove value(s) from one and add it/them to the other (and vice versa). I have 3 submit buttons one add (takes value from right select box and places it in left select box) one remove (takes value from left select box and places it in right select box) and then save which saves changes the database accordingly. My actual actionform has 4 string[] types: member, notMember, selMember, notSelMember (member and not Member are the two multi select boxes).


inside the action class depending on the value of myAction, I add/subtract values in (notS)/(s)elmembers from the members/notmembers array.

I keep getting a "property members returns null" exception even though I'm setting the members property inside the action class.

I've even tried to store values for members/not members in the request b/c I think the above code might return null for the property members as its not part of the form.

 
 
subject: Retrieving contents from a select multiple=true input