2

My problem is the following : I ask the user to select a value (<apex:inputField value="{!GDT_Activity__c.Sandbox_Name__c}" id="GDTservice" style="width:50%;">), and then compare this value and display a corresponding PageBlockSection. I would like for it to recover the value of inputField in my controller. what I need to use apex:param and how ?

/** APEX PAGES **/

            <apex:actionRegion >
            <apex:pageBlockSection title="Select a service" columns="2" >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="GDT Services" for="GDTservice"/>
                    <apex:outputPanel >  
 /*THIS INPUTFIELD*/    <apex:inputField value="{!GDT_Activity__c.GDT_Service__c}" id="GDTservice">
                            <apex:actionSupport event="onchange" reRender="thePageBlock" status="status" action="{!SelectService}" onsubmit="test(this.value)">                             
                                <apex:param name="pService" value="" assignTo="{!idService}"/>  
                            </apex:actionSupport>
                        </apex:inputField>                           
                        <apex:actionStatus startText="Loading ..." id="status" />                      
                    </apex:outputPanel>     
                </apex:pageBlockSectionItem>                 
            </apex:pageBlockSection>
        </apex:actionRegion>

/** CONTROLLER **/

public with sharing class GDT_Activity_Controller {
public Boolean S01 {get; set;}
public String idService {get; set;}

public GDT_Activity_Controller(ApexPages.StandardController controller) {
    S01 = false;
}

public void SelectService(){ 
    if(idService == 'VALUE') /** idService = VALUE INPUTFIELD **/
           S01= true; 
}
}

Thanks

1 Answer 1

2

The controller parameter of your constructor can return a reference to the record bound to the page using controller.getRecord(). You can then check this value directly. You don't need to use an apex:param attribute.

Edit

Change your controller to this:

public with sharing class GDT_Activity_Controller {
    public Boolean S01 {get; set;}
    GDT_Activity__c record;

    public GDT_Activity_Controller(ApexPages.StandardController controller) {
        S01 = false;
        record = (GDT_Activity__c)controller.getRecord();
    }

    public void SelectService(){ 
        if(record.GDT_Service__c == 'VALUE') /** idService = VALUE INPUTFIELD **/
            S01= true; 
    }
}
3
  • This is to say that I can retrieve the value in a variable like this : idService = controller.getRecord() ? May 7, 2014 at 13:19
  • @SimonG See my updated answer for how you can read the values bound to the standard controller.
    – sfdcfox
    May 7, 2014 at 13:33
  • I just apply, my god it works ! I look complicated. A big thank you. May 7, 2014 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .