6

I am using the apex:actionSupport control to execute some code when the apex:inputField it is associated to, has its value changed. The apex:inputField is a look up field, so it spawns a new window to do the look up and then dutifully returns the value to the control on the page. The onchange event of the apex:actionSupport control then fires, but in my apex handler, the object the apex:inputField is bound to, does not have the value populated. Any ideas how I can get this value?

Here's my code:

<apex:inputField id="ShareInputField" value="{!Share.Value__c}"> 
  <apex:actionSupport onsubmit="alert(this.value);" event="onchange" action="{!GetTarget}" immediate="true" reRender="ShareForm"/>
</apex:inputField> 

public void GetTarget(){ system.debug('USR_MSG: ' + this.Share.Value__c); } 
  • 2
    What you're describing sounds like it should work. Can you post your code? – Marcel Meijer Oct 25 '13 at 12:39
  • <apex:inputField id="ShareInputField" value="{!Share.Value__c}"> <apex:actionSupport onsubmit="alert(this.value);" event="onchange" action="{!GetTarget}" immediate="true" reRender="ShareForm"> </apex:actionSupport> </apex:inputField> public void GetTarget(){ system.debug('USR_MSG: ' + this.Share.Value__c); } The onsubmit javascript echos out the look up value correctly, but the value within my apex code is just null. – Flippsie Oct 25 '13 at 13:53
  • 1
    It was the immediate="true" attribute I had used as I had to suppress the validation of other fields in order to allow the postback. If I remove this attribute the value does make it to the bound property. – Flippsie Oct 25 '13 at 15:09
6

The main issue is that immediate=true flag. When that's set, the action method is fired before the getters and setters. This is useful for things like cancelling, when you don't actually need to process anything. However, it's preventing the controller from getting your values.

As you mentioned, removing this causes validation failures else where. You'll want to use the apex:actionregion tag to resolve this. With this in place, only that portion of the form is processed, so validations present elsewhere won't get run.

<apex:actionRegion>
  <apex:inputField id="ShareInputField" value="{!Share.Value__c}"> 
    <apex:actionSupport onsubmit="alert(this.value);" event="onchange" action="{!GetTarget}" reRender="ShareForm"/>
  </apex:inputField>
</apex:actionRegion>
  • Thanks, yes, I'd implemented an apex:actionRegion to get around the problem. – Flippsie Oct 28 '13 at 9:18
0

I think I see your problem. It should be:

public pagereference GetTarget() {  
    Your logic here...

return null; 
}

Public void does not work with actionsupport

  • Thanks for your input. I'm afraid that makes no difference. The binding does not appear to have transferred the value that was looked up to the public property. I can subsequently save the item and the value is available - no problem. It's just when the apex:actionSupport event fires that it is not populated. – Flippsie Oct 25 '13 at 14:14
  • Can you check with 'firebug' in Firefox (Or check it in chrome) what actually gets sent to salesforce? – Marcel Meijer Oct 25 '13 at 14:19
  • @MarcelMeijer public void methods should work just fine with actionsupport tags – Ralph Callaway Oct 28 '13 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.