我正在登录页面上工作,其中有2个输入字段用户名和密码以及2个提交按钮登录和忘记密码。所有这4个元素都是一种形式。我已将null输入的验证应用于用户名密码。如果用户在不提供用户名和密码的情况下单击登录,则会显示一些主要消息。忘记密码是一个弹出窗口,它还有两个字段用户名和电子邮件,同样的空白对话也在这里。我的问题是当我点击登录时提供任何输入,它弹出忘记密码窗口以及用户名和密码验证错误。 以下是我的代码。 感谢
登录页面
<h:form >
<p:panel id="panel" >
<p:focus context="panel"/>
<h:panelGrid >
<h:outputLabel for="firstname" value="#{app.username} : " style="font-weight:bold; font-size:12px;">
<h:outputLabel value="*" style="color:red; font-size:12px;"/></h:outputLabel>
<p:inputText id="firstname" required="true" label="Firstname" value="#{userManageBean.user.userName}" size="35" maxlength="10" requiredMessage="User Name is required."/>
<p:message for="firstname" />
<br/>
<h:outputLabel for="surname" value="#{app.paswrd} : " style="font-weight:bold; font-size:12px;">
<h:outputLabel value="*" style="color:red; font-size:12px;"/></h:outputLabel>
<p:inputText id="surname" required="true" label="#{app.paswrd}" value="#{userManageBean.user.password}" type="password" size="35" maxlength="10" requiredMessage="Password is Required" />
<p:message for="surname" />
<h:outputText value="#{userManageBean.message}" style="font-weight:bold; font-size:12px; color:red; "></h:outputText>
</h:panelGrid>
<br/>
<p:commandButton id="SubmitButton1" value="#{app.log_in}" action="#{userManageBean.submitLoginUser}" ajax="false" />
<p:commandButton value="#{app.forgotpwd}" onclick="dlg1.show();" ajax="false" />
</p:panel>
</h:form>
弹出
<h:form>
<p:dialog header="#{app.forgotpwd}" widgetVar="dlg1" resizable="false" width="300" showEffect="clip" hideEffect="fold" modal="true" visible="#{facesContext.validationFailed}" >
<table>
<tr>
<td><h:outputText value="#{app.username} : "/> <h:outputText value="*" style="color:red; font-size:12px;"/></td>
<td> <p:inputText id="txt" value="#{forgetPwdBean.userID}" required="true" requiredMessage="User Name is Required" />
<p:message for="txt" ></p:message>
<!-- <p:tooltip for="txt" value="#{viewcontrollerBundle.username}" showEffect="fade" hideEffect="fade" /> -->
</td>
</tr>
<tr><td>
<h:outputText value="#{app.emp_id} : "/><h:outputText value="*" style="color:red; font-size:12px;"/></td>
<td> <p:inputText id="txt1" value="#{forgetPwdBean.emailID}" required="true" requiredMessage="Email is Required"/>
<p:message for="txt1"></p:message>
<!-- <p:tooltip for="txt1" value="#{viewcontrollerBundle.mailid}" showEffect="fade" hideEffect="fade" /> -->
</td>
</tr>
<tr><td><p:commandButton value="#{app.submit}" action="#{forgetPwdBean.forgetPassword}" ajax="false"/>
</td></tr>
</table>
</p:dialog>
</h:form>
答案 0 :(得分:1)
以下代码会在您的表单验证失败时弹出对话框。
<p:dialog ... visible="#{facesContext.validationFailed}">
编辑(为什么没有上面的代码就显示对话框):
潜在的问题是你的commandButtons是非ajax,因此页面将被完全重新加载,你可能只看到一秒钟的对话
如果查看primefaces showcase,可以看到使用onclick =“dlg.show()”的按钮使用ajax:
<p:commandButton id="modalDialogButton" value="Modal" onclick="dlg2.show();" type="button"/>