+ Start a Discussion
Amita TatarAmita Tatar 

rerender salesforce not working

Hi all,

I have following code: Scenario is that i have two objects Account and Proposal Form with look up relationship..
I have some standard forms already stored in Proposal Form object which has service family and service category drop down.

On Account i want to rerender field from proposal form on matching of certain conditions,but it is not working. can you please help me out here.
Class::

public with sharing class SurveyClass{

Public Account acc{get;set;}
Public Proposal_Form__c pfc {get;set;}
Public ID rid;
private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    acc = (Account)controller.getRecord();
  }

public void Selected(){
//acc = [SELECT Id, Name, Proposal_Form__r.Name, Proposal_Form__r.Fields_Associated__c, Proposal_Form__r.Service_Family__c, Proposal_Form__r.Sub_Service_Category__c FROM Account ];
pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: acc.Proposal_Form__r.Service_Family__c and Sub_Service_Category__c =: acc.Proposal_Form__r.Sub_Service_Category__c];

}
}


VF Page:::


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Client Survey Form"> 
<apex:pageBlockSection title="Service Requirements" >
<apex:inputField value="{!acc.Proposal_Form__r.Service_Family__c}"/>
<apex:inputfield value="{!acc.Proposal_Form__r.Sub_Service_Category__c}"/> 
</apex:pageBlockSection> 

<apex:outputPanel id="form">
<apex:pageblockSection title="Question Set" >
<apex:inputField value="{!acc.Proposal_Form__r.Fields_Associated__c}">
<apex:actionSupport event="onchange" action="{!Selected}" oncomplete="alert('Hello');" rerender="form"  rendered="true"/>
</apex:inputField>
</apex:pageblockSection>
</apex:outputPanel>

</apex:pageBlock>
</apex:form> 
</apex:page>
Please help me out here.

Thanks,
Amita
 
Shivdeep KumarShivdeep Kumar
Hi Amita,

Can you use the selectoption instead of inputfields.
with the help of selectoptions you can capture the selected value and send to controller with the help of action Support.
If you want to rendered the page so create boolean variable in apex and use that on vf page for rendering.

Thanks
Shivdeep
Amita TatarAmita Tatar
Hi Shivdeep,

Can you explain me through code?
 
Shivdeep KumarShivdeep Kumar
Hi Amita,

Please try the below code, it's just a sample so update it with your requirement.
Class::

public with sharing class SurveyClass{

Public Account acc{get;set;}
Public Proposal_Form__c pfc {get;set;}
Public ID rid;
public string SFselectedValue {get;set;}
public string SCselectedValue {get;set;}

private ApexPages.StandardController standardController;
    
public SurveyClass(ApexPages.StandardController controller) {
    this.standardController = standardController;
    acc = (Account)controller.getRecord();
  }

  public List<selectoption> getServiceFamilyValue() {
List< selectOption> SFOptions = new list<selectOption>();
for(Proposal_Form__c p :[select Service_Family__c from Proposal_Form__c]){ // Replace serviceFamily with your field API name
SFOptions.add(new selectOption(p.Service_Family__c,p.Service_Family__c)); // Replace serviceFamily with your field API name
}
return SFOptions;
}
public List<selectoption> getServiceCategoryValue() {
List< selectOption> SCOPtions = new list<selectOption>();
for(Proposal_Form__c p :[select Sub_Service_Category__c from Proposal_Form__c]){ // Replace servicecategory with your field API name
SCOPtions.add(new selectOption(p.Sub_Service_Category__c,p.Sub_Service_Category__c)); // Replace servicecategory with your field API name
}
return SCOPtions;
}
public void Selected(){
//acc = [SELECT Id, Name, Proposal_Form__r.Name, Proposal_Form__r.Fields_Associated__c, Proposal_Form__r.Service_Family__c, Proposal_Form__r.Sub_Service_Category__c FROM Account ];
pfc = [SELECT Fields_Associated__c FROM Proposal_Form__c where Service_Family__c =: SFselectedValue and Sub_Service_Category__c =: SCselectedValue];
System.debug('#####pfc '+pfc);
}
}


VF Page:::


<apex:page standardController="Account" extensions="SurveyClass" sidebar="false" showHeader="false" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Client Survey Form"> 
<apex:pageBlockSection title="Service Requirements" >
<apex:selectList size="1" value="{!SFselectedValue}">
   <apex:selectOptions value="{!ServiceFamilyValue}"/>
   <apex:actionSupport event="onchange" reRender="SCat"/>
  </apex:selectList>
  </apex:pageBlockSection> 
  <apex:pageBlockSection title="Service Category" id="SCat">
  <apex:selectList size="1" value="{!SCselectedValue}">
   <apex:selectOptions value="{!ServiceCategoryValue}"/>
   <apex:actionSupport event="onchange" reRender="Ques" action="{!Selected}"/>
  </apex:selectList>
</apex:pageBlockSection> 


</apex:pageBlock>
</apex:form> 
</apex:page>

Thanks
Shivdeep