+ Start a Discussion
Rajesh ShahRajesh Shah 

actionSupport rerender problem

I am having a problem using action Support and rerendering a section.

Following is the page code.

<apex:form id="AccountForm">
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}" />
<apex:commandButton value="Custom Save" action="{!saveCustom}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Account.Name}" />
<apex:inputField required="true" value="{!Account.AccountNumber}" />
<apex:inputField value="{!Account.Industry}" />
<apex:inputField value="{!Account.Has_Shipping_Address__c}" >
<apex:actionSupport event="onclick" action="{!changeShippingSection}" rerender="AccountForm" status="StatusChange"/>
<apex:actionStatus startText="Updating page ..." id="StatusChange"/>
</apex:inputField>


</apex:pageBlockSection>

<apex:pageBlockSection id="ShippingAddressSection" rendered="{!shippingSection}" Title="Shipping Address" >
<apex:inputField value="{!Account.ShippingCity}" />
<apex:inputField value="{!Account.ShippingState}" />
<apex:inputField value="{!Account.ShippingCountry}" />
<apex:inputField value="{!Account.ShippingPostalCode}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

 In the above code, when the Has Shipping Address field is clicked, the Shipping Address section should be visible. Following is the corresponding controller code

public void changeShippingSection()
{
shippingSection = account.Has_Shipping_Address__c;
//return null;
}

 It works perfectly fine when I AccountForm as Id in the rerender attribute. But if I put shippingAddressSection as Id in the attribute, no change happens even though function gets called.

Is this the intended behaviour or am I missing something?

 

 

 

Message Edited by Rajesh Shah on 10-08-2009 07:47 PM
Best Answer chosen by Admin (Salesforce Developers) 
Rajesh ShahRajesh Shah

Found the solution :smileyhappy:: (thanks to Sorna and Edwin)

It seems that if the component that I am rerendering has a rendered attribute, it doesn't works. So I had to wrap the pageBlockSection in an outputPanel with no rerenderd attribute. Now I just rerender the outputPanel. Attached is the updated code .

<apex:form id="AccountForm">
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}" />
<apex:commandButton value="Custom Save" action="{!saveCustom}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Account.Name}" />
<apex:inputField required="true" value="{!Account.AccountNumber}" />
<apex:inputField value="{!Account.Industry}" />
<apex:inputField value="{!Account.Has_Shipping_Address__c}" >
<apex:actionSupport event="onclick" action="{!changeShippingSection}" rerender="ShippingAddressPanel" status="StatusChange"/>
<apex:actionStatus startText="Updating page ..." id="StatusChange"/>
</apex:inputField>

</apex:pageBlockSection>
<apex:outputPanel id="ShippingAddressPanel">
<apex:pageBlockSection id="ShippingAddressSection" rendered="{!shippingSection}" Title="Shipping Address" >
<apex:inputField value="{!Account.ShippingCity}" />
<apex:inputField value="{!Account.ShippingState}" />
<apex:inputField value="{!Account.ShippingCountry}" />
<apex:inputField value="{!Account.ShippingPostalCode}" />
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>

 

 

 

 

 

 

Message Edited by Rajesh Shah on 10-09-2009 04:47 PM

All Answers

Rajesh ShahRajesh Shah
Any thoughts on the above?
Edwin VijayEdwin Vijay

Hi.. try using an outputpanel and rerender the outputpanel, place your pageblocksection inside the outputpanel..

I too faced a similar issue, but i do not remember the cause... Maybe, the pageblocksection in turn has a rerender which causes the problem..

 

Cheers!!

Rajesh ShahRajesh Shah

Found the solution :smileyhappy:: (thanks to Sorna and Edwin)

It seems that if the component that I am rerendering has a rendered attribute, it doesn't works. So I had to wrap the pageBlockSection in an outputPanel with no rerenderd attribute. Now I just rerender the outputPanel. Attached is the updated code .

<apex:form id="AccountForm">
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
<apex:commandButton value="Cancel" action="{!cancel}" />
<apex:commandButton value="Custom Save" action="{!saveCustom}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Account.Name}" />
<apex:inputField required="true" value="{!Account.AccountNumber}" />
<apex:inputField value="{!Account.Industry}" />
<apex:inputField value="{!Account.Has_Shipping_Address__c}" >
<apex:actionSupport event="onclick" action="{!changeShippingSection}" rerender="ShippingAddressPanel" status="StatusChange"/>
<apex:actionStatus startText="Updating page ..." id="StatusChange"/>
</apex:inputField>

</apex:pageBlockSection>
<apex:outputPanel id="ShippingAddressPanel">
<apex:pageBlockSection id="ShippingAddressSection" rendered="{!shippingSection}" Title="Shipping Address" >
<apex:inputField value="{!Account.ShippingCity}" />
<apex:inputField value="{!Account.ShippingState}" />
<apex:inputField value="{!Account.ShippingCountry}" />
<apex:inputField value="{!Account.ShippingPostalCode}" />
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>

 

 

 

 

 

 

Message Edited by Rajesh Shah on 10-09-2009 04:47 PM
This was selected as the best answer