+ Start a Discussion
cmarz_1cmarz_1 

Command button ReRender happens before Action is complete

I have a command button with an action and a rerender set.  The action fills up a list and the rerender is for a pageblock that displays the list.  The pageblock's render is set to not show if the list is null (starting value).  So when the button is clicked the action should fill up the list, the rerender then should allow the pageblock to show.  Except when I run debug on the code I can see the get fuction for the list being called proir to the action of filling the list is being completed.  As a consequence the pageblock is not being displayed because it thinks the list is still null.  Accounding to the VF docs "ReRender: The ID of one or more components that are redrawn when the result of an AJAX update request returns to the client."  This doesn't seem to be the case.  Anyone have any ideas?

 

<apex:commandButton action="{!fillProductList}" value="Add Products" reRender="AddProductsTable"  status="status"  />     <apex:actionStatus id="status" startText="loading..."/>
    
<apex:pageBlock title="Add Products" id="AddProductsTable" rendered="{!NOT(ISNULL(prodList))}" >
       <apex:pageBlockTable value="{!prodList}" var="p" cellpadding="4" >
           <apex:column headerValue="Name" > {!p.Id} </apex:column>
</apex:pageBlockTable>
        </apex:pageBlock>

 

 

code

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

You can't specifiy a rerender target for something that might not be there at some point during the life of the page, if you want to be able to bring it back.  See this thread.

 

Probably just need to surround the pageBlock with an outputPanel and then move the id up to the panel:

 

<apex:commandButton rerender="AddProductsTable"/> <apex:outputPanel id="AddProductsTable"> <apex:pageBlock rendered="{!NOT(ISNULL(prodList))}"> </apex:pageBlock> </apex:outputPanel>

 

That way you're always asking the outputPanel to rerender, and since it's always on the page, you should be able to find it.

 

Everything inside the outputPanel will ge re-evaluated. 

 

All Answers

Ron HessRon Hess

would need to see some of your controller code to be sure, but you may have luck if you put an outputPanel around the pageblock , and specify an ID for that , and then rerender the outputPanel.  put the rendered attribute on the output panel also.

 

not sure this will work, but that's what i would try.

jwetzlerjwetzler

You can't specifiy a rerender target for something that might not be there at some point during the life of the page, if you want to be able to bring it back.  See this thread.

 

Probably just need to surround the pageBlock with an outputPanel and then move the id up to the panel:

 

<apex:commandButton rerender="AddProductsTable"/> <apex:outputPanel id="AddProductsTable"> <apex:pageBlock rendered="{!NOT(ISNULL(prodList))}"> </apex:pageBlock> </apex:outputPanel>

 

That way you're always asking the outputPanel to rerender, and since it's always on the page, you should be able to find it.

 

Everything inside the outputPanel will ge re-evaluated. 

 

This was selected as the best answer
JohannesBorrmanJohannesBorrman

 

Could you tell me what the !prodlist method in you controller looks like? i'm having nearly the same problem and couldn't fix it with an outputlabel. My method for the pageblock returns an object of items from a query.