+ Start a Discussion
Charlie CoxCharlie Cox 

Passing Parameters Using Command buttons

I am attempting to making a column of commandButtons that serve as links to other pages on a site I am making. However the commandButton is not passing the ID to the other page, thus not allowing a user to view it. Is there a way to pass parameters with commandButtons? I tried using <a href=" " > but that will not work for a public facing site.

Here is the code generating the links:

<apex:pageBlockTable value="{!courses}" var="c" id="theTable">
                <apex:column headerValue="Name" 
                  <apex:commandButton value="{!c.Name}" action="{!viewCrs}">
                        <apex:param value="{!c.Id}" assignTo="{!courseId}" name="courseId" />
                  </apex:commandButton>
                    
                </apex:column>



Alternatively I could use commandLinks. That code looks like this:

<apex:pageBlockTable value="{!courses}" var="c" id="theTable">
                <apex:column headerValue="Name"
                  <apex:commandLink value="{!c.Name}" action="{!viewCrs}">
                        <apex:param value="{!c.Id}" assignTo="{!courseId}" name="courseId" />
                  </apex:commandLink>
                </apex:column>

However when I do that and click on the link it redirects to the same page. I saw that this error came up:User-added image

I tried commenting out that line of code but still has the same problem. Again I cannot use <a> because of the issues with forward facing sites. 


Any insight would be helpful! Thanks!
Charlie CoxCharlie Cox
Just realized I forgot to include the controller:

public pageReference viewCrs() {
        pageReference reRend = new PageReference('/apex/ExecEdSelectedCourse?contactId=' + contactId + '&id=' + courseId);
        reRend.setRedirect(true);
        return reRend;
    }
Grazitti TeamGrazitti Team
Hi

It looks like you are having some javascript failure as you are using direct link to Jquery. The correct way would be adding jquery to static resources and then reference to it. Otheriwse your code has no problem. We created a dummy page by exactly copy pasting your code and it's working fine. The dummy site can be checked at below url which is working fine
http://developerboardsite-developer-edition.ap1.force.com/

let us know if you have any question .
please don't Forget to Mark this as your best answer if it works fine for you

Regards,
Grazitti Team
Web: www.grazitti.com
Charlie CoxCharlie Cox
Is there a way I can see the source code?
Grazitti TeamGrazitti Team
Hi,

Below is the code for the functionality you have seen here (http://developerboardsite-developer-edition.ap1.force.com/).


VF page:

<apex:page controller="test">
    <apex:form >
    <apex:pageblock >
    <apex:pageBlockTable value="{!courses}" var="c" id="theTable">
                <apex:column headerValue="Name">
                  <apex:commandLink value="{!c.Name}" action="{!viewCrs}">
                        <apex:param value="{!c.Id}" assignTo="{!courseId}" name="courseId" />
                  </apex:commandLink>
                </apex:column>
    </apex:pageblocktable>
    </apex:pageblock>
    </apex:form>
</apex:page>


Controller:

public class test{
   public String courseId{get;set;}
    public test(){}
    public List<contact> getcourses(){
        List<contact> cntct = [select id, name, email from contact];
       
        return cntct;
    }
    public pageReference viewCrs() {
        pageReference reRend = new PageReference('/apex/test2?id=' + courseId);
        reRend.setRedirect(true);
        return reRend;
    }
}


Regards,
Grazitti Team
Web: www.grazitti.com