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
VijoshVijosh 

Passing value from a visualforce page to a controller string variable.

Hi all,

I have created a visualforce  page and wanted to pass current values from feilds of this page to the controller.
The scenario is like, on the screen we have three fields and the user puts in some value to those fields. Now this values entered in the fields should be passed to the variable in the controller. These fields are not binded to any object. 
Now I able to pass the Static value to the controller for eg. <apex:param name="two" value="Vijosh" />. But how to pass Dynamic values from  to the controller.


<apex:page controller="TestFieldPopulationController" id="pg">
    <script type="text/javascript">
        function userInput(){
            var UInput=document.getElementById("{!$Component.pg.frm.in}").value;
            return UInput;
        }
       
    </script>
   
    <apex:form id="frm">
        <apex:actionFunction name="hitMe" action="{!iWantMyJSValues}" rerender="jsvalues">
            <apex:param name="one" value="" />
            <apex:param name="two" value="Vijosh" />
            <apex:param name="three" value="Keyboard" />
           
        </apex:actionFunction>
       
        <apex:outputPanel id="jsvalues">
            <apex:panelGrid columns="2">
                Value One:<apex:inputText id="in" value="{!valueOne}"/>
                Value Two:<apex:inputText value="{!valueTwo}" />  
                Value Three:<apex:inputText value="{!valueThree}" />
               
<apex:commandButton value="Submit" onclick="hitMe(userInput())"/>
         </apex:panelGrid>       
        </apex:outputPanel>
   </apex:form>
</apex:page>

Regards,
Vijosh
Best Answer chosen by Vijosh
Sonam_SFDCSonam_SFDC
You just need to create the same variables in the controller class as shown in the sample code on the link below:
http://salesforce.stackexchange.com/questions/14675/how-to-get-the-text-fields-values-in-the-controller-class-without-using-any-scri

So for your code:
class TestFieldPopulationController{
public String valueOne{get;set;}
public String valueTwo{get;set;}
public String valueThree{get;set;}

<and now use these values being passed in the controller>
.
.
}

All Answers

Sonam_SFDCSonam_SFDC
You just need to create the same variables in the controller class as shown in the sample code on the link below:
http://salesforce.stackexchange.com/questions/14675/how-to-get-the-text-fields-values-in-the-controller-class-without-using-any-scri

So for your code:
class TestFieldPopulationController{
public String valueOne{get;set;}
public String valueTwo{get;set;}
public String valueThree{get;set;}

<and now use these values being passed in the controller>
.
.
}
This was selected as the best answer
VijoshVijosh
Thanks Sonam,

Appreciate your quick response.

Vijosh
Naresh Kumar 7Naresh Kumar 7
@Sonam_SFDC,

Can you plz tell me

how we can compare input field value with String on VF page.
SonamSonam (Salesforce Developers) 
@Naresh, would help if would create a new thread in case the question you have isn't the same as the one asked in the existing thread.

To answer your questions here:you can do try the following:

//get user to input the field on the VF page using this inputtext field
<apex:inputText value="{!inputValue}" id="theTextInput"/>

//Take this value to the controller through the following:
public String inputValue{get;set;}

//Compare it with the string in the controller using String method:

String myString = 'abcd'; //string to compare with
Integer result = inputValue.compareTo(myString); System.assertEquals(result, 1); 

reference:http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_string.htm

 
Naresh Kumar 7Naresh Kumar 7
Y d way Thanks @Sonam