I am trying to pass a value from visualforce page to apex controller using apex:param inside the apex:repeat but it gives me a null value. How to make my code work? am i missing something ? Please help me.


Visualforce Page

<apex:repeat value="{!ButtonsControl}" var="btnlist" id="btnsid" >

  <apex:outputText value="{!btnlist.Option_Name__c}">
        <apex:param name="LikedUserName" value="{!btnlist.Option_Name__c}" assignTo="{!actionBTN}" />



global with sharing class Contact_Handler_Controller {

public String actionBTN{get;set;}

public static List<Control_Option__c> getButtonsControl(){
   return [SELECT Id,Object__c,Option_Name__c FROM Control_Option__c WHERE Object__c='Contact'];
public Contact_Handler_Controller()

The constructor is called before your getButtonsControl, and so it will indeed be null. In fact, that code, by itself, doesn't have any particular purpose, because you're not using the parameter with a function call of some sort. Here'd be a typical usage:

<apex:repeat value="{!ButtonsControl}" var="btnlist" id="btnsid" >
  <apex:commandButton action="{!doSomething}" value="Do Something" reRender="form">
    <apex:param name="LikedUserName" value="{!btnlist.Option_Name__c}" assignTo="{!actionBTN}" />

This will call the function doSomething (not currently defined in your controller), and actionBTN will contain the appropriate value for that instance of the button within your action function.

  • but what i want is when the apex repeat is executed , the data will automatically pass to the apex controller without any action by the user. – Danryl Tigol Carpio Oct 27 '15 at 2:26
  • how can i do that ? – Danryl Tigol Carpio Oct 27 '15 at 2:27
  • @DanrylTigolCarpio You'd just assign a value directly to a variable. apex:param is used for passing values between Visualforce components and Apex Code. In fact, I'm not really sure what problem it is you're trying to solve; I'd suggest opening a new question to address the problem you're having (what you've attempted/what you're trying to do), rather than ask specific questions about why a particular syntax is correct or not. – sfdcfox Oct 27 '15 at 2:32
  • You have a big point fox. Here is the scenario, I want to write a program that will display a dynamic button , that button has the status of (ON/OFF) so if button is off button style will inactive and if its on, style will be active. So to do that I have two Object First Object(Buttons__c...Custom field(Button_name__c)), is where i will add manually a dynamic button i want to display in the page. Second Object(Button_Status__c...Field(Button_Name__c,Status__c))is where the status(ON/OFF) based. – Danryl Tigol Carpio Oct 27 '15 at 3:07

just remove the line of code

<apex:param name="LikedUserName" value="{!btnlist.Option_Name__c}" assignTo="{!actionBTN}" />

This should solve the problem, i believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.