user1939400
user1939400

Reputation: 51

JSF2 facelets and mvc

I'm trying to use mvc in my JSF2 facelets webapplication.

This is my logincontroller:

@ManagedBean
@ApplicationScoped
public class LoginControllerImpl implements LoginController{

    @ManagedProperty(value = "#{applicationBean}") 
    private ApplicationBean applicationBean;

    @Override
    public boolean checkLogin(String username, String password) {
        Store store = applicationBean.getStore(); //my model and my data are in this object

      try {
            store.checkLogin(username, password);
            return true;
        } catch (LoginException ex) {
            return false;
        }

    }

}

This is my loginBean:

@ManagedBean
@SessionScoped
public class LoginBean implements Serializable{

    @ManagedProperty(value="#{loginController}")
    private LoginController loginController;
   private String username;
    private String password;

    public void checkLogin(){
        loginController.checkLogin(username, password);
    }          
}

Now I want to redirect the user to a welcome page when checklogin is true. Any ideas/tips how i should do that?

Upvotes: 0

Views: 81

Answers (1)

SJuan76
SJuan76

Reputation: 24885

You can use implicit navigation, just return the page to which you want to access (relative to the current URL)

@ManagedBean
@SessionScoped
public class LoginBean implements Serializable{

  @ManagedProperty(value="#{loginController}")
  private LoginController loginController;
  private String username;
  private String password;

  public String checkLogin(){
    if (loginController.checkLogin(username, password)) {
      return "welcome.xhtml";
    }
    return null; // won't change page
  }          
}

Upvotes: 2

Related Questions