my dog learned polymorphism*
The moose likes JSP and the fly likes JSF Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSF Action" Watch "JSF Action" New topic
Author

JSF Action

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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 ]

GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bill Dudney
Author
Ranch Hand

Joined: Sep 05, 2003
Posts: 234
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!


TTFN,<br /> <br />-bd-<br /> <br /><a href="http://www.amazon.com/exec/obidos/ASIN/0471449156/qid=1064343733/sr=2-1/ref=sr_2_1/002-8375300-3666449" target="_blank" rel="nofollow">Jakarta Pitfalls</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471146153/qid=1064343733/sr=1-2/ref=sr_1_2/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">J2EE AntiPatterns</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471462071/qid=1064343733/sr=1-3/ref=sr_1_3/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">Mastering JavaServer Faces</a> | <a href="http://bill.dudney.net/roller/page/bill" target="_blank" rel="nofollow">Blog</a> | <a href="http://www.jroller.com/page/BillDudney" target="_blank" rel="nofollow">Eclipse Blog</a> | <a href="http://www.sourcebeat.com/TitleAction.do?id=2" target="_blank" rel="nofollow">Eclipse 3 Live</a>
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Sep 05, 2003
Posts: 234
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

Perfect. How much easier can it get?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Action