function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VarunCVarunC 

Show / Hide pageblock on button click

Hi,

I'm trying to show or hide a PageBlock on click of a commandbutton.

here is what i'm trying to do:

Button Code:
Code:
<apex:commandButton action="{!processSelected}" value="Process Selected" reRender="pageBlock, pageBlockProcessed" status="AjaxStatus"></apex:commandButton>

 
My Page Code:
Code:
<apex:pageBlock title="Selected Records" id="pageBlockProcessed">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageBlockTable value="{!selectedContacts}" var="l" rendered="{!NOT(ISNULL(selectedContacts))}">
        <apex:column value="{!l.Name}"></apex:column>
        <apex:column value="{!l.Email}"></apex:column>
        <apex:column value="{!l.Phone}"></apex:column>
    </apex:pageBlockTable>
</apex:pageBlock>

 "selectedContacts" is populated with Selected Contacts on CommandButton click. But the Page Block (pageBlockProcessed) does not show or hide when i populate and hide data in "selectedContacts" :(.


My Full page layout is something like this:
Code:
<apex:page controller="Contacts">
<apex:sectionHeader title="Contact List"></apex:sectionHeader>
<apex:form >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock title="" id="pageBlockFilter">
... Some VF Code ...
<apex:commandButton action="{!processSelected}" value="Process Selected" reRender="pageBlock, pageBlockProcessed" status="AjaxStatus"></apex:commandButton>
</apex:pageBlock>
<br/>
<div style="width:100%;display:{!IF(ISNULL(selectedContacts),'block','none')}">
<apex:pageBlock title="Selected Records" id="pageBlockProcessed">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!selectedContacts}" var="l" rendered="{!NOT(ISNULL(selectedContacts))}">
<apex:column value="{!l.Name}"></apex:column>
<apex:column value="{!l.Email}"></apex:column>
<apex:column value="{!l.Phone}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</div>
<apex:pageBlock title="" id="pageBlock">
<apex:pageBlockTable value="{!contacts}" var="c" rendered="{!NOT(ISNULL(contacts))}" rows="{!pageSize}">
... Some VF Code ...
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 
The code in RED above needs to Be Shown and Hidden on click of "Process Selected" button.

CAN ANYONE help me here ? ... plz ...

At this point the page BLOCK is displaying At All times, selectedContacts is able to only hide the pageBlockTable, as and when there is data in the list. But i want FULL page block to Show and Hide with presence of data in selectedContacts.

- Varun
XactiumBenXactiumBen
Try creating a new method in the controller that checks for the state of selectedContacts.

Something like this:
Code:
public boolean getRendered()
{
Boolean render = (selectedContacts == null || selectedContacts.size() == 0 — false : true);

return render;
}

 
Then in your page you can just use rendered="{!Rendered}"

Does that help?
jwetzlerjwetzler
In addition to what Ben just suggested you'll also want to do something like this:
Code:
      
<apex:outputPanel id="thePanel">
<apex:pageBlock title="Selected Records" id="pageBlockProcessed" rendered="{!rendered}">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!selectedContacts}" var="l">
<apex:column value="{!l.Name}"></apex:column>
<apex:column value="{!l.Email}"></apex:column>
<apex:column value="{!l.Phone}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>


And then your commandButton should only need to rerender "thePanel" each time (because it will also rerender everything inside of the outputPanel.
VarunCVarunC
Thanks a Lot ... :) .. to BOTH of you ...

it worked like a charm now .. with outputPanel and that Rendered variable fix ... :D ...

Thanks again .. I was upto this issue for around 2 days .... i think I still miss many-many of the VF tags to learn :)
knicholsknichols
Does this work when the object you are querying has columns that a profile can't see?  For example, we have two different pricing objects and the rep's profile controls which one they can see.  The problem is they still see the header information for both objects.  So it appears, it returns rows from the query but just doesn't show them in the VF page.