+ Start a Discussion

urgent: passing <apex:param with command button and command link

Hi All,


I have small problem...I am trying to show the related list of contacts i.e cases when i click on apecific contact name.

it is coming good with command link but having problem with command button....here is the code.....can any one rectify it pls...


<apex:page controller="Ccontactstocases"  showChat="true" tabStyle="contract">
  <apex:form >
  <apex:pageBlock >
      <apex:pageBlockTable value="{!con}" var="Allcontacts">
          <apex:column value="{!Allcontacts.id}" />
          <apex:column >
           <apex:commandLink action="{!callcases}" styleClass="btn">
                              <apex:outputField value="{!Allcontacts.Name}"/>
                              <apex:param name="hi" value="{!Allcontacts.id}"/>
          <apex:commandbutton action="{!callcases}" value="{!Allcontacts.Name}">
                        <apex:param name="hi" value="{!Allcontacts.id}" />      
          <apex:column value="{!Allcontacts.title}"/>
    <apex:pageBlock >
    <apex:pageBlockTable value="{!cases}" var="Allcases">
        <apex:column value="{!Allcases.subject}"/>
        <apex:column value="{!Allcases.priority}"/>
        <apex:column value="{!Allcases.status}"/>



public class Ccontactstocases {

   Public list<Contact> con{get;set;}
   Public list<Case> cases{get;set;}
   public Ccontactstocases ()
       con = [select id,name, title from Contact limit 10];
public void callcases()
    ID contactid = apexpages.currentpage().getparameters().get('hi');
    cases =[select id,subject,priority,status from case where contactid = :contactid ];

Is the parameter not present on the URL when you retrieve it? I've had similar problems (although I was assigning the parameter to a controller property) in the past. The solution for me was to add a rerender to the command button - if I didn't have anything to sensibly rerender then I just put a big output panel around the body of the page.