XPages Managed Bean setter not firing on checkbox change

夙愿已清 提交于 2019-12-07 18:21:26

问题


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:


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.



来源:https://stackoverflow.com/questions/20481098/xpages-managed-bean-setter-not-firing-on-checkbox-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!