【问题标题】:primefaces p:commandButton update property fails to update p:messages componentprimefaces p:commandButton 更新属性无法更新 p:messages 组件
【发布时间】:2016-10-26 14:49:05
【问题描述】:

我有一个 PrimeFaces <p:commandButton update=":messages",它在发送表单后不显示 p:messages,但如果我使用 update="@all",它会更新 p:messages,我可以看到显示的消息。

我尝试了许多其他组合,例如update="messages"update="NewRegistryForm:messages"update="@form :messages"render=":messages"... 但似乎没有其他方法。知道为什么会发生这种情况吗?

RegistryInputNewBean.processRequest 我只是像这样更新消息组件:

FacesContext.getCurrentInstance().addMessage(
    null,
    new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "error_processing_request")
);

mytemplate.xhtml,包含p:messages,是这样的:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    lang="en"
>
    <f:view contentType="text/html" encoding="UTF-8" locale="en">
        <h:head>
            <title>test</title>
        </h:head>
        <h:body id="pageBody">
            <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" showSummary="false"/>
            <ui:insert name="content" />
        </h:body>
    </f:view>
</html>

myform.xhtml是这样的:

<!DOCTYPE html>
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:p="http://primefaces.org/ui"
>
<ui:define name="content">
<ui:composition template="mytemplate.xhtml">
        <h:form id="NewRegistryForm">
                <p:commandButton 
                    id="sendButton"
                    type="submit" 
                    action="#{registryInputNewBean.processRequest}" 
                    update="@all"
                    style="display:none" />
        </h:form>
</ui:composition>
</ui:define>
</html>

【问题讨论】:

    标签: primefaces jsf-2


    【解决方案1】:

    p:messages 不在表单内,这就是为什么按钮不会单独更新组件的原因,只有在您输入 @all 时才会更新页面中的所有组件。

    如果您将另一个包含p:message 的表单放入其中,您将能够使用update="fooForm:fooMessages" 更新组件

    【讨论】:

      【解决方案2】:

      你可以在 bean 上更新

      喜欢

      RequestContext rc = RequestContext.getCurrentInstance();
      rc.update("id");
      

      【讨论】:

      • 是的,你可以,但这会导致与在 p:commandButton 上使用 update 不同的行为吗?
      猜你喜欢
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 2011-06-02
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多