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
WizradWizrad 

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!

Best Answer chosen by Admin (Salesforce Developers) 
WizradWizrad

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

bob_buzzardbob_buzzard

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?

WizradWizrad

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.

 

 

global void getStatus() {
	List<Object__c> statuses = [QUERY];
	
	for(Object__c status : statuses) {
		oscList.add(new OverrideStatusCoupler(status));
	}
}

 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.

 

bob_buzzardbob_buzzard
If you add in comment detail does that disappear too, or does it make it through to the controller?
WizradWizrad

It also disappears.

bob_buzzardbob_buzzard

Do you have an immediate attribute on your actionFunction?

WizradWizrad

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:

 

 

<apex:inputCheckbox value="{!currStatus.selected}" id="asdf">
       <apex:actionSupport event="onclick" rerender="asdf" />
</apex:inputCheckbox>

 

the box actually unchecks itself after a second, then laughs at me.  Onchange has the same result.

 

WizradWizrad

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.

This was selected as the best answer
bob_buzzardbob_buzzard

Good to know.