You need to sign in to do that
Don't have an account?
Semira@gmail.com
Passing a value to a variable from visualforce page to controller
Hi,
I have a String variable in my controller call ChildQuery. I want to pass a value to the string variable from Visualforce page without any javascript or button. How can that be possible? This value needs to be hidden and auto assign as soon as the visualforce page is opened.
//set the value of Childquery to "write some string value here like ABCD" without calling <script></script>
// maybe using these tags below?
<!-- apex:inputHidden / -->
<!-- apex:param / -->
<!-- apex:variable / -->
This is what my class would look like. I'm writing a generic class which would be used by many many different visualforce page. So cannot set the value of the variavle in the controller. It has to pass through the visualforce page so I can throw any page and just call this controller class.
I have a String variable in my controller call ChildQuery. I want to pass a value to the string variable from Visualforce page without any javascript or button. How can that be possible? This value needs to be hidden and auto assign as soon as the visualforce page is opened.
//set the value of Childquery to "write some string value here like ABCD" without calling <script></script>
// maybe using these tags below?
<!-- apex:inputHidden / -->
<!-- apex:param / -->
<!-- apex:variable / -->
This is what my class would look like. I'm writing a generic class which would be used by many many different visualforce page. So cannot set the value of the variavle in the controller. It has to pass through the visualforce page so I can throw any page and just call this controller class.
Class sObject { public string ChildQuery {get; set;} public sObjectController(ApexPages.StandardController controller){ system.debug('THIS IS THE VALUE I'M GETTING:' + ChildQuery); } }
I have tried that. It is returning Null Value. Does Param has be invoked by something?
Class sObject
{
public string ChildQuery {get; set;}
public sObjectController(ApexPages.StandardController controller)
{ system.debug('THIS IS THE VALUE I'M GETTING:' + ChildQuery);
} }
<apex:inputText value="{!ChildQuery}" label="Input"/>
or
<apex:inputHidden value="{!ChildQuery}" id="theHiddenInput"/>
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
See example
https://salesforce.stackexchange.com/questions/36580/passing-a-value-from-visualforce-page-to-controller
If I have to use apex:actionfunction, I have to write <script></script> which I was trying to avoid. Is there really no other way? I was trying to pass a string of query like "select id from [specific object] where [specific field] =: RecordID"
I'm trying to use this string in my controller where I can say
String childQuery = //get the string value from VS page.
database.query(childQuery);
And controller like this:
That defeats the purpose of my controller. As I have mentioned before, I wrote a generic Controller Sobject which does not have any specific object or fields defined in it. Because I want to use any visualforce page from any object and be able to call the controller without touching the controller class ever becuase it will read everything from the visualforce page.
This is why I need to pass the query string from the visualforce page. Then in my controller, it will read as string and call Databate.query(query)
My controller:
I'm not familiar with actionfunction with javascript. Is this right? It's still not returning anything.
VF page
With the code I provided, you would declare the Object name and Field name as string variables inside the visualforce page. This makes the controller dynamic for different visualforce pages, as long as you are passing difference object and field name strings in.
I used a Visualforce component in between to pass the variable from a Visualforce Page to the Apex Controller. The Controller remains the same in this case and can be used for other Visualforce Pages as well. (Just call the Visualforce Component from the page passing different values to the attribute.)
Whatever value is passed from the Visualforce page in the Visualforce Component CustomLinksComponent, it gets assigned to the variable linkTypeVar.
This value can be used in the variable's setter method of the controller. Additionally, this value can be used to make further SOQL queries.