• 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

Am I misunderstanding the basics of JSF 2.0?

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem (or misunderstanding) with JSF 2.0...
I have 2 JSPs, one to enter firstname & surname and the other to display then 'upload' (not implemented yet) to a DB.
Now moving from page1 to page 2 works and the labels display the values OK, but at the point of submitting on page2 the values of
firstname & surname are 'NULLED',
I presumed the values were still active as they are displayed in the labels.
Isn't the sort of the point of the JSF framework or as I say, am I missing the point?

Thanks in advance.

Here is the basic coding...



Cheers
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keith,

just two short hints (I don't have more time at the moment): JSF 2.0 uses XHTML/Facelets as its preferred templating technology. Not JSPs! And you should check if the FacesServlet is setup correctly in your web.xml descriptor. I think you will find enough sources for more information with these hints ;-)

Marco
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using:

<h:inputText label="First Name" value="#{flash.firstname}"/>
<h:inputText label="Last Name" value="#{flash.surname}"/>

In your next page use:

<h: outputLabel value="#{flash.firstname} #{flash.surname}" />

Then you can access the value in your bean with:

Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
setFirstname ((String) flash.get("firstname"));
setSurname ((String) flash.get("surname"));

You may have to use #{flash.keep.firstname} in your EL expression in your page tag though. I'm not sure. Using the "keep" function in the flash tag attribute allows the saved data to stay through another iteration of the view lifefcycle. It will take the data from one page view to the next only unless you use 'keep' to maintain it. You'll have to look into it, but I think this points you in the right direction to do what you want. Atleast this is one way.

Good luck,
Mark

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It shouldn't actually be necessary (although it might be nice) to use flash scope to make this work correctly. The managed bean is session-scoped, so the values should be retained across multiple pages, regardless of whether they are forwards or redirects.

However, one thing I noticed about your code was the signature of the create( ) method. You specified this when you said . The action attribute expects a method that returns a String, and takes no parameters...yours is returning void. Honestly, I'm not sure what that would do...and in JSF 1.2, that would have failed deployment.

If you want to stay on the same page, you can use an actionListener, which takes an ActionEvent parameter (which you don't have to do anything with) and returns void. If you want to transition to a new page, use action, and have the method return the name of the page you wish to transition to.

I'm not sure that's the reason your fields are nulled, but it sure won't work correctly until you change it in one form or another.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will work fine. Just try to do one thing that in page2.jsp try to get only one name
 
Aman Goel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Worst Solution.... Do not misguide please
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic