ajax - 当两个页面都包含在一个页面中时,如何从另一个页面的命令按钮更新一个页面中的Primefaces组件

标签 ajax jsf primefaces

我有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>

如果我将它们都包含在一个页面中,如下所示
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>

如何从update="dis123"中的命令按钮调用input.xhtml

最佳答案

不,你不能。像update="dis123"这样的相对客户端ID基本上在相同的NamingContainer父组件中进行搜索,在您的情况下,该组件就是第一页的<h:form>。但是,不存在这样的组件。它实际上在另一个NamingContainer父级中。您需要提供一个绝对的客户端ID:update=":form1:dis123"
对于初学者来说,找到正确的绝对客户端ID的简单方法是,只需在JSF生成的HTML输出(右键单击,浏览器中的View Source)中查找所需组件的生成的HTML元素ID,然后在其前面加上:即可。
请注意,这与包含项无关。将所有代码放在一个页面中时,您会遇到完全相同的问题。
也可以看看:

  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
  • 关于ajax - 当两个页面都包含在一个页面中时,如何从另一个页面的命令按钮更新一个页面中的Primefaces组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14438707/

    相关文章:

    JSF如何在Netbeans7.1中升级到Mojarra 2.1.21(只是子jsf-api.jar和jsf-impl.jar失败)

    jsf-2 - 如何在 primefacs columnGroup 中设置货币格式?

    JSF 2.0 + Primefaces : Find all child components of a certain type

    asp.net - 与多行 asp :TextBox on full postback vs. 异步回发不同的换行符

    php - jQuery Ajax 似乎正在 POSTing,但无法捕获值

    javascript - xmlHttp.status==200 永远不会为真

    jquery - 如何让循环中的多个ajax请求按顺序返回值?

    jsf - 使用 Netbeans 指定调试源

    java - JSF <trh :script>rendering and running order

    java - 使用 primefaces p :media plugin 在 liferay 上显示 pdf