我正在使用Primefaces,并有一个登录对话框:
<p:dialog widgetVar="dlgLogin" header="Login" modal="true">
<p:outputPanel>
<h:form>
<p:messages for="msgLogin" autoUpdate="true" closable="true" showSummary="true" showDetail="false" severity="error"/>
<p:panel>
<h:panelGrid columns="2">
<p:outputLabel value="User Name"/>
<p:inputText id="userName" value="#{loginBean.userName}"
required="true" requiredMessage="User Name is required"/>
<p:outputLabel value="Password"/>
<p:password id="password" value="#{loginBean.password}"
required="true" requiredMessage="Password is required"/>
</h:panelGrid>
</p:panel>
<p:commandButton icon="ui-icon-arrowrefresh-1-n" value="Cancel" onclick="PF('dlgLogin').hide()"/>
<p:commandButton type="submit" value="Login"
ajax="false" validateClient="true"
oncomplete="handleClose(xhr, status, args);"
action="#{loginBean.login}"/>
</h:form>
</p:outputPanel>
</p:dialog>
提交登录是非故意的非ajax,因此整个页面将被刷新。
服务器代码是:
FacesContext.getCurrentInstance().addMessage("msgLogin", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Wrong User Name or Password.", "Wrong User Name or Password."));
如果服务器中的登录失败,我想显示一条消息,并打开对话框。但它不起作用。
怎么办呢?
感谢。
答案 0 :(得分:0)
不要在JSF中关闭对话框,而是在Java中关闭:
if (successfulLogin) {
RequestContext.execute("PF('dlgLogin').hide()");
} else {
FacesContext.getCurrentInstance().addMessage("msgLogin", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Wrong User Name or Password.", "Wrong User Name or Password."));
}