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

Passing value from VF page to controller
HI all,
I have created a VF page which is having account standard controller and an extension, please find the below code
<apex:page standardController="Account" sidebar="false" showHeader="false" extensions="Report">
<apex:form id="thisForm" >
<apex:inputField value="{!account.CustomerPriority__c}" /><br/><br/>
<apex:inputField value="{!account.SLASerialNumber__c}"/><br/><br/>
<apex:commandButton value="Search" action="https://ap1.salesforce.com/00O90000002Gcja?getSearch()"/>
</apex:form>
</apex:page>
Here is the extension class,
public class Report {
public Report(ApexPages.StandardController controller) {
}
Public String getSearch()
{
// Here i want to return a string which will be address but that address should contain
the values passed from the page
I tried to access using this {!account.CustomerPriority__c}, but its not working
}
}
Please help me out ASAP
Thanks & Regards,
You won't be able to have a getter that reacts to the input fields in that way, as getters are called when the page is first rendered.
It looks to me like you should be invoking an actionfunction in the controller that builds the URL and returns it. Something like
Page:
controller:
HI BOB,
Thanks for replying, could you please help me out with this thing
The exact thing i want is to pass these two parameters in the form to controller and build a URL based on these two parameters. Could you Pls explain me how to retrieve these two parameter values and how to build URL and pass as a String or Page Reference
The code I've posted above should do this.
The "parameters" you are referring to are actually input fields on the form, thus you have to submit the form to the controller in order to be able to access them. Once your action method is invoked, those fields will be populated in the record the controller is managing.
You can then build the URL as a page reference and return that to the browser.
HI Bob,
I tried using your code its not working, its throwing error like getParameter function will return Map<String,String>
The functionality i need to do it in controller is something like this
public class Report {
Public String getSearch()
{
return '/{!account.CustomerPriority__c}&{!account.SLASerialNumber__c}';
}
}
I need to build URL by passing those two values and return to the VF page
Thanks in advance,
Hi ,
You can get the parameters by this way :-
Please verify the exact id of these parameters from the actual vf page by inspecting the generated html of vf page.
You can't get the parameters this way, as the getter will run as part of the page being rendered. If you want to capture what the user has entered server side, you must submit the page back to the controller.
The other way would be to use javascript to pull the contents of the input fields from the page and build the URL, and fire all that off via an onclick handler.
Hi bob_buzzard,
It works , I have tested following code on my dev org :-
Please try it ..
This isn't the code that you posted above though. As I have said a number of times, you have to submit the form. In your latest code you are submitting the code via an actionfunction.
As you are doing that, why would you pull the parameters from the URL rather than using the fields from the sobject that are bound to the apex:inputfield components? Not only is it fragile, in that the ids will change if the structure of the page changes, but this is also bad practice from a security point of view, as they leave your code open to Cross Site Request Forgery, as documented in the Visualforce Developer's Guide.
Its much better to let Visualforce work as intended - capture the information into the sobject exposed as a controller property, then provide an action method that produces a page reference based on that input.
Thanks for sharing the information bob_buzzard , I know the code I posted above is not the real , t I just wrote that on notepad to give an example. Also I agree that it is not the good practice.
But I have a doubt that action function does submit the form or not, I think Action function does not submit the whole form, while command button does. and that is the difference between an action fucntion and command button action. If the form is submitted means your setter functions for the inputs written in between form tags will get called and you can get them by their respective property name(like acc.name or so..) in the controller. And before form submission you can get their values by there element ids. Please correct me if I am wrong.
Actionfunction submits the whole form in the same way that a command button does - the postback still occurs in the same way. You should only need to access values by id in javascript on the page, not server side.
If you only wanted to submit part of a form, you would use an actionregion, which only submits the particular input fields inside the actionregion tags.