• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

JSF Action

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder when I should start posting these questions in the Struts/Frameworks forum??
Anyway, is there an equivilent in JSF to the Struts Action? When I click a commandButton, how exactly do I perform some business logic? Is there a specific type of class I can call from the nav rules?
In an older tutorial on the alphs JSF I ran across, you could put a method in your JavaBean for the form like getResult() or whatever, and then your "action=" for the commandButton tag would be "mybean.result". Then you would have that return "success" or "failure" or whatever you wanted for those rules and in your nav rules in the jsf-config.xml you would have forwards for both of those responses. Is this still the case? I am having a hard time finding this kind of information as the spec as of right now seems so new, tutorials on the web are slow to catch up.
Thanks.
[ March 04, 2004: Message edited by: Gregg Bolinger ]
 
Sheriff
Posts: 67695
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When does the book promotion officially end? Until then, I'd say to post here so your posts stay eligible for the drawing.
After that, I think the Frameworks forum would be a more appropriate place for JSF discussion.
 
Author
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg,
The demos that come with the spec are probably the best bet for now...
But for what its worth here is a simple example from the book...
Here is the login button. "#{loginPage.login}" is a method binding that binds the button to a method named 'login' that returns a string and takes no arguments.

here is the java code...

and then here is the relevant piece of the faces-config.xml file...

if the login method returns 'valid login' the app moves to AccountSummary.jsp, if 'invalid login' then the app returns to Login.jsp.
The login method would then be responsible for doing any business logic. I like to put the logic into other classes (like LoginCommandLocal above) so that the logic can be used across UI's but you get the idea from the code.
If you don't please hassle me!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code makes perfect sense! I only have one question.
Does the public String login() method exist in a JavaBean like LoginBean or whatever that coorosponds to the Login Form? I would assume so, but I just want to be sure.
 
Bill Dudney
Author
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg,
Yes that is exactly right. The login method is on the loginPage bean. The login method delegates to the actual logic...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect. How much easier can it get?
 
reply
    Bookmark Topic Watch Topic
  • New Topic