function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karimulla salesforcekarimulla salesforce 

Apex include page with multiple controllers in salesforce development

Using the Includetab with multiple controllers, if yes, iam getting the values in the system.debug(); , but unable to display the values in the visualforce page..!
 
<!--Using the Includetab with multiple controllers-->

<apex:page controller="actionfunctiontest1" >
   
   <apex:form >
        <ul>
          <li onclick="passValueToController('Testing'); return false;" style="cursor:pointer;">Click Me</li>
        </ul> 
     
    <apex:actionFunction name="passValueToController" action="{!testing}" reRender="frm" >
        <apex:param name="selectedval" value="selectedval" assignTo="{!selectedval}"></apex:param>
     </apex:actionFunction>
   </apex:form>
       
    <apex:outputPanel id="frm">
           <apex:include pageName="actionfunctiontest2"/>
     </apex:outputPanel>
      
  </apex:page>

<!--apexclass-->
Apex Controller:

public class actionfunctiontest1 {
 public String selectedval{get;set;}
  // public actionfunctiontest2 t1{get;set;}
  public void testing(){
  system.debug('form the selectedval controller1'+selectedval);
  
      actionfunctiontest2  t1= new actionfunctiontest2();
   } 
}
Included page is:
<apex:page controller="actionfunctiontest2">
  <apex:form >
 The value passed is:<apex:inputtext value="{!name}"/>
  </apex:form>
</apex:page>


Apex Controller:-

public class actionfunctiontest2 {
   public string name{get;set;}
   public actionfunctiontest2(){
        name =Apexpages.currentPage().getParameters().get('selectedval');
        system.debug('This is the controller2 form 1 im getting the values here');
        system.debug(' sucess:'+ name);
      }
      
}

//iam gettig the value is the system.debug, but unable to dispaly it in the visualforce page..
//can multiple controllers can be used for the Include tag in salesforce

Thank you
vijay kumar kvijay kumar k
Hi Karimulla

Instead of calling apex call you can call visualforce page then name can display is Vf Page.

I'm changing testing method
 
public pageReference testing(){ 
system.debug('form the selectedval controller1'+selectedval); 
PageReference includePage = new pageReference('/{IncludePage}?selectedval='+selectedval); includePage.setRedirect(true); return includePage; 
}

Try this code.
Note: Replace {Includepage} with your vf page API Name

Regards
Vijay

 
uspayroll cmiuspayroll cmi
Hi all,
i am also searching for similar scinarion of the karimulla, By using the Vijay Kumar answer page is redirecting to the 2nd page, i dont want to redirect to the page,
am displaying 2VFpage is inside of the first VFpage , when i click on the Click Me then that time 2VFpage controller will be called and getting value in debug statement not displaying it in the first vfpage, how to display that value ???
karimulla salesforcekarimulla salesforce
Hi Vijay, thank you for your reply , actually the solution you had suggested was good,but the thing is, it is getting redirected to the Other page by using of pageReference... but for me it should display or render in the same page,with out redirecting to the other page...! so please suggest a solution to display in the same page..

Thanks and regards,
Karimulla...!
vijay kumar kvijay kumar k
Hi karimulla

Whenever concept coming two different pages we should redirect to one page to another there is no other solution. So usually we are using visulaforce components. Using visualforce components no need to redirect to another page.

How to use visulaforce componets in visulaforce page below link will help you:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_component.htm

If are confusing how to use vf components ask me I'll help you.