function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dean Abraham.ax925Dean Abraham.ax925 

Parameter not being passed to Apex properly

  I have been struggling to get this working, and hope somebody can help me get back on track.

  This visualforce page has a radiolist selector, which needs to fire off a function in the Apex controller with a parameter.  When the function fires off, debugging shows me that the value being returned is from the previous radio selection, not the current selection.  Seems like the action is firing off before the rerender (and param assignment)?

  I have tried using the "onclick" event, grabbing the value from the querystring rather than the assignTo, and neither worked.

 

  Can anybody offer any suggestions?

 

Visualforce Page:

<apex:outputPanel id="approvalStat" >

  <apex:selectRadio value="{!insurance.Approval_Stage__c}" layout="pageDirection" styleClass="checkwrap">
    <apex:actionSupport event="onchange" rerender="approvalStat, errors, insuranceRejectionArea" action="{!validateOnApproval}">
       <apex:param name="inAS" value="{!insurance.Approval_Stage__c}" assignTo="{!inAS}" />
    </apex:actionSupport>
    <apex:selectOptions value="{!ApprovalStages}" />
  </apex:selectRadio>

</apex:outputPanel>

 

Controller:

 

public String inAS { //Holds the Approval Status from page
        get;
        set{
            inAS = value;
        }
    }

 

public pageReference validateOnApproval()

{

        if(inAS != 'Approved') {
            System.debug('\n\n******************* Action Status:' + inAS + '\n\n');
            return null; //Only act when Approved
        }

}

 

Thanks in advance!

Dean

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I believe this is because of the way you are setting up the value - the merge field will be evaluated when the page is rendered, it won't be dynamically recalculated as part of the onchange event.

 

 

<apex:actionSupport event="onchange" rerender="approvalStat, errors, insuranceRejectionArea" action="{!validateOnApproval}">
     <apex:param name="inAS" value="{!insurance.Approval_Stage__c}" assignTo="{!inAS}" />
</apex:actionSupport>

 

You shouldn't need to pass the parameter, as you are backing the selectradio component with data from the viewstate. By the time your validateOnApproval action method is invoked, the Approval_Stage__c field of your insurance object will have been updated with the user's selection.

 

 

 

All Answers

bob_buzzardbob_buzzard

I believe this is because of the way you are setting up the value - the merge field will be evaluated when the page is rendered, it won't be dynamically recalculated as part of the onchange event.

 

 

<apex:actionSupport event="onchange" rerender="approvalStat, errors, insuranceRejectionArea" action="{!validateOnApproval}">
     <apex:param name="inAS" value="{!insurance.Approval_Stage__c}" assignTo="{!inAS}" />
</apex:actionSupport>

 

You shouldn't need to pass the parameter, as you are backing the selectradio component with data from the viewstate. By the time your validateOnApproval action method is invoked, the Approval_Stage__c field of your insurance object will have been updated with the user's selection.

 

 

 

This was selected as the best answer
Dean Abraham.ax925Dean Abraham.ax925

Bob,  Thanks for taking a look!

 

The ugly, hidden truth is that this is part of a collection of objects that are inside a repeat control.  So, I just returned the ID of the row as my parameter instead, then iterated over the collection to find the individual row/value and presto!

 

Thank you for your help!