2015-01-06 137 views
1

增加的分量:添加动态项目

<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> 

如何通过按下按钮添加一个新的选择信息?对于ssjs?

回答

0

Try Knut对Xpages add values into Combo Box的回答。组合框和无线电组都使用相同的底层组件。

如果您尝试从按钮中动态添加xp:selectItem元素到radioGroup组件,则该选项仅适用于该部分刷新。刷新区域tat再次包含radioGroup,它将恢复为您设计中特别编码的选项。如果您使用viewScope变量,您将保留页面生命周期的选项。

2

selectItems属性添加到radioGroup,它读取viewScope中的其他选项。设置viewScope的按钮,并添加与Java对象SelectItem一个新的选择与标签和值:

<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> 
+0

你为什么未接受周后,这个答案?它不工作了吗? –