Xpages 复选框控件不一致地计算值

Xpages 复选框控件不一致地计算值,xpages,xpages-ssjs,Xpages,Xpages Ssjs,我想使用checkbox控件的特性,使用SSJS根据会话变量的值返回“true”或“false”。计算仅在页面完全刷新时运行。加载页面后,代码不会进行部分或完全刷新(唯一的例外是,代码将在第一次部分或完全刷新时运行-这很有趣)。我写了一个快速演示程序。 我确信这与JSF的生命周期有关,但我对破解正在发生的事情的技术并不成熟。 谢谢 ---丽莎& 将sessionScope变量直接绑定到xp:复选框。这样,当刷新时,sessionScope变量的任何更改都将通过复选框反映出来: <xp:ch

我想使用checkbox控件的特性,使用SSJS根据会话变量的值返回“true”或“false”。计算仅在页面完全刷新时运行。加载页面后,代码不会进行部分或完全刷新(唯一的例外是,代码将在第一次部分或完全刷新时运行-这很有趣)。我写了一个快速演示程序。
我确信这与JSF的生命周期有关,但我对破解正在发生的事情的技术并不成熟。 谢谢 ---丽莎&


将sessionScope变量直接绑定到xp:复选框。这样,当刷新时,sessionScope变量的任何更改都将通过复选框反映出来:

<xp:checkBox id="checkBox1" text="Computed Checkbox" value="#{sessionScope.checked}"></xp:checkBox>

下面是一个使用按钮进行部分刷新和完全重新加载的示例:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:panel id="Panel1">
        <xp:label id="label1" value="Panel1" style="font-weight:bold"></xp:label>
        <xp:button id="button1" value="Button1 - Check the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="Panel2">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = true;
                    print("just clicked Button1 sessionScope.checked = ",sessionScope.checked);
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
        <xp:button id="button3" value="Button 2 - Uncheck the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="Panel2">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = false;
                    print("just clicked Button2 sessionScope.checked = ",sessionScope.checked);
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>

        <xp:button id="button2" value="Reload page - Uncheck the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = true;
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
        <xp:button id="button4" value="Reload page - Check the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = false;
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
    </xp:panel>

    <xp:panel id="Panel2">
        <xp:label id="label2" value="Panel2" style="font-weight:bold">
        </xp:label>
        <xp:checkBox id="checkBox1" text="Computed Checkbox" value="#{sessionScope.checked}"></xp:checkBox>
    </xp:panel>
</xp:view>

谢谢你,亨里克。我应该尝试一下,因为我过去使用绑定来帮助我完成控件。我为我的应用程序提出的解决方法稍微复杂一些。我设置了一个作用域变量,并使用该作用域变量的值来设置或取消设置带有“getComponent('componentID')。setValue('Yes'或'No')的复选框。“是”和“否”分别是选中和未选中时复选框的值。不过,如果能进行这样的计算,那就太好了——这似乎是最优雅的。但是,唉,这只是一套空的阿玛尼套装。
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:panel id="Panel1">
        <xp:label id="label1" value="Panel1" style="font-weight:bold"></xp:label>
        <xp:button id="button1" value="Button1 - Check the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="Panel2">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = true;
                    print("just clicked Button1 sessionScope.checked = ",sessionScope.checked);
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
        <xp:button id="button3" value="Button 2 - Uncheck the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="Panel2">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = false;
                    print("just clicked Button2 sessionScope.checked = ",sessionScope.checked);
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>

        <xp:button id="button2" value="Reload page - Uncheck the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = true;
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
        <xp:button id="button4" value="Reload page - Check the Box">
            <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:
                    sessionScope.checked = false;
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
    </xp:panel>

    <xp:panel id="Panel2">
        <xp:label id="label2" value="Panel2" style="font-weight:bold">
        </xp:label>
        <xp:checkBox id="checkBox1" text="Computed Checkbox" value="#{sessionScope.checked}"></xp:checkBox>
    </xp:panel>
</xp:view>