【问题标题】:Correct way to update message-field when using JSF and Primefaces?使用 JSF 和 Primefaces 时更新消息字段的正确方法?
【发布时间】:2012-11-01 12:37:45
【问题描述】:

关于此还有另一个问题,但我无法解决我的问题。 jsf and primefaces update problem

从 : 开始的正确级别是多少?我只想更新messagePanel-messages,有什么问题。我尝试了 5 种不同的解决方案,但都没有成功。

<ui:composition template="./template.xhtml">

    <ui:define name="title">
        <h:outputText value="#{bundle.editXTZ_title} - #{XTZBean.username} - -->: #{RmaBean.selectedRma.rma}"></h:outputText>
    </ui:define>
    <h:panelGroup id="messagePanel" layout="block">
        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
    </h:panelGroup>
    <ui:define name="body">
        <h:form id="formi">
            <p:accordionPanel activeIndex="#{XTZBean.activeIndex}">  
                <p:tab title="Muokkaa"> 

......更多代码,然后

                <p:tab title="Avainsanat">  

                        <p:panelGrid id="avainsanaGrid" style="margin-top:20px;" styleClass="noBorders">
                            <p:row>
                                <p:column></p:column>
                                <p:column></p:column>


<p:row rendered="#{XTZBean.suljettu}">
                                <p:column></p:column>
                                <p:column></p:column>
                                <p:column><p:commandButton value="Tallenna" id="btnAvainsana" process="@this,avainsana" update="avainsanaGrid, :messagePanel"  
                                                           actionListener="#{XTZBean.talletaAvainsana}" style="width: 210px;"/></p:column>
                                <p:column></p:column>
                                <p:column></p:column>
                                <p:column></p:column>
                                <p:column></p:column>
                            </p:row> 
                         </p:panelGrid>  
                    </p:tab>

谢谢! 萨米人

【问题讨论】:

    标签: jsf primefaces facelets updates


    【解决方案1】:

    根据目前提供的信息(并假设&lt;ui:insert name="body"&gt; 本身不在另一个NamingContainer 组件中),:messagePanel 是正确的。

    但是&lt;h:panelGroup id="messagePanel"&gt; 不在正确的位置。它完全在模板定义之外,因此完全被忽略了。它必须放在任何&lt;ui:define&gt; 中。

    例如

    <ui:define name="body">
        <h:panelGroup id="messagePanel" layout="block">
            <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
        </h:panelGroup>
    
        <h:form id="formi">
            ...
        </h:form>
    </ui:define>
    

    另见:

    【讨论】:

    • 感谢您的回答!我得到了一个 javax.faces.FacesException: Cannot find component with identifier ":messagePanel" 引用自“j_idt6:formi:j_idt12:btnAvainsana”。
    • 你修复了模板吗?好吧,如果您仍然遇到此异常,那么显然还有另一个 NamingContainer 作为 &lt;ui:insert name="body"&gt; 的父级,根据异常消息,它很可能是自动生成的 ID j_idt6。给它一个固定的 ID 并改用:someId:messagePanel。有关详细信息,另请参阅我的答案中的第一个“另见”链接。
    • 给你的表单 prepend id false
    • @KeremBaydoğan:不,这不能解决问题。消息未放置在表单内。
    • @BalusC 是的,我也修复了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    相关资源
    最近更新 更多