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
Marc C.Marc C. 

Calling Actions with Parameters from a pageBlockTable

I've just read about a dozen posts on this issue but none of the solutions work for me. Parameters simply are not passed when the commandButton or commandLink is inside a pageBlockTable. The exact same commandLink code works outside the table (see below).

 

  <apex:form >
<apex:pageBlock >
<apex:commandlink value="Connect(123)" action="{!selected}"> <apex:param name="customer" value="123"/> </apex:commandlink>  
<apex:pageBlockTable value="{!matches}" var="i" id="theTable" styleClass="tableClass">
<apex:column >
<apex:commandlink value="Connect(333)" action="{!selected}">
<apex:param name="customer" value="333"/>
</apex:commandlink>
... 

If you click the top link, the selected action is fired with the customer parameter set to 123.

 

If you click the link inside the column of the pageBlockTable no action is fired.

Marc C.Marc C.

Here the relevant controller action snippet:

    public PageReference selected() {
        system.debug('selected()');
        string customer = ApexPages.currentPage().getParameters().get('customer');
        system.debug(customer);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'You selected ' + customer));
        return null;
}

 This action is not getting fired.

Marc C.Marc C.

Don't know if this is relevant but my page has an auto action:

<apex:page controller="FooBar" tabStyle="Account" action="{!loader}">

 

jwetzlerjwetzler

Use the assignTo parameter on the apex:param component to pass the value back into your controller so you can refer to it. The check you're doing on currentPage() just gives you the query parameters of the current page you're looking at.

Marc C.Marc C.

"assignTo" and "string customer = ApexPages.currentPage().getParameters().get('customer');" are equivalent in that the value is passed from the page to the controller. Neither works because the real problem is the action not being called.

 

As I mentioned, the commandLink works outside of the pageBlockTable and I get the parameter with getParameters. The issue is not so much the parameter but the entire action "selected" is not invoked. Indeed, the debug console reveals that none of my actions are invoked when command link is clicked. When I log in as a normal user (I'm admin) the action would fire however (mostly). It feels like a bug in the framework...

jwetzlerjwetzler

Oh, sorry I misunderstood the issue. I tried your example and it did work as you expected it to.

 

public class pbtCon {

    public String[] matches { get; set; }

    public pbtCon() {
        matches = new List<String>();
        matches.add('one');
        matches.add('two');
    }

    public PageReference selected() {
        system.debug('selected()');
        string customer = ApexPages.currentPage().getParameters().get('customer');
        system.debug(customer);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'You selected ' + customer));
        return null;
    }    

}

<apex:page controller="pbtCon">
  <apex:form >

  <apex:pageBlock >

    <apex:commandlink value="Connect(123)" action="{!selected}">
      <apex:param name="customer" value="123"/>
    </apex:commandlink>
    
    <apex:pageBlockTable value="{!matches}" var="i" id="theTable" styleClass="tableClass">         
      <apex:column >  
        <apex:commandlink value="Connect(333)" action="{!selected}">
          <apex:param name="customer" value="333"/>
        </apex:commandlink>
      </apex:column>
    </apex:pageBlockTable>
    
  </apex:pageBlock>
</apex:form>
</apex:page>

 

The debug log printed out selected() and then 333 for me.

 

Maybe you have some validation failures on your page that are preventing your action from firing? Do you have any inputs in your table (perhaps required inputs) that could be invalid? Do you have a pageMessages component somewhere on your page?