+ Start a Discussion
kfkaalkfkaal 

Checkbox does not set Boolean

I have written my own related list in VF and boud it into the main page this way:

 

 

<apex:include pageName="AccountRelatedListOperDetail_All" />

 

The page contains - amongst others - a list which needs a checkbox in front for selection.

 

 

Reduced code of  the VF page:

 

<apex:form>
<apex:PageBlockTable value="{!odList}" var="op">
...
<apex:column width="20px">
     <apex:inputCheckbox value="{!op.checked}"/>
</apex:column>
...
</apex:PageBlockTable>
</apex:form>

 

odList is a list: List<odWrapper>

 

odWrapper is just a little wapper to wrap the checkmark, the dataobject and other minor things:

 

public with sharing class nxODWrapper {
	public Operation_Detail__c od { get; set; }
	public Boolean checked { get; set; }
	public String RTShortname { get; set; }
	public String HA { get; set; }
}

 

 

My problem:

 

The checkbox does not set the variable 'checked'. When I read the 'checked' variable, it reads null. If I preset it to true before I display the table, the checkboxes are (visually) checked and I can read the variable 'checked' as true. When I uncheck the checkboxes in the ui, the variable 'checked' still has true.

 

 

So, I package 

Shashikant SharmaShashikant Sharma

I can suggest you one thing here , do not bind check box directly from object field and

Create a public boolean property in your wrapper and bind it with check box and copy its value to objects field in setter of the boolean property.

One more thing when you check or uncheck the binded value will remain same as proprty is not set yet till a sever call is invoked. but the checked property of check box control will give you idea about the checked dtatus of check box..

kfkaalkfkaal

Thank you very much for your answer.

 

But you will find, that I am doing exactly what you ask me to do:

 

In my wrapper, "od" is the object itself, "checked" is a public boolean variable in my object.

 

Any other idea what that could be?

Shashikant SharmaShashikant Sharma

Please initialize your checked property when you add item to wrapper list, do not leave it to null, give some value true or false. Try this I will try this scenario my self and will let you know further.

kfkaalkfkaal

Hi 

 

thank you very much for your time and efford.

I made a mistake. I overwrote my List with the wrapper objects before I read it again.

 

kfkaalkfkaal

I was too quick,

 

Shashikant, it would be really good if you could try what you suggested.

 

I have preset my variables, but that does not make a difference. I overwrote the 'set' procedure of my checkbox variable and tried to write some text into another variable whenever the checkbox would access its variable, but obviously, the checkbox does not access the variable.

My trial looks like this:

public with sharing class nxODWrapper {
   public Boolean checked { 
      get;
      set {
          if( log == null ) {
             log = 'x';
          } else {
             log += 'x';
          }
checked = value;
}
}
public String log { get; set; }
}

 Obviously, I bound the "checked" variable to my checkbox in the ui. At the end, I tried to read the "log" variable. In it there was only an 'x' for my first preset in my code. No click caused a access to this variable.

Could you verify that a public variable in a custom class can be bound to a ui checkbox?

 

That really would help. I could not make it (binding to a standard object's field works)

 

Thanks a lot.