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
OldDeadBugOldDeadBug 

Incorrect use of apex:param tag??

I have a method in my controller that is not being sween by the page, even though the names are identical

 

I am using a commandLink in a pageblocktable for each line. the action for the link goes to a method that requries a class object for its argument. Whereas each of the lines on the page are made up of these class objects, I apparently have to associate the line object with a property in the controller. So, the line object code is:

 

 

public LineQuote generateLQ;
    
    public LineQuote getGenerateLQ()
    {
        return generateLQ;
    }
    
    public void setGenerateLQ(id lqID)
    {
        system.debug('Set LQ LineQuote from apex:param');
        generateLQ = null;
        for (LineQuote GL :Ws_QOALQs)
        {
            if (lqID == GL.OppItem.ID)
            {
                generateLQ = GL;
                system.debug('Found CreateLineItem assigned to LQ');
            }
        }
    }

 

 

So the page code for the link in the line is:

 

 

<apex:pageBlockTable id="ProductsTable" style="text-align: center" value="{!Ws_QOALQs}"  var="LQ" columns="10" align="center" >
    <apex:column headerValue="Click to Generate RequestID" width="10%">
         <apex:CommandLink value="Generate RequestID" action="{!GenerateRequestID}" reRender="theMessages">
              <apex:param name="LQ" value="{!LQ.OppItem.ID}" assignTo="{!generateLQ}" />
         </apex:CommandLink>
    </apex:column>
</apex:pageBlockTable>

 

 

So, the CommandLink calls the GenerateRequestID method in the controller (shown below), and uses the parameter tag to assign the line's Id to the setGenerateLQ method where it is used by the controller in this method:

 

 

 public PageReference GenerateRequestId(LineQuote LQ)
    {
        PageReference returnPage;
        returnPage = new PageReference(Ws_QOA.QOA_DetailedQuote_Create(LQ)).setRedirect(true);
        return returnPage;
    }

 

 

So, currently the page doesn't recognize this method. However, if I remove the LineQuote LQ argument, it sees the method, for example

 

 

public PageReference GenerateRequestId(){return null;}

 

 

So, I don't know if I'm using the param tag incorrectly, or if I'm calling the method incorrectly, or if I even need to send the LQ object to the method at all. I believe I do as an almost exact copy of the process is working for another page on another controller, but I can't identify the significant difference.

 

Any ideas on why my page recognizes one version of the method, but not the other, and is it the way I'm using the param tag or something else??

 

 

Best Answer chosen by Admin (Salesforce Developers) 
d3developerd3developer

There is no way to directly pass an argument to a method (except, arguably, with an actionFunction).  That is why you have params in the first place.

 

I think you want something like this:

 

 

<apex:CommandLink value="Generate RequestID" action="{!GenerateRequestID}" reRender="theMessages">
<apex:param name="LQ" value="{!LQ.OppItem.ID}" assignTo="{!lq}" />
</apex:CommandLink>

 

 

And this:

 

 

 public LineQuote lq { get; set; }

public PageReference GenerateRequestId()
{
PageReference returnPage;
returnPage = new PageReference(Ws_QOA.QOA_DetailedQuote_Create(lq)).setRedirect(true);
return returnPage;
}

 

 

All Answers

d3developerd3developer

There is no way to directly pass an argument to a method (except, arguably, with an actionFunction).  That is why you have params in the first place.

 

I think you want something like this:

 

 

<apex:CommandLink value="Generate RequestID" action="{!GenerateRequestID}" reRender="theMessages">
<apex:param name="LQ" value="{!LQ.OppItem.ID}" assignTo="{!lq}" />
</apex:CommandLink>

 

 

And this:

 

 

 public LineQuote lq { get; set; }

public PageReference GenerateRequestId()
{
PageReference returnPage;
returnPage = new PageReference(Ws_QOA.QOA_DetailedQuote_Create(lq)).setRedirect(true);
return returnPage;
}

 

 

This was selected as the best answer
SSRS2SSRS2

yes. also you can use this method to pass parameter value using apex param tag.

 

<apex:CommandLink value="Generate RequestID" action="{!GenerateRequestID}" reRender="theMessages">
<apex:param name="LQ" value="{!LQ.OppItem.ID}" />
</apex:CommandLink>

 And

 public PageReference GenerateRequestId() {
String lq = ApexPages.currentPage().getParameters().get('LQ');
PageReference returnPage;
returnPage = new PageReference(Ws_QOA.QOA_DetailedQuote_Create(lq))setRedirect(true);
return returnPage;
}

 

-Suresh

 

OldDeadBugOldDeadBug

Thanks to both responders!!

 

I used the first method, however as for the second where the following is used.

String lq = ApexPages.currentPage().getParameters().get('LQ'); 

Does the getParameters() method work to capture the value of any component in the page, as long as it is identified with an id attribute??

String lq = ApexPages.currentPage().getParameters().get('LQ'); 
SSRS2SSRS2

>Does the getParameters() method work to capture the value of any component in the page,

  No cannot use for every components.apex  param has name attribute that's why I used getParameters() method. Also can use with html components(name attribute necessary).  

 

 

>as long as it is identified with an id attribute?

  No it is not identified with id attribute

 

-Suresh