+ Start a Discussion
mmixmmix 

SelectList's actionSupport does not invoke setter?

Its been driving me nuts, as all of your other samples state it works, but for me it does not. Below are the pieces of code.

The actionSupport gets called on account (status is updated) but the property setters never get called from ajax (i tried in FF, IE and chrome), I only get GETTER and GETTER2 entries in the log, there is no setter call for either the contract or the account. The action Suport is properly placed inside the selectlist, so I do not believe this is a wiring problem. 

 

Another problem I have is that select list does not 'rewind' to the current value of the getter. For example  if Account__c is preassigned the select list is always positioned on the first entry in the list.

 

Can anyone help? :

 

 

<apex:pageBlockSectionItem > <apex:outputLabel value="Account" for="cmbAccount"/> <apex:selectList value="{!currentAccount}" size="1" multiselect="false" required="true" id="cmbAccount"> <apex:selectOptions value="{!AccountOptions}" /> <apex:actionSupport event="onchange" status="ajaxStatus" rerender="owner"/> </apex:selectList> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Rate" for="rateCombo"/> <apex:selectList value="{!billItem.Rate__c}" size="1" required="true" id="rateCombo"> <apex:selectOption itemValue="STD" itemLabel="STD"/> <apex:selectOption itemValue="N/C" itemLabel="N/C"/> <apex:selectOption itemValue="N/B" itemLabel="N/B"/> </apex:selectList> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Contract" for="cmbContract" /> <apex:selectList value="{!currentContract}" size="1" required="true" id="cmbContract"> <apex:selectOptions value="{!ContractOptions}" /> </apex:selectList> </apex:pageBlockSectionItem>

 

 

 

 

 

public String getCurrentAccount() { system.debug('GETTER'); return billItem.Account__c; } public void setCurrentAccount(String s) { system.debug('SETTER'); billItem.Account__c = s; } public String getCurrentContract() { system.debug('GETTER2'); return billItem.GP_Contract__c; } public void setCurrentContract(String s) { system.debug('SETTER2'); billItem.GP_Contract__c = s; } private List<SelectOption> myContractOptions; private List<GPContract__c> myContracts; public List<SelectOption> getContractOptions() { myContractOptions = new List<SelectOption>(); myContractOptions.Add(new SelectOption('', '-- None --')); myContracts = [Select id, name, Contract_Code__c from GPContract__c where account__c = :billItem.Account__c order by name]; for (GPContract__c c: myContracts) { myContractOptions.Add(new SelectOption(c.id, c.name)); } return myContractOptions; } private List<SelectOption> myAccountOptions; private List<Account> myAccounts; public List<SelectOption> getAccountOptions() { if (myAccountOptions == null) { myAccountOptions = new List<SelectOption>(); myAccounts = [Select id, name, GP_CUSTNMBR__c from account where GP_CUSTNMBR__c <> '' order by name]; for (Account a: myAccounts) { myAccountOptions.Add(new SelectOption(a.id, a.name)); } if (myAccountOptions.size() == 0) throw new MyException('No accounts associated with user'); if (billItem.Account__c == null) { billItem.Account__c = myAccounts[1].id; ResetCases(); ResetProjects(); } } return myAccountOptions; }

 

Message Edited by mmix on 01-26-2009 04:12 AM
Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Might be because you have two required fields in your form.  ActionSupport is going to do a form submit so it's going to do requiredness validation.  Try wrapping your selectList in an actionRegion tag.  That way when actionSupport fires it's only going to submit the part of the form contained within the actionRegion.

 

Also I suspect if you put a pageMessages component on your page somewhere you'd see the requiredness error message. 

All Answers

jwetzlerjwetzler

Might be because you have two required fields in your form.  ActionSupport is going to do a form submit so it's going to do requiredness validation.  Try wrapping your selectList in an actionRegion tag.  That way when actionSupport fires it's only going to submit the part of the form contained within the actionRegion.

 

Also I suspect if you put a pageMessages component on your page somewhere you'd see the requiredness error message. 

This was selected as the best answer
TehNrdTehNrd
Are any of the input fields required on this layout? If so, and the are not filled in they will prevent the set from executing. Monitor your debug log to see if it says a field is required and add this to the top of your page:

<apex:outputPanel id="error"> <apex:messages/> </apex:outputPanel>

And then where ever you have a rerender also rerender "error".