• Post Reply Bookmark Topic Watch Topic
  • New Topic

Business Logic in JSF  RSS feed

 
Gauri Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All -

I am new to JSF. I have been working with Struts before.

I would like to know where should be the business logic reside in JSF?
e.g. If I am writing a simple login page. Clicking on submit button the business logic will check user id and password and will display appropriate page. If the login successful then welcome page and for unsuccessful login display error msg page.

Where should be the logic to check the user id and password is correct and how do we call this business logic from the login page. My understanding the Managed Page Beans will have only getter/setter methods and no business logic.

Please help.

Thanks,
Gauri
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can have JavaBean components that can handle your business logic stuff and have them invoked from within your page's managed backing bean bean.

Provide an actionListener for the submit button and have your JavaBean components invoked from the handler code of that actionListener.

Best of luck ...
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, it's actually not considered best practice to place business logic in either JSF or Struts classes. Unless the logic is really trivial, it's better to place the business logic in independent Java classes and have it invoked by the Struts action processor or JSF bean.

The advantages are:

1. If you do things properly, you can test the business logic using ordinary init testing (without having to start up a J2EE server).

2. You can easily switch from Struts to JSF or JSF to Struts or JSF to whatever, since the GUI code isn't all tied into the business code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!