1

Hello I'am having problems with updates, I have some composite component nested in few components and i want to update some of them, what is proper way ? Second can i update div?

Code example:

<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>
user2771738
  • 913
  • 11
  • 31

3 Answers3

0

Instead of divs use p:outputPanel:

<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>
  • Ye sure, but I got problem how to call thoose id of components "form panel button outer label" because not all are seen from view – user2771738 Feb 03 '14 at 08:36
  • Second I can't update divs? I have problem cause i got always stack trace when i put div id in update – user2771738 Feb 03 '14 at 11:09
0

I found some easy way for updating nested components ( i think so ) and i hope that someone will find this usefull. The idea is to set styleClass to primefaces component ( dont know some random styleClass name ) and update component using that styleClass. For example:

...bla bla nested components
<p:panel id="somePanel" styleClass="somePanelStyle">
`... bla bla nested components`
<p:panel>
... bla bla nested components

any if you need to update it ( in this example panel with id "somePanel") via button for example:

<p:commanButton update="@(.somePanelStyle)"

Currently im only using this way because its easy to implements update and search (CTRL+H in eclipse) where is that component.

About updating divs, BalusC got some nice answer: Answer about updating divs from JSF by BalusC

Community
  • 1
  • 1
anotherUser
  • 551
  • 6
  • 29
0

Before to show my answer I would like to do some assumption:

  • First of all you use the same identifier for both h:form and this is an error
  • I don't know what exactly represents whatToUpdate into your composite but I guess it is bound to some update attribute.
  • I suppose that form value inside whatToUpdate attribute of your composite component references the outer one.
  • inside JSF context I don't recommend you to use div, the only place where i would put them is HTML template code.
  • in JSF context I don't recommend you to update element outside h:form component, especially if your p:commandButton is a submit button.
  • I noticed that you would like update only components into two sub-tree, if you put everything inside a h:form will be more easy update each components inside the sub-tree just using form referencing.

This is my this is what I would do in your place:

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

In this way you will update each component of form1 and form2 in the easiest way possible and you not have to worry anymore if you would add some components in one of the sub-trees.

Let me know if I wrong some assumption.

giaffa86
  • 708
  • 1
  • 9
  • 22