• 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

What's wrong with JSF navigation

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
marwen Bakkar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic