1

Added component:

<xp:radioGroup id="radioGroup1" layout="lineDirection">
    <xp:selectItem itemLabel="1" itemValue="1"></xp:selectItem>
    <xp:selectItem itemLabel="2" itemValue="2"></xp:selectItem>
    <xp:selectItem itemLabel="3" itemValue="3"></xp:selectItem>
</xp:radioGroup>

How to add a new selectItem by pressing the button? For ssjs?

JohnLemon
  • 91
  • 8

2 Answers2

2

Add a selectItems property to radioGroup which reads additional options from a viewScope. Set the viewScope in button and add a new option with Java object SelectItem with label and value:

<xp:radioGroup id="radioGroup1" layout="lineDirection">
    <xp:selectItem itemLabel="1" itemValue="1"></xp:selectItem>
    <xp:selectItem itemLabel="2" itemValue="2"></xp:selectItem>
    <xp:selectItem itemLabel="3" itemValue="3"></xp:selectItem>
    <xp:selectItems>
        <xp:this.value><![CDATA[#{javascript:viewScope.selectItems}]]></xp:this.value>
    </xp:selectItems>
</xp:radioGroup>
<xp:button
    value="Add option"
    id="button1">
<xp:eventHandler
    event="onclick"
    submit="true"
    refreshMode="complete">
    <xp:this.action><![CDATA[#{javascript:
        if (!viewScope.selectItems) {
            viewScope.selectItems = [];
        }
        viewScope.selectItems.add(new javax.faces.model.SelectItem("Value1", "Label1"));
    }]]></xp:this.action>
</xp:eventHandler></xp:button>
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
0

Try Knut's answer to Xpages add values into Combo Box. Combo Box and Radio Group both use the same underlying component for options.

If you try to add an xp:selectItem element to the radioGroup component dynamically from the button, the option will only be available for that partial refresh. Refresh an area tat contains the radioGroup again and it will revert to the options specifically coded in your design. If you use a viewScope variable instead, you'll retain the options for the life of the page.

Community
  • 1
  • 1
Paul Stephen Withers
  • 15,699
  • 1
  • 15
  • 33