wood burning stoves*
The moose likes JSP and the fly likes problem getting all parameters from multiple select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "problem getting all parameters from multiple select" Watch "problem getting all parameters from multiple select" New topic
Author

problem getting all parameters from multiple select

Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
I have a multiple select option box that's properly displaying all the values. I'm using getParameterValues() to retrieve all of the selections but it only returns a string[] with the first selection made. I'm guessing something is wrong in my JSP.



Here's the servlet snippet:



Thanks!
[ April 16, 2007: Message edited by: Bear Bibeault ]

SCJP 1.5
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Hmm, on first inspection everything seems OK. How about showing us the final renderred HTML rather than the JSP source? That way we can eliminate any masked markup problems.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes, everything seems fine. (<- ok this does not help)

Please also show us how you checked that there is only one element in the array.
[ April 16, 2007: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
The debugger clearly shows that the array is only populated with one value, when I have selected two.

Here's that portion of the HTML rendering:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Umm, how are you selecting elements from a disabled control?
Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
The select gets enabled when the user chooses the search option that they apply to. I took that bit of code out earlier so as to avoid this question from you guys...forgot to pull it out of the HTML. It is enabled when I make the selections.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

1. Do you have any other elements called "subset" in the same page ?
2. Can you show us why you think there is only one selection being sent ?
Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
Satou, I thought you had it! I did have another component named "subset", it was the select list itself. I renamed it but no dice.

Other than showing you a screen shot of the debugger, I don't know how to show you that this array only gets populated with the uppermost selection from the list. I set a breakpoint just after this line and clearly see only the top selected ID as a string element in the array.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Works without a hitch for me. How about ditching the debugger and trying to log or emit the values?
Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
There isn't a logging framework setup on this app. I tried sysout's but they aren't showing up in the JBoss log or command prompt. But I'm confident there is only one value being retrieved. That's all that gets sent into my search filter.

I tried writing another simple multi select and had the same results. How frustrating.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Originally posted by Shawn Kuenzler:
There isn't a logging framework setup on this app.


Why not? And, no time like the present.

I coded up a small test JSP page using your most recent example:



which submits to itself.

When both options are selected and the form submitted, the expected result appears:



What happens when you run this file? (Assumes you are up-to-date with JSP 2.0 and JSTL 1.1).
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Just to throw a real dumb question out there...

How are you selecting more than one value in your select list when you are using this page?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
Ben, I click on one and then hold control and click on the other. Both are highlighted before submitting.

Bear, I tried the JSP and when it submits, Tomcat says 'the request resource /main.jsp is available. I need to reconfigure something on the app server I guess.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem getting all parameters from multiple select
 
Similar Threads
jstl c:forEach
Dropdown list not displaying with textfield in form
passing a parameter to an action class
assigning a function's result to a form field
Nested hashmap tags for dynamic pulldowns