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
Dman100Dman100 

setting pageBlock visibility using rendered

I have a two pageBlocks and I want to display the second pageBlock after the command button the first pageBlock is fired.

 

I created a boolean public property in my controller:

 

public Boolean IsShown{ get; set; }

 

I set the property in my method:

 

public PageReference ChildAccountOwnershipCount() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; ChildAccountCount = [Select Count() From Account where ParentId =: parent.Id]; ChildAccountCount += ChildAccountCount + 1; IsShown = true; return null; }

 

 

Here is my VF code:

 

<apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit" id="ChildAccountsPageBlock"> <apex:pageBlockButtons > <apex:commandButton action="{!ChildAccountOwnershipCount}" value="Update" rerender="ChildAccountsPageBlock, Msg, ChildAccountConfirmPageBlock" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock id="ChildAccountConfirmPageBlock" rendered="{!IsShown}" > <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Confirm" rerender="ChildAccountsPageBlock, Msg" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection > <apex:outputLabel value="You are about to update {!ChildAccountCount} accounts. Please click to confirm." /> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion>

 

 

 

The second pageBlock does not open when the page posts back?

 

Thanks.

jwetzlerjwetzler

lots and lots of posts regarding this on the forums.  move the id of your pageBlock to your actionRegion and I think it will work.

 

If that pageBlock is not initially rendered on your page, you won't be able to rerender it because it can't be found.

Dman100Dman100

I tried moving the id of the pageBlock to the actionRegion, but it still does not render the pageBlock.

 

<apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit" id="ChildAccountsPageBlock"> <apex:pageBlockButtons > <apex:commandButton action="{!ChildAccountOwnershipCount}" value="Update" rerender="ChildAccountsPageBlock, Msg, ChildAccountConfirmPageBlock" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion id="ChildAccountConfirmPageBlock" rendered="{!IsShown}" > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Confirm" rerender="ChildAccountsPageBlock, Msg, ChildAccountConfirmPageBlock" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection > <apex:outputLabel value="You are about to update {!ChildAccountCount} accounts. Please click to confirm." /> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion>

jwetzlerjwetzler

You tried moving the id and the rendered attributes together (not what I said to do), thus creating the same problem for yourself on a different component.  Again, your actionRegion is not going to be rendered on the page, therefore the ID of the actionRegion will not be on the page, thus it will not be found when you ask it to find the ID on the page to be rerendered.

 

Move the id to the actionRegion but leave the rendered attribute on the page block. It will then find the actionRegion (which is always rendered) and ask the actionRegion to rerender everything inside of it, re-evaluating the rendered expression on your pageBlock.

Message Edited by jwetzler on 10-20-2009 12:04 PM
Dman100Dman100

Following your instructions as I understand them, I moved the id to the actionRegion and left the rendered attribute in the pageBlock.  The rerender attribute on the command button specifies the id in the actionRegion.

 

<apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit" id="ChildAccountsPageBlock"> <apex:pageBlockButtons > <apex:commandButton action="{!ChildAccountOwnershipCount}" value="Update" status="ChildAccountsLoadingStatus" rerender="ChildAccountsPageBlock, Msg, Panel1" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion id="Panel1" > <apex:pageBlock rendered="{!isShown}"> <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Confirm" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:outputLabel value="You are about to update {!ChildAccountCount} accounts. Please click to confirm." /> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion>

The pageBlock defined by the actionRegion id="Panel1" does not display.  Did I misunderstand again or did I miss something?

Rajesh ShahRajesh Shah

I had a similar problem with PageBlockSections. What I found is that we you are trying to render a component which has rendered attribute, it doesn't works. Embed the pageBlock inside a outputPanel which has no rendered attribute and then try to rerender the outputPanel. That should work. For more details, check the following thread:

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=17485#M17485