1

In my code the parameter in an apex:param does not get passed on to the controller. Here is the code for Visualforce:

<apex:Outputpanel>
<apex:variable value="{!1}" var="row"/>
    <apex:repeat value="{!list}" var="item">
        <apex:commandLink value="Action" action="{!performAction}">
             <apex:param value="{!row-1}" assignTo="{!pos}"/>
        </apex:commandLink>
        <apex:variable value="{!row+1}" var="row"/>
    </apex:repeat>
</apex:Outputpanel>

Controller:

public Integer pos {get; set;}


public PageReference performAction() {

    if (list[pos] != null){
        delete list[pos];   
    }
    list.remove(pos);

    return null;
}

So what is wrong here?

  • It looks like you may be attempting to modify the displayed contents, of some collection, on your visualforce page. Am I right? If so, I can expand on this comment in an answer. Also, if I'm right, this is an example of an X-Y problem (where you ask about how to fix your chosen solution instead of asking for help in achieving your overall goal), and I'd suggest using an <apex:actionSupport> along with rerender to accomplish a partial page refresh instead of specifying the action attribute in your <apex:commandLink>. – Derek F May 2 '17 at 20:36
2

Though optional you have to put in a name attribute for the apex:param.

Update:

A similar question was answered on why param needs a name attribute. Param gets passed as a key value pair to the controller, you have to specify name for the key value pair to be generated.

<apex:param> assignTo attribute not setting value to contoller variable

         <apex:param value="{!row-1}" assignTo="{!pos}" name="pos"/>
| improve this answer | |
  • @DanielBallinger the op is using commandlink which as per the idea should work without re-render attribute? I put in a name attribute and tested, the value gets passed to teh controller – Rao May 2 '17 at 20:43
  • Ah right. Missed that bit. – Daniel Ballinger May 2 '17 at 20:45

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.