0

I cannot pass apex:param to controller

public class TestClass {
    public String paramFrom { get { return 'Hello param!'; } }
    public String paramTo { 
        get; 
        set {
            paramTo = value;
            System.debug('VALUE >>> ' + value);
        } 
    }

    public PageReference click() {
            System.debug('VALUE IN CLICK >>> ' + paramTo);
        return null;
    }
}

VF page:

<apex:page controller="TestClass">
    <apex:pageblock title="Parameters">
        <apex:pageblocksection columns="1" showheader="false">
            <apex:form >
                <apex:commandButton action="{!click}" value="Click">
                    <apex:param name="param1" value="{!paramFrom}" assignTo="{!paramTo}"/>
                </apex:commandButton>
            </apex:form>
            <apex:outputText value="{!paramTo}" />
        </apex:pageblocksection>
    </apex:pageblock>
</apex:page>

Output text is empty after click and

13:43:37:033 USER_DEBUG [13]|DEBUG|VALUE IN CLICK >>> null
1
  • 1
    rerendering the pageblock should solve your issue and you wont be reloading the entire page also. As mentioned in below post, use rerender attribute, <apex:commandButton action="{!click}" value="Click" rerender="Parameters"> Feb 3, 2016 at 12:46

2 Answers 2

2

Use rerender in the button. Rerender is the key here.

<apex:commandButton action="{!click}" value="Click" rerender="none">
       <apex:param name="param1" value="{!paramFrom}" assignTo="{!paramTo}"/>
</apex:commandButton>
2
  • Great, thanks. But is it possible to implement it with reloading? In original application I need to pass parameter to controller and reload data in page Feb 3, 2016 at 11:51
  • there is may workaround. Like oncomplete call another actionfunction and don't use rerender on it. or use inputhidden and set the value using Javascript in VF page and then use it in Controller. Feb 3, 2016 at 11:56
0

changing apex:commandButton to apex:commandLink solves this issue and it works without specifying rerender attribute

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .