+ Start a Discussion

Cannot retrieve param

I'm trying to allow the user to click a button in a pageBlockTable to launch a new URL.


Here is the page code:


<apex:column style="text-align: left;vertical-align:middle;">
           <apex:facet name="header">Action</apex:facet>
                    <apex:commandButton value="Log Time" action="{!LogTime}">
                            <apex:param name="selectedJob" value="{!job.Id}"/>


..and here is the controller function:


public PageReference LogTime() {
        selectedJobID = System.currentPageReference().getParameters().get('selectedJob');
        PageReference ref = new PageReference('/' + selectedJobId);
        return ref;   


What am I doing wrong?


I've had success passing a param to the controller using the 'assignTo' attribute of the <apex:param> tag.



- move selectedJobID so that it is a public controller variable 

   (move outside of the LogTime() method)



public Id selectedJobID {get; set;}


 - Then, add the assignTo attribute to your apex:param tag


<apex:param name="selectedJob" value="{!job.Id}" assignTo="selectedJobID" />




 - finally, remove the first line of the LogTime method (PageReference should now be the first line.)