Reputation: 51
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
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