你好,我有更新问题,我有一些复合组件嵌套在少数组件,我想更新其中的一些,什么是正确的方法?第二,我可以更新div?
代码示例:
<div id="outer">
<p:commandButton id="button"/>
<div id="inner">
<h:form id="form">
<mycomponents:test whatToUpdate="form panel button outer label">//here problem
</h:form>
</div>
</div>
<div id="outer2">
<h:form id="form">
<p:panelGroup id="panel">
<p:label id="label" value="value"/>
</p:panelGroup>
</h:form>
</div>
答案 0 :(得分:0)
使用 p:outputPanel :
代替div<p:outputPanel id="outer">
<p:commandButton id="button" update="inner"/>
<p:outputPanel id="inner">
<h:form id="form">
<mycomponents:test whatToUpdate="form panel button outer label">//here problem
</h:form>
</p:outputPanel>
</p:outputPanel>
答案 1 :(得分:0)
我找到了一些简单的方法来更新嵌套组件(我想是这样),我希望有人会发现这个有用。 我们的想法是将styleClass设置为primefaces组件(不知道一些随机的styleClass名称)并使用该styleClass更新组件。 例如:
...bla bla nested components
<p:panel id="somePanel" styleClass="somePanelStyle">
`... bla bla nested components`
<p:panel>
... bla bla nested components
如果你需要通过按钮更新它(在这个带有id&#34; somePanel&#34;的面板中),例如:
<p:commanButton update="@(.somePanelStyle)"
目前我只使用这种方式,因为它易于实现更新和搜索(在eclipse中的CTRL + H),其中是该组件。
关于更新div,BalusC得到了一些不错的答案: Answer about updating divs from JSF by BalusC
答案 2 :(得分:0)
在显示我的答案之前,我想做一些假设:
h:form
使用相同的标识符,这是一个错误whatToUpdate
的是什么,但我想它会绑定到某个update
属性。 form
属性中的whatToUpdate
值引用外层组件。JSF
上下文中我不建议您使用div,唯一可以放置它们的地方是HTML
模板代码。JSF
上下文中我建议您不要更新h:form
组件之外的元素,尤其是当您的p:commandButton
是提交按钮时。h:form
里面,只需使用表格引用就可以更容易地更新子树内的每个组件。这是我的,这就是我在你的位置所做的事情:
<h:form id="form1">
<p:outputPanel id="outer">
<p:commandButton id="button"/>
<p:outputPanel id="inner">
<mycomponents:test whatToUpdate="@form :form2">
</p:outputPanel>
</p:outputPanel>
</h:form>
<h:form id="form2">
<p:outputPanel id="outer2">
<p:panelGroup id="panel">
<p:label id="label" value="value"/>
</p:panelGroup>
</p:outputPanel>
</h:form>
通过这种方式,您将以最简单的方式更新form1
和form2
的每个组件,如果要在其中一个子树中添加一些组件,则不必再担心。< / p>
如果我错了一些假设,请告诉我。