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

passing parameter from vf to controller

i have to pass parametet with commandbutton which is outside of table.
this is my vf: 
<apex:form styleClass="myFormStyle " >
  <apex:pageBlock title="My Bucket"  >
  <apex:pageMessages id="msg"> </apex:pageMessages>
  <!-------------first section-display table and take quantity from user----------------->
  <apex:pageblockSection >
  <apex:pageBlockTable value="{!itemInBucket}" var="i">
   <apex:column value="{!i.Product_Name__c}" />
    <apex:column value="{!i.price__c}"  />
    <apex:column value="{!i.Quantity__c}" headerValue="Available Quantity"/ >
    <apex:column headerValue="Required Quantity" >
    <apex:commandButton value="+" action="{!incrementCounter}" reRender="bucket"/>
    <apex:inputText value="{!count}" style="width: 25px !important;" styleClass="qty " id="bucket"/>
    <apex:commandButton value="-" action="{!decrementCounter}" reRender="bucket"/>
    <apex:Column >
    <apex:commandLink value="Place Order" action="{!placeOrderForSinglePro}" >
    <apex:param name="Pname" value="{!i.Product_Name__c}"/>
    <apex:param name="price" value="{!i.price__c}" />
     <apex:param name="quantity" value="{!i.Quantity__c}" />
    <apex:Column >
    <apex:commandLink value="cancel" action="{!cancelOrder}" rendered="true" >
    <!---------------------second section- take address and name from user--------------->
    <apex:pageBlockSection >
    <apex:inputText value="{!n}" label="Name" />
    <apex:inputTextarea title="Address" value="{!a}" label="Address"/>
   <!---------------commandButton is in pageBlock------------------------------->
   <apex:commandButton value="Place Order for All Products" action="{!placeOrderForAllPro}"/>
  <apex:commandLink value="View Order" action="{!openOrderPage}"/>
  <apex:commandLink value="Previous Page" style="float:right;" action="{!redirect}"/>

here i am taking quantity name and address from user and storing all that into Order__C object. now my inputFileds are in diffrent pageBlockSection and my command button is in pageBlock. so how can i insert  that  to Order__c when i click on commandButton.

Give it a try with <apex:param> to send value to controller from VF page with the help of command link 
Suraj TripathiSuraj Tripathi
Hi SFDC Sagarika,

You can use apex:actionFunction to pass the variable and call the function that is written in a controller.

<apex:commandButton value="Place Order for All Products" action="{!placeOrderForAllPro}"/>

In above you can call the apex:actionFunction using onClick on the CommandButton.

Go through the below link to know more.


Hi Suraj,

i went through above link. but i have to pass parameter with apex:actionFunction. 
Suraj TripathiSuraj Tripathi
Hi Force.platform,

Use <apex:param> to pass value using <apex:actionFunction>.

Example - 

Visualforce Page-

<apex:page controller="passparam">
  <apex:pageblock id="pgblck">
   First name : <apex:inputtext id="fn" value="{!firstname}">
   Last Name :<apex:inputtext id="ln" value="{!lastname}">
 Click this to See full name :  <apex:inputcheckbox onclick="calculate('{!$Component.fn}','{!$Component.ln}')">
Full Name:    <apex:outputtext value="{!fullname}"></apex:outputtext>

<apex:actionfunction action="{!calpercentage}" name="calAF" rerender="pgblck">
<apex:param assignto="{!firstname}" name="param1" value="" />
<apex:param assignto="{!lastname}" name="param" value="" />
  function calculate(frst,lst){
  var Fname = document.getElementById(frst).value;
 var Lname = document.getElementById(lst).value;
   var res = confirm('Do you want to calculate?');
   if(res == true)
      calAF(Fname,Lname );

Controller - 
Public class passparam{
Public string firstname{get;set;}
Public string lastname{get;set;}
Public string fullname{get;set;}
 Public void calpercentage(){
  fullname = firstname +' '+lastname;

In the Above example, I am using <apex:param> to send the value to the controller.

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.