You need to sign in to do that
Don't have an account?
adampro
Parameter won't pass to Controller Class
Hi-
I created two pages that use the same controller, and I want each to pass a parameter to the controller so I can handle each page accordingly. However, I can't seem to figure out how to pass the paramter to the controller.
I have the page set up like so:
<apex:page standardController="Contact" extensions="SharedController" showHeader="false" action="{!Redirect}"> <apex:param name="childToClone" value="1" assignTo="{!childToClone}"/> </apex:page>
And I set the controller up like so:
public with sharing class SharedController { public PageReference Redirect() { string childToClone = ApexPages.currentPage().getparameters().get('childToClone'); // MORE CODE HERE } }
I tried printing the keys in the parameters map and it returned <id, scontrolcaching>. Any ideas?
Hi adampro,
Try the following example. This will give you an idea of passing paramemter using single controller
PassParamPage1:
<apex:page controller="onevf" showheader="false">
<!-- form to include book and price details -->
<h1>Book Name</h1>
<apex:Pageblock >
<apex:form >
Book Name : <apex:inputText value="{!bname}" />
Price : <apex:inputText value="{!price}"/>
<apex:commandButton value="Go to output page" action="{!save}"/>
</apex:form>
</apex:Pageblock>
<!-- End of form -->
</apex:page>
PassParamPage2:
<apex:page controller="oneVF" showheader="false">
<br/><br/>
<h1>Welcome to My Library</h1> <br/><br/>
You going to take the book : <apex:outputText value="{!bname2}"/>
<br/><br/>
The book price is : <apex:outputText value="{!price2}"/>
</apex:page>
Controller:
public class onevf{
Set<ID> setId = new Set<ID>();
public string bname{get;set;}
public string price{get;set;}
public string bname2{get;set;}
public string price2{get;set;}
public onevf(){
bname2 = ApexPages.currentPage().getParameters().get('Book Name');
price2 = ApexPages.currentPage().getParameters().get('Price');
}
public Pagereference save(){
PageReference pr = new PageReference ('/apex/PassParamPage2');
pr = Page.PassParamPage2; // use the name of the second VF page
pr.setRedirect(true);
pr.getParameters().put('Book Name',string.valueof(bname));
pr.getParameters().put('Price', string.valueof(price));
return pr;
}
}
Here, Im using two pages. PassParamPage1 is to get the input values for book details and PassParamPage2 page is used to diaplay the output by getting the values through parameter.
Hope this helps you...!
Please don't forget to give kudos and mark this as a solution, if this works out.