+ Start a Discussion
mba75mba75 

passing a parameter from a pageBlockTable commandlink to the controller

I basically want to hide some panel in my page to do that I want to update the variable Modif_mode :
 
The default Value is false this value should be update to true when I click on my commandLink but nothing happen
 
Any Idea ?
 
<apex:outputpanel id="Mode">
           <apex:outputlabel  value="{!Modif_mode}" />
</apex:outputpanel>

 
<apex:pageBlockTable value="{!Opportunity.OpportunityLineItems}" var="opplis" id="line_items" >
          <apex:column headerValue="Action">        
                <apex:commandLink rerender="Mode">Modif
                          <apex:param name="Modif_mode" value="true" assignTo="{!Modif_mode}"/>
                  </apex:commandLink>
          </apex:column>
</apex:pageBlockTable>
 
controller :
 

Boolean Modif_mode = false;

public boolean getModif_mode() {return Modif_mode;}

public Void setModif_mode (Boolean b) { Modif_mode = b; }

 

 

jwetzlerjwetzler
I'm not totally sure what's going wrong here but instead of using the param component, you should just put an action method on your command link that sets the value of Modif_mode and returns null.  Also you should make Modif the value of your commandLink.
<apex:commandLink rerender="Mode" value="Modif" action="{!doSwitch}"/>

Also I think you should be using outputText instead of outputLabel.
mba75mba75
thank you if I add immediate="true " it works .
and my modif_mode variable is update to true .
but it should show the following button and hide the following outpupanel:
 
<apex:pageBlockButtons id="PBB">
<apex:commandButton id="nl" Value="Add New line" action="{!RunHide}" immediate="true" rerender="fam_prod,Mode,nl, PBB" rendered="{!if(Modif_mode=true,'true','false')}">
<apex:param name="pbeName" value="Add New Product"/>
</apex:commandButton>
</apex:pageBlockButtons>

<apex:outputpanel id="fam_prod" rendered="{!if(Modif_mode=true,'false','true')}"> 
        <apex:outputLabel value="Product Family:" for="family"/>
        <apex:actionRegion >
        <apex:selectList value="{!family}" size="1" id="families" >
        <apex:actionSupport event="onchange" rerender="Products,Rate_types,Plans"/>
        <apex:selectOptions value="{!families}"/>
        </apex:selectList>
        </apex:actionRegion>
        <apex:outputLabel value="Product:" for="Products"/>
        <apex:actionRegion >
        <apex:selectList value="{!Product}" size="1" id="Products" disabled="{!ISNULL(family)}">
        <apex:selectOptions value="{!Products}"/>
        <apex:actionSupport event="onchange" rerender="Rate_types,Plans"/>
        </apex:selectList>
        </apex:actionRegion>
</apex:outputpanel>
 
Any idea ?

helpForcehelpForce
I'm trying to do the same thing as mba75, in that I want to pass a parameter to my controller from a commandButton.

So i click the button, it passes a variable from my datatable (ID of custom object) to a controller method,  which redirects to a new page using that parameter.

The issue here is that the value of the parameter is a variable from my datatable, not just true or false.

page code:

<apex:form >
    <apex:pageBlock title="">
     
        <apex:dataTable value="{!detailedAvailability}" var="ava" styleClass="list">
                <apex:column headerValue="Resource">                       
                        <apex:outputText value="{!ava.empFirstName} {!ava.empLastName}"/>              
                <apex:column headerValue="Option">                                                                                                                    
                        <apex:commandButton action="{!onClickBook}" value="Book Now" id="theButton">   
                             <apex:param value="{!ava.empId}" assignTo="{!empId2}" />
                             </apex:commandbutton>                                               
                </apex:column>                
        </apex:dataTable>
    </apex:pageBlock>
  </apex:form>

controller

.....

String empId2 = null;
   
public void setEmpId2(String emp) { empId2 = emp;}   

public String getEmpId2() { return empId2; }

public PageReference onClickBook() {       
  PageReference pageRef = new PageReference('/' + empId2);
  pageRef.setRedirect(true);       
  return pageRef;
 }

......

I've simplyfied what im doing here for this example, as i will be using the returned paramter in a query etc. The code works fine besides the fact the parameter empId2 doesn't update when the button is clicked. i.e. if i put {!ava.empId} in the value field of the
command button is displays the relevant employeeID per line, just can;t seem to pass it to my controller (it stays null)!

any help appreciated.