问题
Is it possible to update child components of a composite component just by specifying the parent composite ID? E.g. if I have:
<composite:interface>
<composite:attribute name="value" type="..." required="true"/>
</composite:interface>
<composite:implementation>
<p:treeTable id="main-tree" ...>
...
</p:treeTable>
</composite:implementation>
and to use it somehow like this:
<my:comp id="composite-component" />
...
<p:ajax update="composite-component" />
Is that possible? Right now the only way I see is to specify the child component ID explicitly:
<p:ajax update="composite-component:main-tree" />
回答1:
This can be done by wrapping a <div> around your composite components implementation and set the div's id=#{cc.clientId}:
<html ...>
<composite:interface>
...
</composite:interface>
<composite:implementation>
<div id="#{cc.clientId}">
...
</div>
</composite:implementation>
</html>
And in the using page:
<my:comp id="composite-component" />
....
<h:commandButton value="Update first name">
<f:ajax execute="composite-component" render="composite-component">
</h:commandButton>
The <p:ajax>should work accordingly.
来源:https://stackoverflow.com/questions/9726818/jsf-updating-a-composite-component