0

How to pass the Selected pick list value from the apex:inputfield to controller Ex: apex:inputfield value="{!case.category}" how to pass the selected value from category. -

<apex:inputField value="{!case.Category__c}"> 
  <apex:actionSupport event="onchange" reRender="Test" action="{!find}" immediate="true"> 
    <apex:param name="catval" value="{!case.Category__c}" assignTo="{!categoryfield}"/> 
  </apex:actionsupport> 
</apex:inputfield> 
<apex:inputField value="{!case.Sub_Category__c}"/> 
5
  • 3
    Please add your VF page code?
    – RCS
    Jan 20, 2017 at 10:23
  • <apex:inputField value="{!case.Category__c}"> <apex:actionSupport event="onchange" reRender="Test" action="{!find}" immediate="true"> <apex:param name="catval" value="{!case.Category__c}" assignTo="{!categoryfield}"/> </apex:actionsupport> </apex:inputfield> <apex:inputField value="{!case.Sub_Category__c}"/>
    – user40976
    Jan 20, 2017 at 10:26
  • 4
    This is due to immediate=true attribute. When that's set, the action method is fired before the getters and setters. Any specific reason for using immediate=true?
    – Saroj Bera
    Jan 20, 2017 at 10:35
  • no specific reason for that .actually i am trying to hide the field based on the picklist selection.
    – user40976
    Jan 20, 2017 at 10:43
  • If i am not keeping immediate = true then it is showing error in the debug log like tou must enter a value for other mandatory fields.
    – user40976
    Jan 20, 2017 at 10:46

1 Answer 1

0

You can use actionfunction incombination with some javascript to send values to controller as shown below: (Below is because you are using apex:inputfield. For some of the apex components, you can directly us "assignTo" to send values to controller)

Page:

<apex:page standardController="Case" extensions="tesssss">
    <apex:form>
        <apex:actionFunction name="sendValues" reRender="render">
            <apex:param name="value1" value="" assignTo="{!value1}" />
        </apex:actionFunction> 

        <apex:pageBlock>
            <apex:inputField value="{!Case.Reason}" onchange="getValues()" styleClass="value1"  />  
        </apex:pageBlock>

        <apex:outputPanel id="render">{!value1}</apex:outputPanel>
    </apex:form>

    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js" />
    <script type="text/javascript">
    var $j = jQuery.noConflict();
    function getValues() {
        var v1 = $j('.value1').val();
        if(typeof v1 != 'undefined') sendValues(v1);
    }
    </script>

</apex:page>

Controller:

public class tesssss {

    public String value1 {get; set;}

    public tesssss(ApexPages.StandardController controller) {

    }


}

You must log in to answer this question.

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