anusha(salesforce developer)

Action Support or ActionFunction rerender Problem with Pagereference

Challenge of passing parameters to sales force custom controller and diverting to another page after updating respected record .This is because of re render attribute of Action support .This can be solved using action function and action support together.
Please refer to below example. 

Apex Page :-

<apex:page extensions="testAccountController" standardcontroller="Account">
<html><script type="text/javascript">
function calDiversion(){
derectToAccount();
                }
</script> 

       <apex:form>
         <apex:pageblock>
                  <apex:pageblocktable rendered="{!testAddress.size&gt;0}" value="{!testAddress}" var="addres">
                         <apex:column headervalue="StreetName" value="{!addres.StreetName}"/>
                         <apex:column headervalue="City" value="{!addres.City}"/>
                         <apex:column>
                               <input id="radio" name="selectRadio" type="radio" />
 <!---------------------- Parameters to pass to controller on selection of radio button     --------------->
                                    <apex:actionsupport action="{!updateTestaccountAdress}" event="onclick"  
                                                                     oncomplete="calDiversion()" rerender="ResultPanel">
                                          <apex:param assignto="{!acnt.BillingStreet}" name="street" 
                                                                                        value=" {!addres.StreetName}"/>
                                         <apex:param assignto="{!acnt.BillingCity }" name="City" 
                                                                                                value=" {!addres.City}"/>                                                            
                                      </apex:actionsupport>
                                </input>
                         </apex:column>
                  </apex:pageblocktable>
             <apex:actionfunction action="{!redirectToAccountpage}" name="derectToAccount"/>                      </apex:pageblock>      
        </apex:form>
     <apex:outputlabel id="ResultPanel"/>   
</html>    
</apex:page>


Apex Controller:-

public with sharing class testAccountController {
    Public list<address__c> brazilAddress{get;set;}
    public testAccountController(ApexPages.StandardController controller) {
        brazilAddress=new list<address__c>();
        acnt=(Account)controller.getrecord();
        acnt=[select id,BillingStreet,BillingCity from account where id=:acnt.id];

   Public PageReference redirectToAccountpage(){
       PageReference  pagRef= new PageReference('/'+acnt.id);
       return pagRef;
   } 

    Public PageReference updateTestaccountAdress(){ 
       update acnt;
       return null;
    }
}

1 comment:

  1. where you are created acnt object,what is these methods,where it is available(derectToAccount();, rendered="{!testAddress.size>0}" value="{!testAddress}")..whare is this id available(rerender="ResultPanel")

    ReplyDelete