我想在没有输入字段的情况下点击更新按钮后弹出所需的消息,弹出必须打开。如果我输入所有字段然后输入更新按钮弹出应该关闭。
下面是jsf代码,
<h:form id="dia">
<p:dialog header="Reset password" widgetVar="reset" id="dialog" modal="true" appendToBody="true"
visible="#{facesContext.validationFailed}">
<h:panelGrid columns="3" cellpadding="10px" cellspacing="10px">
<h:outputLabel value="New password" />
<p:inputText id="npwd" value="#{crmBean.newPassword}" requiredMessage="Enter password" required="true" >
</p:inputText>
<h:message for="npwd" display="icon" />
<h:outputLabel value="Confirm password" />
<h:inputText id="opwd" value="#{crmBean.confirmPassword}" requiredMessage="Enter password" required="true" >
</h:inputText>
<h:message for="opwd" display="icon" />
</h:panelGrid>
<p:commandButton actionListener="#{crmBean.resetPassword()}"
value="Update password" class="sitebtn" style="margin-left: 350px;" oncomplete="if (args && !args.validationFailed) reset.show()" />
</p:dialog>
</h:form>
下面的是支持bean代码,
public void resetPassword(){
cust_id=105;
if (newPassword.equalsIgnoreCase(confirmPassword)) {
int i = crmService.resetPassword(newPassword, cust_id);
if (i==1) {
RequestContext.getCurrentInstance().execute("reset.hide()");
FacesContext.getCurrentInstance().addMessage(
"crmprofile",
new FacesMessage("Reset password successfully..","Thank you..."));
this.confirmPassword=null;
this.newPassword=null;
} else {
FacesContext.getCurrentInstance().addMessage(
"crmprofile",
new FacesMessage("Please enter values correctly:","Thank you..."));
this.confirmPassword=null;
this.newPassword=null;
}
}
else {
FacesContext.getCurrentInstance().addMessage(
"crmprofile",
new FacesMessage("Please enter values correctly:","Thank you..."));
this.confirmPassword=null;
this.newPassword=null;
}
}