You need to sign in to do that
Don't have an account?

Passing Parameters to Controller Method
Hi,
I was wondering if it is possible to pass parameters to our controller method while in a VF page.
For example, normally, say we have a controller called "MyController" and inside it we have a method call "Method" which take a string parameter.
Is it possible to call this method and pass a value to it from our VF page? If so how?
Would this work?
<apex:commandButton action="{!Method('stringvalue'}"/>
Thanks in advance.
You can pass parameters to a controller though the page's parameter list, but not directly to the function. Here's a standard method for passing a parameter:
<!-- page --> <apex:commandButton action="{!myMethod}" value="Click Me"> <apex:param name="myParam" value="my Value"/> </apex:commandButton> // Controller method public void myMethod() { string myParam = apexpages.currentpage().getparameters().get('myParam'); // Do something with myParam here }
All Answers
You can pass parameters to a controller though the page's parameter list, but not directly to the function. Here's a standard method for passing a parameter:
<!-- page --> <apex:commandButton action="{!myMethod}" value="Click Me"> <apex:param name="myParam" value="my Value"/> </apex:commandButton> // Controller method public void myMethod() { string myParam = apexpages.currentpage().getparameters().get('myParam'); // Do something with myParam here }
Thanks man!
Much appreciated!
Thanks, a lot...:smileyhappy:
Hi all,
i am a begineer to the salesforce so i am still in the phase of learning..
i have displayed a list of all the accounts in the app using list controllers and a VF page...
now if i click on the members of the list i want its details to be displayed below the list.. for this im using "param" but i am not able to fetch the data...
so please help....
Hey Nik,
This is one that got me, but apparently its a very persistant and common bug. You need to specify a rerender attribute in the commandButton.
This is your visualforce page
This will be the controller