【问题标题】:Get select value in radio button group in xpages by SSJS通过 SSJS 在 xpages 中的单选按钮组中获取选择值
【发布时间】:2017-01-24 13:18:25
【问题描述】:

我在 xpages 应用程序中有以下要求:

我有一个带有两个选项的单选按钮组。 我有一个组合框,其值将根据单选按钮组中选择的选项计算。选项将根据与单选按钮的 onChange 事件关联的组合框的部分刷新来计算。

我的问题是我无法在单选按钮上选择值来安装组合框选项。当我通过 SSJS 进行组装时,我还必须在 SSJS 中获取单选按钮上选择的值。 xpages 上是否有任何组件/方法可以从中获取所选值?

我知道通过 RPC 组件或 jquery 可以通过 CSJS 获得选定的值,但我只想使用 SSJS。

感谢

克努特,

我根据你的建议做了一个例子,根据下面的代码,但它不起作用。因为?

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:radioGroup id="radioGroup2">
    <xp:selectItem itemLabel="a"></xp:selectItem>
    <xp:selectItem itemLabel="b"></xp:selectItem>
    <xp:selectItem itemLabel="c"></xp:selectItem>
    <xp:eventHandler
        event="onclick"
        submit="true"
        refreshMode="partial" refreshId="computedField2" execMode="partial"   execId="radioGroup2">
    </xp:eventHandler></xp:radioGroup>
<xp:text
    escape="true"
    id="computedField2"
    value="#{javascript:getComponent('radioGroup2').getValue()}">
</xp:text><xp:br></xp:br><xp:br></xp:br>
</xp:view>

【问题讨论】:

    标签: radio-button xpages selectedvalue


    【解决方案1】:

    使用

    getComponent('radioGroup1').getValue()
    

    将“radioGroup1”替换为您的单选按钮组的id

    这是一个例子:

    <?xml version="1.0" encoding="UTF-8"?>
    <xp:view
        xmlns:xp="http://www.ibm.com/xsp/core">
        <xp:radioGroup
            id="radioGroup1"
            value="#{viewScope.radio}">
            <xp:selectItem itemLabel="a" />
            <xp:selectItem itemLabel="b" />
            <xp:eventHandler
                event="onclick"
                submit="true"
                refreshMode="partial"
                refreshId="checkBoxGroup1" execMode="partial" execId="radioGroup1">
            </xp:eventHandler>
        </xp:radioGroup>
        <xp:br></xp:br>
        <xp:checkBoxGroup
            id="checkBoxGroup1"
            value="#{viewScope.check}">
            <xp:selectItems>
                <xp:this.value><![CDATA[#{javascript:
                    if (!getComponent('radioGroup1').getValue()) {
                        return [];
                    }
                    if (getComponent('radioGroup1').getValue() == 'a') {
                        return ['A1', 'A2'];
                    }
                    return ['B1', 'B2'];
                }]]></xp:this.value>
            </xp:selectItems>
        </xp:checkBoxGroup>
    </xp:view>
    

    在本例中,您可以使用viewScope.radio 代替getComponent('radioGroup1').getValue(),因为收音机的值存储在视图范围变量中。

    【讨论】:

    • 这个我试过了,没用。在组合框的 SSJS 代码中,返回的值为 null。我应该在单选按钮的 Onchage 事件中使用此值并将其与范围变量相关联吗?
    • 它应该在你计算selectItems的组合框的部分刷新代码中。
    • 请看问题描述中的新信息。
    • 将您的示例放入一个空的新数据库中。这应该有效。那就从那里去吧。
    • 我使用的是 dojo 过滤选择。看来问题出在他身上。我解决了用组合框替换它的问题,它工作得很好,我什至不需要使用范围变量。非常感谢您的支持!
    【解决方案2】:

    我通过在组合框的计算值中使用 getComponent("RadioButtonGroup1").getValue() 来完成类似的操作。或者你可以使用这个:

    this.getParent().getValue()

    在 onChange 中填充一个作用域变量,该变量是您的组合框的基础。

    【讨论】:

    • 嗨,它成功了!但是我怎么能不使用范围变量呢?我已经使用了很多,并希望避免因为性能问题而创建更多。
    • 使用 getComponent 可能会比这更糟糕的性能杀手;您可能想从我们的一位大师那里(一如既往)阅读这个很好的解释:avatar.red-pill.mobi/tim/blog.nsf/d6plinks/TTRY-942UPQ
    • 另外,如果你使用requestScope,它的寿命很短。因为组件在页面上,所以每个请求都可以访问它。但无论您是将其存储在 requestScope 还是 viewScope 中,保存一个字符串对性能的影响都将是最小的。
    猜你喜欢
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2012-07-18
    相关资源
    最近更新 更多