【发布时间】:2013-02-06 19:14:36
【问题描述】:
我有一个具有必需属性的字段。当我按下 Accept 按钮保存一些数据而不在字段中输入任何值时,会显示一条错误消息。到现在为止还挺好。
但是,如果在那之后我决定单击 Cancel 按钮,则该错误消息会覆盖应该显示在 <p:dialog/> 元素内的确认消息。
注意:如果我改用<p:confirmDialog/> 组件,似乎没有问题,因为我猜它使用message="" 属性,没有<p:messages/> 标记。
XHTML
<p:dialog>
<p:outputPanel>
<h:form>
<h:outputText value="Field:"/>
<p:inputText id="field" value="" type="text" required="true" requiredMessage="You must complete the field" />
<p:growl id="messages" showDetail="true"/>
<p:commandButton id="dialogCancel" value="Cancel" oncomplete="confirmCancelDialog.show();" actionListener="#{controller.addCloseWarn}" />
</h:form>
</p:outputPanel>
</p:dialog>
<h:form>
<p:dialog id="confirmCancelDialog" header="Warning!" widgetVar="confirmCancelDialog" modal="true" >
<p:messages id="closeMessage" showDetail="true" autoUpdate="true" />
<p:commandButton id="confirm" value="Accept" onclick="..." />
<p:commandButton id="decline" value="Cancel" onclick="..." />
</p:dialog>
</h:form>
Bean 控制器
public void addCloseWarn(ActionEvent actionEvent) {
FacesContext.getCurrentInstance().addMessage("closeMessage", new FacesMessage(FacesMessage.SEVERITY_WARN, null,
"Are you sure you want to leave the page?"));
}
【问题讨论】:
-
你能发布 xhtml 页面的结构,其中表单的位置是输入字段和按钮吗?这个带有对话框的表单是否可能在另一个表单中?
-
@partlov 当然。在那里我编辑了帖子。带有对话框的表单与包含输入字段的表单是分开的。
标签: jsf dialog primefaces validation