Pudelduscher
Pudelduscher

Reputation: 379

Reading native multi select field with ssjs

i have a document in readmode and i need a multi select field in it (editable). So i create a something like this

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

    <select multiple="multiple" name="myField" id="myField" size="3">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>

    <xp:button value="Test" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:print(param.get("myField"));}]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>

</xp:view>

When i press the button i got only a value back when i select just one entry, if i select more than one, i got just null back. Is there a trick to got also multiple values from a native html field?

Upvotes: 0

Views: 231

Answers (2)

stwissel
stwissel

Reputation: 20384

Use the XPages multi-select, but bind it to a view Scope variable. Then you can access that value easily.

 <xp:checkBoxGroup id="checkBoxGroup1"
    value="#{viewScope.someOptions}">
    <xp:selectItem itemLabel="One" itemValue="1"></xp:selectItem>
    <xp:selectItem itemLabel="Two" itemValue="2"></xp:selectItem>
    <xp:selectItem itemLabel="Three" itemValue="3"></xp:selectItem>
</xp:checkBoxGroup>

That should do the trick for you. YOu then would get an array of values simply by accessing viewScope.someOptions. Let us know how it goes

Upvotes: 4

Sven Hasselbach
Sven Hasselbach

Reputation: 10485

The selected value is contained in the POST data of the HTTP request. You can access the value via RequestParameterMap of ExternalContext.

Here is an EL statement that will do the trick:

<xp:label id="label1" value="#{facesContext.externalContext.requestParameterMap.myField}" />

Upvotes: 2

Related Questions