• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass drop down box value to a bean

 
Fred Fasle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have a form with a number of text fields and a drop down box. I am able to pass the values in the text fields into a javabean without any problem using <jsp:setProperty name="myBean" property="*" /> on the following JSP page. But for my drop down box, listed below, I get a number that doesn't match any of the options. I am using simple get and set methods in my Javabean. Any ideas?
<select name="result" size=1 width=40 >
<option value='05'selected>05
<option value='10'>10
<option value='15'>15
<option value='20'>20
<option value='25'>25
</select>
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..
Try this..

hth
MB
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having this exact same problem. I've got properly formed HTML for the select box but the bean value still isn't being set properly. Other text input fields work fine.



Bean setter/getter:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original post is from 2003. It is no longer considered acceptable to post to directly to JSP pages. Data handling should happen in task controller servlets.

Is this old code that you are dealing with?
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gah... didn't see the date on it. Just did a search and saw exactly the problem I was having.

No, it's not old code. I was following some examples in the OReilly JSP 3rd edition book. In it, he redirects back to the original form when submitted data does not validate properly. The form is filled out again with the original submitted values using the Bean that is created when the form is submitted.

In his examples, though, I've noticed he conveniently never uses a select dropdown box.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What year was that published? That's a rather old-fashioned way of doing things.

And to be honest, I don't know what the issue might be. But not having used <jsp:setProperty> in this way since 2001, I may be missing a nuance.

The value of the select element should be sent as part of the request in the exact same manner as other controls. The fact that it's a select should be moot. Have you inspected the HTTP to see if it's passing the value correctly? (With a tool like HttpFox for Firefox.)
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://oreilly.com/catalog/9780596005634/ Mine has 2004 in the book copyright note.

Yes, it is passing the value properly. I tested it using <c:out value="${param.title}" /> on a test processing page and it shows up fine.

Using the <jsp:setProperty ... property="*"> like this on a Bean is supposed to set all properties automatically if it follows the proper bean getter/setter structure, which my bean does. All other text fields pass through perfectly fine, just the select doesn't.

Looking around more, I might have found something. I'm wondering it it's passing it through not as a single value, but some sort of Map or List, since select has the possibility of having multiple values. Not yet sure how I'd get the value then.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith Fiske wrote:http://oreilly.com/catalog/9780596005634/ Mine has 2004 in the book copyright note.

Not quite ancient, but definitely dated.

I'm wondering it it's passing it through not as a single value, but some sort of Map or List, since select has the possibility of having multiple values

How would it know? The request only sees what's passed in the HTTP... how would it know it originated with a select?
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point. I'm clueless why it's not picking it up then.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same here. I'll try to put some time away later to investigate further.

Meantime, why not use the opportunity to explore modern web application structure where you'll never run into this situation. Maybe this article can help you point you in that direction.
 
Keith Fiske
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I saw you link that to someone else in another thread. I bookmarked it to read later. Appreciate your help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic