File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Sende the previous response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Sende the previous response" Watch "Sende the previous response" New topic
Author

Sende the previous response

Mark Schneider
Greenhorn

Joined: Mar 04, 2013
Posts: 2
Hello coderanch,
i build a simple jsf-application which contains 2 input-fields and a submit-button (action leads to the page itself). The page prints the given parameters out.
What I am trying to implement is if you enter a specific value in the first input-field, the response you received before from the server, should be send again to you instead of the new calculated response...
example:

1. pagecall (called by user):
-> user enters "ABC" in field 1
-> user enters "123" in field 2
-> user submits

2. pagecall (called by submit):
-> JSF checks if value 1 is "DEF" - false
-> JSF prints out "ABC"
-> JSF prints out "123"
-> JSF set value of field 1 to "ABC"
-> JSF set value of field 2 to "123"
-> JSF saves the response
-> JSF send the response
-> user enters "DEF" in field 1
-> user enters "456" in field 2
-> user submits

3. pagecall (called by submit):
-> JSF checks if value 1 is "DEF" - true
=> skips calculating, setting values and so on and load last saved response (so the value of field 1 is not "DEF" but "ABC")
-> JSF send the response

is it even possible?

i tried it by adding phaselisteners and rewriting GET and SET-parameters (but the framework does not allow this)...
do i need to implement an own lifecycle-class or something like that?

kind regards
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

In JSF the more complicated your code, the more wrong it is. JSF is designed to make it easy to work with POJOs with a minimum of platform-specific coding. For projects like yours, in fact, that minimum is 0.

JSF is not like your typical "submit a form" web framework. JSF is based on the idea that people submit a form, get back error messages, and keep re-submitting the form until all the data is valid and can be processed, at which point you (usually) advance to some other page. This cycle of submits is a mechanism known as "postback".

JSF is also a very pure implementation of the Model/View/Controller paradigm where the Controllers are usually already supplied for you and operate transparently. Thus, you provide a View Template (".xhtml") and a Model (backing bean, also known as Managed Bean) and the Controllers are the FacesServlet and the JSF tag element processors. You bind the View to the Model using Expression Language (EL) expressions. Once you have done that, JSF will automatically format and populate the displayed View (web page) using the property values it finds (via "get" methods) in the Backing Bean, and conversely, when you submit, the View (Form) values that are submitted are passed back to JSF, which validates them, updates the Backing Bean values (using "set" methods) - if and only if all incoming data values are determined valid, and then, once the bean has been updated, the action method is invoked where the code that processes these values is located as well as the code that indicates where to navigate once the processing is done.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mark Schneider
Greenhorn

Joined: Mar 04, 2013
Posts: 2
Mhh i think you misunderstood what i want to do.
I know the basics, but i want to interrupt the lifecycle... i "solved" the problem with the following code (which does not do what i want -resending previous response- but works all in all fine in the whole context). It just skips the "apply request values" and following parts and render the response directly (quick'n'dirty code):


This is not an optimum. If anybody got ideas for my problem, please post it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

If you want the View to render a given value, just update the Model in your Action method and the normal Render Response will do the rest. There's no need for platform-specific code to do that.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sende the previous response