1
我有一个具有必需属性的字段。当我按接受按钮来保存一些数据而不在该字段中输入任何值时,会显示一条错误消息。到现在为止还挺好。 但是,如果之后我决定点击取消按钮,该错误消息将覆盖原本应在<p:dialog/>
元素内显示的确认消息。Primefaces:必填字段消息覆盖<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>
豆控制器
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
@partlov当然。我在那里编辑了这篇文章。带有对话框的表单与包含输入字段的表单分开。 – CountD