apex:outputPanel not rerendering

I have a VisualForce page that contains some output panels. When a command link is clicked, some conditions changes and depending on the some of the panels are rerendered or not.

My problem is that some of the panels get rerendered, whereas other don't, although they depend on the same condition.

My code is:
<apex:form>
<apex:outputPanel id="menu">
<apex:outputPanel id="itemOne" rerendered="${selectedItem == 1}">Item One</apex:outputPanel>
<apex:outputPanel id="itemTwo">
<apex:outputPanel id="subitemTwo" rerendered="${selectedItem == 1}">
Subitem
</apex:outputPanel>
</apex:outputPanel>
</apex:outputPanel>

<apex:commandLink value="Refresh" action="{!refreshMenu}" reRender="itemOne,itemTwo" ></apex:commandLink>

</apex:form>

When I click the "Refresh" command link, panels "itemTwo" and "subitemTwo" get refreshed, but panel "itemOne" does not. This is weird, because "itemOne" and "subitemTwo" depend on the same condition.
graham on 20-02-2013 11:38
The reason why "subitemTwo" gets refreshed, and "itemOne" does not, is that in your command link the rerender attribute specifies itemOne and itemTwo to be refreshed. The rule is that only items that don't have a rerendered attribute can be refreshed. This is why if you want to conditionally rerender an output panel, you should put it in another panel that is always rerendered.

Then in the command link you specify only output panels that have no rerendered condition to be rerendered.

A working code for your problem would be:
<apex:form>
<apex:outputPanel id="menu">
<apex:outputPanel id="itemOneWrapper">
<apex:outputPanel id="itemOne" rerendered="${selectedItem == 1}">Item One</apex:outputPanel>
</apex:outputPanel>
<apex:outputPanel id="itemTwo">
<apex:outputPanel id="subitemTwo" rerendered="${selectedItem == 1}">
Subitem
</apex:outputPanel>
</apex:outputPanel>
</apex:outputPanel>

<apex:commandLink value="Refresh" action="{!refreshMenu}" reRender="itemOneWrapper,itemTwo" ></apex:commandLink>

</apex:form>

Note the itemOneWrapper output panel that wraps itemOne and is referenced in the command link.
graham on 20-02-2013 11:43

Post an answer

Do you have a solution to this problem, or want to comment on it? Other users will appreciate your help!
Your answer or comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems