1

I am tying to hide and show apex:pageblocker on the bases of the value in list. But i am not able to show when value is not been selected. My anybody tell me what is wrong. I am getting value in the pageblockTable.

my code:

     <apex:commandButton action="{!addSelected}" value="Add Selected" reRender="id_ViewSelectedItem"/>

     <apex:pageBlock title="Selected Installed Items" id="id_ViewSelectedItem"  rendered="{!IF(theInstalledItem_checkedView.size>0, true, false)}">
     <apex:pageBlockTable value="{!theInstalledItem_checkedView}" var="ins" >
2
  • I tried in this way also rendered="{!theInstalledItem_checkedView != null || theInstalledItem_checkedView.size>0}"
    – AnuRaj
    Jan 22, 2013 at 11:29
  • What is the problem? What you can not to show? Jan 22, 2013 at 11:54

1 Answer 1

6

It seems to be related to the use of 'reRender' on your commandButton. I am not 100% why, the docs don't seem to indicate any restrictions around targeting components in a rerender that then use the rendered attribute. So this could be a VF bug. Anyway here are a couple of ways to get this to work as your expecting...

  • If you remove the 'reRender' attribute it works
  • If you add an outer panel wrapping the page block section it works.

My test code (slightly adapted from your sample) below, reflects the second option above.

<apex:page controller="HideAndShowController">
    <apex:form>
        <apex:commandButton action="{!addItem}" value="Add Item"
            reRender="outerPanel" />
        <apex:outputPanel id="outerPanel">
            <apex:pageBlock title="Selected Installed Items"
                id="id_ViewSelectedItem"
                rendered="{!IF(myList.size > 0, true, false)}">
                <apex:pageBlockTable value="{!myList}" var="ins">
                    <apex:column value="{!ins}" />
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

Update: This blog from Bob Buzzard offers further insight into this issue. Nice one Bob!

2
  • Interesting article. I always assumed it was something to do with the fact that because the reRender action only re renders the element's children, excluding itself (which I found made some kind of sense to me)
    – Ben
    Jan 22, 2013 at 17:07
  • How to do it without outputPanel? Apr 27, 2015 at 12:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .