aspose file tools*
The moose likes JSF and the fly likes What's wrong with JSF navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "What Watch "What New topic
Author

What's wrong with JSF navigation

marwen Bakkar
Ranch Hand

Joined: Jan 28, 2010
Posts: 84
I wanted to see how JSF works so I grabbed a book which I'm now reading. I was struck by something regarding the so called navigation model:

In plain HTML as everybody knows it, the action attribute of a form's submit button points to the resource that the form data will be posted to; it's this resource that contains the form handling logic.

In JSF however, the commandButton action attribute contains an "outcome" that indicates the page that should be displayed next, which means the form is implicitly posted to itself and then a server-side forwarding gives control to the target resource, which in this case doesn't contain form-handling logic.

Isn't this a violation of the "don't make me think" principle?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15661
    
  15

I never thought about it.

Seriously, however, one of the primary characteristics of JSF is that there shouldn't be any form-handling logic. JSF is a Model/View/Controller architecture. The HTML form is handled by JSF's controllers, and unlike most other MVC systems, you don't (usually) code controllers in JSF, since the controllers are pre-supplied as part of the framework. Hence, you only have to design and implement Model (backing bean) and View template (.xhtml).

The proper technical term for form-handling in JSF is "postback". Since JSF is designed to enforce that all data in a form is valid before it may be used to update the Model or invoke the Action method, JSF will repeatedly post the same form until all validations are satisfied. Then - and only then, the Model will be updated, the action method (and/or action listeners) will fire, and the action will indicate to JSF what View to navigate to next.

In JSF1, the Action would return an abstract rule name. Which, being the unthinking person I am, I usually named something like "success", "failure", "unauthorized" or whatever. JSF2 allows you to alternatively explicitly designate a target View ID. A lot of people like that because it's less coding, although also less abstract, hence, less conducive to code re-use.


Customer surveys are for companies who didn't pay proper attention to begin with.
marwen Bakkar
Ranch Hand

Joined: Jan 28, 2010
Posts: 84
Tim Holloway wrote:I never thought about it.

The proper technical term for form-handling in JSF is "postback". Since JSF is designed to enforce that all data in a form is valid before it may be used to update the Model or invoke the Action method, JSF will repeatedly post the same form until all validations are satisfied. Then - and only then, the Model will be updated, the action method (and/or action listeners) will fire, and the action will indicate to JSF what View to navigate to next..


Exactly. The action attribute in HTML means the target resource. The action attribute in JSF means the target resource after the form has been implicitly posted back to itself. That's what I felt was wrong, especially because neither the official tutorial nor the book I am reading (jsf, the complete reference) came clear about it, while that's what every web developer is used to. They didn't introduce the elephant in the room.

Thanks for the explanations!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's wrong with JSF navigation
 
Similar Threads
Navigation Problem
Trying to redirect from page user has clicked on to another (might be able to use nav rule?)
My JSF Portlet Tutorial
jsf and servlets
Incorrect action value in html's form created from h:form