You need to sign in to do that
Don't have an account?
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?
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>
All Answers
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!!
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>