Search code examples
javascriptxpagestypeof

checkBoxGroup: typeof return [Ljava.lang.String


I have the following XPage, one checkboxgroup and one computedfield

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:panel id="ref">
        <xp:checkBoxGroup id="checkBoxGroup1">
            <xp:selectItems>
                <xp:this.value><![CDATA[#{javascript:var val = ["Test1", "Test2"];
return val}]]></xp:this.value>
            </xp:selectItems>
            <xp:eventHandler event="onchange" submit="true"
                refreshMode="partial" refreshId="ref">
            </xp:eventHandler>
        </xp:checkBoxGroup>

        <xp:text escape="true" id="computedField3">
            <xp:this.value><![CDATA[#{javascript:typeof getComponent("checkBoxGroup1").getValue()}]]></xp:this.value>
        </xp:text>
        <xp:br></xp:br>
    </xp:panel>
</xp:view>

When I click the checkboxes I was expeciting the computedField to return a type of array, instead it returns [Ljava.lang.String

how can I change my code so that if I select one or more checkboxes the computedField returns a type of "array" or "vector"


Solution

  • Try this snippet on OpenNTF Snippets site https://openntf.org/XSnippets.nsf/snippet.xsp?id=convert-any-value-to-an-array