如何从命令按钮在另一页更新Primefaces部件在一个页面时两页被包括在一个页部件、按钮、命令、页面

2023-09-10 13:50:32 作者:告别过去种种

我有2页

input.xhtml

<h:form>
    <p:panelGrid>
        <p:row>
            <p:column>
                <h:outputText value="Name : "/>
            </p:column>
            <p:column>
                <p:inputText id="name" value="#{inputBean.name}"/>
            </p:column>
        </p:row>
        <p:row>
            <p:column colspan="2" >
                <p:commandButton action="#{inputBean.buttonAction}" value="Submit"/>
            </p:column>
        </p:row>
    </p:panelGrid>
</h:form>

display.xhtml

<h:form id="form1">
    <h:outputText value="#{inputBean.name}" id="dis123"/>
</h:form>

如果我象下面这样一个页面包括他们的

If I include both of them in a single page like below

的index.xhtml

<p:accordionPanel widgetVar="main" multiple="true">
    <p:tab title="Input">
        <ui:include src="input.xhtml"/>
    </p:tab>

    <p:tab title="Output">
        <ui:include src="display.xhtml"/>
    </p:tab>
</p:accordionPanel>

我可以叫更新=dis123 input.xhtml

推荐答案

没有,你不能。像相对客户端ID 更新=dis123基本搜索在同一 NamingContainer 父组件是在你的情况下, &LT; H:形式GT; 的第一页。但是,没有这样的组分存在。它实际上是在不同的 NamingContainer 父。您需要提供一个绝对的客户端ID来代替:更新=:窗口1:dis123

No, you can't. A relative client ID like update="dis123" basically searches in the same NamingContainer parent component which is in your case the <h:form> of the first page. However, no such component exist. It's actually in a different NamingContainer parent. You need to provide an absolute client ID instead: update=":form1:dis123".

对于初学者来说,一个简单的方法来计算正确的绝对客户端ID是通过看在JSF生成的HTML输出(单击鼠标右键,查看源文件的浏览器),用于在生成的HTML元素的ID所需的组件,然后preFIX用

For starters, an easy way to figure the right absolute client ID is by just looking in the JSF-generated HTML output (rightclick, View Source in browser) for the generated HTML element ID of the desired component and then prefix it with :.

请注意,这一切都无关,包括。具有在单一页面中的所有code时,你就必须有完全相同的问题。

Please note that this all has nothing to do with includes. You'd have had exactly the same problem when having all the code in a single page.

How引用组件的JSF AJAX?无法找到标识符QUOT组成部分;富&QUOT;鉴于