3
votes

I've created a custom control that is basically a checkbox. I want the checkbox read the value of the dataSource I pass in - which would be a managed bean. I can get the checkbox field to read from the bean but I'm not seeing anything happen when I change the checkbox. It doesn't look like the setter in the bean ever gets called.

The key snippets of my bean are:

private boolean categoriesOn;
...

public boolean isCategoriesOn() {
    System.out.println("Getting On Value");
    return categoriesOn;
}
public void setCategoriesOn(boolean newValue) {
    System.out.println("Setting On : " + newValue);
    this.categoriesOn = newValue;
}

The control on the XPage looks like this:

<xp:checkBox id="flipSwitch"
                    styleClass="onoffswitch-checkbox"
                    value="${compositeData.dataSource}"
                    checkedValue="#{javascript:true}"
                    uncheckedValue="#{javascript:false}">
                    <xp:eventHandler event="onchange" submit="true"
                        refreshMode="complete">
                    </xp:eventHandler>
                </xp:checkBox>

I pass the bean to the custom control with a custom property:

<xc:crtl_toggleSwitch
                dataSource="#{exhibitorInfo.categoriesOn}"
                refreshID="computedField6">
            </xc:crtl_toggleSwitch>

dataSource is set to use Methodbinding.

I've tried with partial and full refresh. I'm just not sure what I need to do to get the changed value back into the bean.

thanks for any advice.

1
The title of your question says combobox but the content says checkbox...Tim Tripcony
Try putting the code in the getter not the setter (or in addition to)Steve Zavocki

1 Answers

4
votes

As indicated in Peter's answer on the question Per linked to, checkboxes cannot be bound directly to booleans (which is admittedly ridiculous). Add these methods:

public String getCategoriesOnAsString(){
 return isCategoriesOn() ? "1" : "0";
}

public void setCategoriesOnAsString(String value){
 setCategoriesOn("1".equals(value));
}

Then bind your checkbox to #{exhibitorInfo.categoriesOnAsString}, and set checkedValue and uncheckedValue to "1" and "0", respectively.