File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Am I misunderstanding the basics of JSF 2.0?

 
Kevin P Smith
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Donald Jackson
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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

 
Tom Fulton
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Aman Goel
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worst Solution.... Do not misguide please
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic