You need to sign in to do that
Don't have an account?
I seem to have broken Apex
Hi all,
I am writing some simple code here, and it doesn't work at all.
First code block is a simple wrapper class.
global class OverrideStatusCoupler { global Boolean selected {get; set;} global Something__c status {get; set;} global OverrideStatusCoupler(Something__c overStatus) { selected = false; status = overStatus; } }
Code block below is code that utilizes the wrapper class.
global with sharing class AController { global List<OverrideStatusCoupler> oscList {get; set;} global AController() { oscList = new List<OverrideStatusCoupler>(); } global PageReference submitForApproval() { //System.assertEquals('im', '' + oscList.size()); for(OverrideStatusCoupler osc : oscList) { if(osc.selected) { System.assertEquals('I', 'succeeded'); } } System.assertEquals('I','failed'); return null; } }
Finally, below is some VF that binds to the list.
<apex:repeat value="{!oscList}" var="currStatus"> <tr> <td style="width:4%;"> <apex:inputCheckbox value="{!currStatus.selected}" /> </td> <td style="width:20%;"> <apex:outputField value="{!currStatus.status.Something__r.Name__c}" /> </td> <td style="width:26%;"> <apex:outputField value="{!currStatus.status.Field_Label__c}" /> </td> <td style="width:20%;"> <apex:outputField value="{!currStatus.status.Override_Value__c}" /> </td> <td style="width:30%;"> <apex:inputText style="width:90%;" value="{!currStatus.status.Comments__c}" /> </td> </tr> </apex:repeat>
Ultimately my wrapper class couples an sobject with a boolean and then the VF page displays a list of records with the checkboxes. Pretty standard stuff. Unfortunately, AController.cls doesn't seem to care about the state of the selected boolean -- it is false no matter what I do. I can even change the definition of the wrapper class to default selected to true, and it still acts like selected is false. The control flow never goes in the if statement so the assertion...
System.assertEquals('I', 'succeeded');
...never fails. It keeps hitting at the...
System.assertEquals('I', 'failed');
...assertion. If I uncomment the assertion that assets the lists' size, I can see the list has 21 elements.
I've tried things such as rerendering the checkbox onchange, putting action regions around the checkbox. Nothing helps.
Things to note about this page:
+Javascript remoting is enabled.
+Standard stylesheets disabled
+No sidebar or header
Any ideas?
Thanks!
I have discovered that jQuery .dialog() does not mix well with VF. After switching to a VF based popup, the same code works as intended.
All Answers
Hmm. This looks very strange - especially the fact that changing the boolean at constructor time doesn't make any difference. A couple of questions/things to check:
How are you populating your list of OverrideStatusCoupler? Are you using the constructor that you have posted or is there a no-arg constructor lurking somewhere that is leaving the status as undefined?
Have you tried adding some debug to your submitForApproval method to dump out each element of the list as you process it, to check that it actually contains the data that you put in there in the first place.
Do you have the immediate attribute set to true on your command button?
When you default the checkbox to true in the wrapper class, does it appear as checked in the page when it is first rendered?
Thanks for the reply Bob. Looks like I left the code that populates the list out. It is below. This method is called as the last line of the constructor.
Yes I have put debug statements in submitForApproval, it shows the selected value as false regardless.
I am not calling this code from a commandButton. There is jQuery dialog() with a button with onclick javascript that calls submitForApproval via actionFunction.
It does appear initially checked.
It also disappears.
Do you have an immediate attribute on your actionFunction?
I was not using the immediate attribute, but if I do with either true or false it fails.
Something that is probably sort of telling is that if change up the checkbox so that:
the box actually unchecks itself after a second, then laughs at me. Onchange has the same result.
I have discovered that jQuery .dialog() does not mix well with VF. After switching to a VF based popup, the same code works as intended.
Good to know.