Business rules in JSF

Asked

Viewed 658 times

2

In JSF where would be the best place to define business rules? In the model, in the Managed-bean or in a layer of business rules( I am very reluctant to adopt this last approach), or even to implement such rules as being custom JSF validators? I have doubts about implementing a business rule in the model since I don’t know when this method would be called, since the bean will directly access the model sets.

3 answers

2


Hello. I don’t know if that would really be an answer because you could use it the way you think best. Here in the company where I work we have this structure:

Our vision layer is composed of:

  • Page JSF
  • Manged Bean (MB)

Our business rule is composed of:

  • Bisness Controller (BC)

And the controllers are:

  • Data Access Object (DAO)

But as I told you, it depends on how you adapt in your business! Hugs

  • We also use it like this. And a package with all objects. A difficulty is always using BC to perform the validations, but always ends up getting something in Bean... I don’t know if I’m the only one who ends up in this situation.

  • Of course, some things will always land on Bean. In my case, for example, I have separate projects (libraries I would say), that is, one project is the vision layer and the other is the business rule. Some dependencies that I have in the vision layer I don’t have in the business, and I wouldn’t have to have just to make validations... then I make the validations in the same bean. The validations considered standards I do in BC.

1

The best place is at the example Service layer

  • Model (Your Objects)
  • Controller (Calls Your Service,)
  • Service (Where All Your Business Rules Are)
  • Dao (Your Repositorys)

Example :

public class LoginController {

     @inject
     private LoginService loginService;
     public void login(Login login)
     {
         loginService.login(login);
     }
}

public class LoginService {

   public boolean login(Login login){
       //todas as Regras feitas aqui!
      if(){
      }
   }

}

0

Like Gilvan said, there are several ways to do it, here at the company we do it like this:

  • JSF - xhtml
  • Managed Bean
  • DAO
  • Model
  • I get it. I think my simplest rules will be transformed into custom JSF validators. And I’ll leave the service class only with methods that have to access the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.