Business rules in JSF [closed]

2

In JSF where would be the best place to set business rules? In the model, in the managed-bean, or in a business rules layer (I'm rather reluctant to adopt this latter approach), or do I implement such rules as JSF custom validators? I have questions about implementing a business rule in the model since I do not know when this method would be called, since the bean will directly access the model sets.

    
asked by anonymous 16.06.2015 / 18:34

3 answers

2

Hello. I do not know if this would be a good answer because you could use it any way you like. Here in the company where we work we have this structure:

Our vision layer is made up of:

  • JSF Page
  • Manged Bean (MB)

Our business rule is made up of:

  • Bisness Controller (BC)

And the drivers are:

  • Data Access Object (DAO)

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

    
16.06.2015 / 18:53
1

The best place is in the Service layer example

  • Model (Your Objects)
  • Controller (Call your Service, Avoid the maximum have if's here)
  • Service (Where All Your Business Rules Stay)
  • 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(){
      }
   }

}
    
26.06.2015 / 18:06
0

As Gilvan said, there are several ways to do it, here in the company we do this:

  • JSF - xhtml
  • Managed Bean
  • DAO
  • Model
16.06.2015 / 21:43