ajax 当两个页面都包含在一个页面中时,如何从另一页面的命令按钮更新一个页面中的 Primefaces 组件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14438707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update Primefaces component in one page from command button in another page when both pages are included in one page
提问by Kishor Prakash
I have 2 pages
我有2页
input.xhtml
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
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
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>
can I call update="dis123"from command button in input.xhtml?
我可以update="dis123"从命令按钮调用input.xhtml吗?
回答by BalusC
No, you can't. A relative client ID like update="dis123"basically searches in the same NamingContainerparent component which is in your case the <h:form>of the first page. However, no such component exist. It's actually in a different NamingContainerparent. You need to provide an absolute client ID instead: update=":form1:dis123".
不,你不能。类似的相对客户端 IDupdate="dis123"基本上在同一个NamingContainer父组件中搜索,在您的情况下<h:form>是第一页。但是,不存在这样的组件。它实际上是在不同的NamingContainer父级中。您需要提供一个绝对的客户端 ID:update=":form1:dis123"。
For starters, an easy way to figure the right absolute client ID is by just looking in the JSF-generated HTML output (rightclick, View Sourcein browser) for the generated HTML element ID of the desired component and then prefix it with :.
对于初学者来说,计算正确的绝对客户端 ID 的一种简单方法是在 JSF 生成的 HTML 输出(右键单击,在浏览器中查看源代码)中查找所需组件的生成的 HTML 元素 ID,然后在它前面加上:.
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.
请注意,这一切都与包含无关。当在一个页面中包含所有代码时,您会遇到完全相同的问题。

