Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF Action

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Bill Dudney
Author
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect. How much easier can it get?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic