I need my JSF page to show the return value of the invoked method without redirecting to another page or refreshing existing. Or maybe I don't understand completely the problem, so I ask to guide me, how to show what bean returns (it returns some String). If it returns "home", then home.xhtml is displayed - this part works. But if it shows something else, I need it to wrote on the page. My page is below, how to change it to attain needed result?
<!DOCTYPE html>
<html
xmlns:h="http://java.sun.com/jsf/html"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>login</title>
</h:head>
<h:body>
<h:form id="loginForm">
<p:growl id="msg" showDetail="true" life="3000" />
<p:panel header="Login" style="width: 360px;">
<h:panelGrid id="loginPanel" columns="2">
<h:outputText value="Username" />
<p:inputText id="username" value="#{loginBean.userName}"></p:inputText>
<p:spacer></p:spacer>
<p:message for="username"></p:message>
<h:outputText value="Password" />
<p:password id="password" value="#{loginBean.password}"
feedback="false"></p:password>
<p:spacer></p:spacer>
<p:message for="password"></p:message>
<p:spacer></p:spacer>
<p:commandButton action="#{loginBean.login()}" value="Login"
update="loginForm" ajax="true"></p:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</html>
My LoginBean class:
@ManagedBean(name = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
private String userName;
private String password;
private String role;
private String msg;
setters and getters for all fields are omitted
public String login() {
UserBean result = UserDao.login(userName, password);
if (!result.isWrongUserName() && !result.isWrongPassword()) {
HttpSession session = Util.getSession();
session.setAttribute("username", userName);
session.setAttribute("role", role);
return "home";
} else if (result.isWrongUserName()) {
???????????
} else {
???????????
}
}
public String logout() {
HttpSession session = Util.getSession();
session.invalidate();
return "login";
}
}