• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read the value selected in the selectOneMenu tag in the forwarded jsp page

 
vijay makam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code in my jsp page:


My Bean class has these two properties:

I am adding the empList with SelectItem instances in my bean's constructor.

The list is getting populated, but the problem is how can I get the selected option in the jsp page which I will be forwarding it to eventually after form submission?
Will not be value be stored in "empName" property?? Because it's not working when I am displaying it using value expression.

Thanks in adavance
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the first thing that will help is to not think in terms of "pages", but in terms of the backing beans. In JSF, pages are views into the backing beans, but the beans themselves are where the action is.

I can't tell for certain, but I suspect that your "myBean" may be a request-scope object. Request-scope objects get created for each request, so each request starts out with a new copy of the bean. You can tell if this is your problem by defining the backing bean in session scope, instead and seeing if the problem persists. JSF does tend to require more session-scope objects than other J2EE platforms do. At least unless you're willing to devote extra time on session data management.
 
vijay makam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your time.

As you said my myBean(managed bean) was in session socpe only. So it should be visible for a user session. But it is not working and I am clueless
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably a silly question, but do you have a getter and a setter on the backing bean for "empName"?
When the next page loads, so long as it accesses the same instance of the same bean (which it should do if it is a session bean), then your "empName" value should appear. e.g.
If you can run with server code debugging (easy with Tomcat and Eclipse, possibly other IDE/AppServer combinations too) then you could place breakpoints in you bean and see if they value gets set, or if something is accidentally re-setting it. If find the combination of good logging and server debugging can really help with "simple, but highly frustrating" problems like this.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you have the following methods defined in myBean's class:



That should be all it takes, but if you don't define the method signatures exactly right, the getter and/or setter method won't be visible to the JSF EL processor and the set/get will fail silently - you'll not see data set if the set method signature is wrong, and you'll get an empty string if the get method signature is wrong.
 
vijay makam
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your time. I got this working. Actually the tag was outside the form.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!