Bart1990
Bart1990

Reputation: 255

How to render an h:panelGroup correctly when using f:ajax and a rendered attribute?

I'm developping an application in JSF2.0. I encountered a problem when mixing ajax and a panelGroup with a rendered attribute.

My page contains 3 panels. In the first panel the user selects an item from a <h:selectOneMenu>. This causes to render the second panel.

The second panel contains an h:dataTable that is connected to a DataModel in the backing bean. The values of the dataTable are determined by the item that was chosen in the <h:selectOneMenu> of the first panel. Each row in the table contains a commandLink to view detailed info about the item of that row:

<h:commandLink action="#{faseController.selectInvulling}">
      <f:ajax render="@form" execute="@form" />
</h:commandLink>

Clicking on the commandLink the third panel gets rendered:

<h:panelGroup rendered="#{faseController.invullingSelected}" layout="block" styleClass="panelElement" id="invulling">
       <label>
          <span>Datum:</span>
          <h:inputText value="#{faseController.selectedInvulling.datum}" required="true" requiredMessage="Gelieve een datum in te vullen." converterMessage="Gelieve een geldige datum in te vullen (dd/mm/jjjj)." >
                 <f:convertDateTime pattern="dd/MM/yyyy" />
          </h:inputText>
       </label>
       <label>
           <span>Evaluatie</span>
           <h:inputTextarea value="#{faseController.selectedInvulling.evaluatie}" cols="100" />
       </label>
       <label>
          <span>Methode</span>
          <h:inputTextarea value="#{faseController.selectedInvulling.methode}" cols="100" />
       </label>
</h:panelGroup>

This is where I encounter a problem. The first time I click on a commandLink to view the detailed info about that row in the table, I get the correct data in the third panel. Afterwards I change the item in the <h:selectOneMenu> of the first panel: the correct corresponding dataTable gets rendered in the second panel. However this time when I click on a commandLink in the table to view the details of that item, I get to see the info from the item I clicked the first time.

If I ommit rendered="#{faseController.invullingSelected}" everything works fine, but this causes confusion in the view, since the third panel is now always rendered.

All three panels are located in the same form. My backing bean is ViewScoped. What am I doing wrong? Any help woud be greatly appreciated.

Upvotes: 1

Views: 3747

Answers (2)

Naveen Chanda
Naveen Chanda

Reputation: 44

Try using this.

<a4j:commandLink action="#{faseController.selectInvulling}" execute="@this"
render="thirdPanelId" limitRender="true"/> 

Execute only the components which you want to process and render only the components which needs to be refreshed.

Upvotes: 0

BalusC
BalusC

Reputation: 1108642

This can happen if you're doing business logic in an getter method instead of in an (action)listener method. I also wonder if you really need to execute and render the entire form. Try to be more specific in specifying the elements which are to be executed and/or re-rendered.

The question is way too broad and the code is not complete enough in order to pinpoint the real cause and propose the a ready-to-use solution.

Upvotes: 1

Related Questions