我需要你的助手来更新 <p:message>
JSF 页面中的组件曾经是非 ajax <p:commandButton>
被点击。目前在这种情况下,我需要验证员工编号是否为空,然后在消息组件中显示错误消息,否则,不显示任何内容。但是现在,一旦 <p:commandButton>
表格就没有显示任何内容。被点击。
下面是 JSF 代码:
<h:form id="form">
<p:inputText value="#{pdf.refNo}"/>
<p:message id="message" for=":form:cmd2" showDetail="true"/>
<p:commandButton id="cmd2"
value="Validate"
ajax="false"
actionListener="#{pdf.validate}"/>
</h:form>
Java bean 是:
public void validate() {
if (refNo.equals("") || refNo == null) {
FacesContext.getCurrentInstance().addMessage(":form:cmd2", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Please enter the Employee No."));
}
}
那么上面的代码是否正确,点击按钮后如何显示消息?
最佳答案
使用 for
解决了这个问题为了指定目标组件。所以在上面的例子中,我提到了命令按钮,所以我们点击它,应该更新一个特定的消息组件。这可以通过以下方式完成:
<p:message id="message" for="cmd2" showDetail="true"/>
或
<p:message id="message" for="form:cmd2" showDetail="true"/>
关于ajax - 如何更新与 <p :commandButton ajax ="false">? 关联的消息组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32009931/