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
DeepikareddyDeepikareddy 

How to pass the values form Visualforce page To controller

Hi.. here iam using the apex:include page functionaliy, one page is included in the another page with common controller..

Vfpage1:
<apex:page controller="testingcontroller">
  <apex:form >
  Entername<apex:inputText value="{!testwrap.name}"/>
  </apex:form>
</apex:page>
Vfpage2: Vfpage1 included in the Vfpage2.
<apex:page controller="testingcontroller" id="pg">
  <apex:include pageName="Vfpage1" id="pge"/>
    <apex:form >
    <apex:commandButton value="test" action="{!test}" reRender="t" />
    <apex:outputLabel id="t">{!message}</apex:outputLabel>
    </apex:form>
</apex:page>

Commoncontroller:
 
public class testingcontroller {

 public string message{get;set;}
 public testwrapper testwrap{get;set;}
 public  testingcontroller(){
 testwrap = new testwrapper();
 }
   public void test(){
    message ='Hi hello'+testwrap.name;
   system.debug('testwrap.name=======>'+testwrap.name);
   }
   
    public class testwrapper{
    
      public string name{get;set;}
      public testwrapper(){
        this.name ='';
        }
    }
}

On clicking on the button the data should have to pass to the Common controller. any solution how it can be achived.. thanks in advance..!

 
Foram Rana RForam Rana R
Hi Deepikareddy,

I hope you are doing well .....!!
Please use the below code:

First Visualforce page Name: V1.vfp
<apex:page controller="testingcontroller">
    
    <apex:form id="PrefForm">
        <apex:actionFunction name="cllactionfun" action="{!test}">
            <apex:param name="name" value="name"/>
        </apex:actionFunction>
        Entername<apex:inputText id="myInput" value="{!testwrap.name}" onchange="testjs();"/>
    </apex:form>
    <script>
    function testjs() {
        //var inputVal = document.getElementById("myInput").value; 
        var inputVal = document.getElementById('{!$Component.PrefForm.myInput}').value;
        alert('@@ inputVal'+inputVal);    
        cllactionfun();
    }
    </script>
</apex:page>

Second Visualforce Page Name: V2.vfp 
<apex:page controller="testingcontroller" id="pg">
  <apex:include pageName="V1" id="pge"/>
    <apex:form >
    <apex:commandButton value="test" action="{!test}" reRender="t" />
    <apex:outputLabel id="t"> {!message}</apex:outputLabel>
    </apex:form>
</apex:page>

Controller  Name :testingcontroller 
public class testingcontroller {
    
    public string message{get;set;}
    public string name{get;set;}
    public testwrapper testwrap{get;set;}
    
    public  testingcontroller(){
        name =  '';
        testwrap = new testwrapper();
    }
    public void test(){
        message ='Hi hello'+testwrap.name;
        system.debug('testwrap.name=======>'+testwrap.name);
    }
    
    public class testwrapper{
        
        public string name{get;set;}
        public testwrapper(){
            this.name ='';
        }
    }
}



Hope this helps you.
​​​​​​​Let me know your review.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana
DeepikareddyDeepikareddy
Hi.. Foram Rana.. i had modified the code , its working good ,but if i click directly on the Commandbutton  after updating, the values are not passing to the Controller, 
i think need to write some onclick functinality suchthat it can take the updated inputvalues from vusualforce page..., please provide your thoughts to achive it.. 

page1:
<apex:page controller="comoncontrl">
 
 <apex:form > 
  <apex:actionFunction name="passvalues" action="{!test}" reRender="t,t2">
   </apex:actionFunction>
  Entername<apex:inputText value="{!std.name}" onblur="testjs();" id="t" /> 
  
  <br/><br/>
  Branch <apex:inputText value="{!std.branch}" onblur="testjs();" id="t2" />
</apex:form>
 <script>
  function testjs(){
  //alert('hello'); 
   passvalues();
  }
  </script>
</apex:page>

page:2
 
<apex:page controller="comoncontrl" id="pg">
 <apex:include pageName="page1" id="pge"/>
 <apex:form >
  <apex:commandButton value="test" action="{!save}"/>
 </apex:form>

</apex:page>

Controller:
 
public class comoncontrl {
public  student std{get;set;}

public  comoncontrl(){
 
 std = new student();
}
 
 public void test(){
}
  
  public void save(){
  
  system.debug('the save request is::'+std.name);
  system.debug('the save request is::'+std.branch);
  }
 
 
 //Wrapperclass
 public class student{
 public string name{get;set;}
 public string branch{get;set;}
 
 public  student(){
 
 this.name ='Deepika';
 
 this.branch='Engineering';
 
 }
 }
 
 
}

 
Foram Rana RForam Rana R
Hi Deepika,

I have checked my above code and I get updated value in System.debug().
Can you please try it again and let me know your review.

Thanks,
Foram Rana
DeepikareddyDeepikareddy
Hi Rana, thanks for your quick response ..!  iam also getting the updated values. 
1) but onchange you had called a actionfunction, so every time when it was updating, the page is getting refresh all the time so i used reRender in it.. 
 
<apex:actionFunction name="cllactionfun" action="{!test}"  reRender="myInput">
            <apex:param name="name" value="name"/>
        </apex:actionFunction>
        Entername<apex:inputText id="myInput" value="{!testwrap.name}" onchange="testjs();" />
2)but if iam using the reRender.. After Edition if i click immediately on the button , the values is not passing..
note: after updating , directly moving the cursr to the command button and on clicking the values are not geting updated in system.debug.. 
 is it correct to use the Rerender in the Action function 
Thanks 
Deepika.