Xpage .component.setValue('Some Value')适用于某些xpage但不适用于其他页面

Moh*_*gan 0 xpages xpages-ssjs xpages-extlib

我在复选框的点击事件上设置输入字段的值.可编辑字段用于验证复选框组.此代码在一个xpage中工作.当我尝试在其他xpage中复制此代码时,它无法正常工作.

这是一个有效的代码:

    <xp:checkBox
        text="pH"
        id="checkBox1"
        value="#{document1.PH}"
        checkedValue="pH">
        <xp:eventHandler
        event="onclick"
        submit="true"
        refreshMode="partial"
        refreshId="routineSectionInput1"
        execMode="partial">
            <xp:this.action>
                <xp:executeScript>
                    <xp:this.script><![CDATA[#{javascript:var  
checkBox1:com.ibm.xsp.component.xp.XspInputCheckbox = getComponent("checkBox1");
    var routineSectionInput1:com.ibm.xsp.component.xp.XspInputText = getComponent("routineSectionInput1");
    if (checkBox1.getValue()=='pH'){
    routineSectionInput1.setValue('Selected');
    } else {
    routineSectionInput1.setValue('');
    }}]]></xp:this.script>
                                               </xp:executeScript>
            </xp:this.action>
            </xp:eventHandler>
            </xp:checkBox>
Run Code Online (Sandbox Code Playgroud)

我在另一个xpage上使用了相同的字段名称和相同的代码,但它无法正常工作.我做错了什么?

最好的祝福

stw*_*sel 5

当您使用涉及绑定的组件逻辑时,请不要在组件之后,继续查找定义其值的数据.所以你的代码看起来像这样:

    <xp:checkBox text="pH" id="checkBox1"
    value="#{document1.PH}" checkedValue="pH">
    <xp:eventHandler
    event="onclick"
    submit="true"
    refreshMode="partial"
    refreshId="routineSectionInput1"
    execMode="partial">
        <xp:this.action>
            <xp:executeScript>
                <xp:this.script><![CDATA[#{javascript:var chkValue = document1.getItemValueString("PH");
                viewScope.routineSection = (chkValue=="pH") ? "Selected" : ""; 
            }]]></xp:this.script>
            </xp:executeScript>
        </xp:this.action>
        </xp:eventHandler>
        </xp:checkBox>
        <xp:text id="routineSectionInput1" value="#{viewScope.routineSection}"></xp:text>
Run Code Online (Sandbox Code Playgroud)

希望有所帮助