• 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

Putting values in the requestScope

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to put values in the requestScope from an action method.

This is what the method looks like:



This is a snippet of my form:


(Yep, it's in a dataTable.)

It will put display the value (2nd inputText), but not the key (1st inputText). That's rather strange. (Inside the action method, the key looks fine.)

Do you see anything wrong there?

Thank you!
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paolo Pinkel wrote:I'm trying to put values in the requestScope from an action method.

Do you see anything wrong there?





Yes. You're creating a whole lot of clunky server-specific code to do what JSF was intended to do easily as one of its core functions.

JSF can define Request-scope beans in faces-config and then reference them as managed properties. The managed properties can be injected into other managed beans and/or referenced via EL expressions in View definitions. And you never have to get within 100 kilometers of FacesContext or any other javax.faces objects to do that.

You've made your job a little more difficult by making 2 request objects, each of which is a simple String-class object. Usually it's easier to define a custom class that holds both key and value with property accessor methods for each. You can then inject this object into a managed bean that initializes its key and value properties, which results in a view almost identical to the one you've coded except that instead of the name "requestScope", you'd substitute the name that your custom object was published under.

There is one "gotcha", however. You can't inject a request-scope object into a session-scope bean since the destination object's lifespan has to be shorter or equal than the injected object. This sometimes means that the "obvious" arrangement of objects has to be turned around.

One final warning. JSF uses postbacks that cause the same form to be sent and received multiple times. That doesn't work well with Request scope, since the Request scope objects get destroyed and created from scratch on each request. So Request scope is much less usable in JSF than it is in other J2EE frameworks.
 
Paolo Pinkel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this enlightening comment, Tim! I'm new to JSF, so... thank you! It's working now!
 
reply
    Bookmark Topic Watch Topic
  • New Topic