Forums Register Login

What's wrong with JSF navigation

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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!
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1040 times.
Similar Threads
Trying to redirect from page user has clicked on to another (might be able to use nav rule?)
Incorrect action value in html's form created from h:form
jsf and servlets
My JSF Portlet Tutorial
Navigation Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:25:49.