Ber*_*yan 8 java jsf richfaces
我正在使用Richfaces的选项列表,我想用我的支持bean中的SelectItems列表填充右侧面板.
填充左侧不是支持bean的问题,但右侧是有问题的.
这就是我现在拥有的
<h:outputText value="Roles" />
<rich:pickList showButtonsLabel="false">
<f:selectItems value="#{Bean.allRoles}" />
</rich:pickList>
Run Code Online (Sandbox Code Playgroud)
编辑:
所以我有角色'a','b','c'和'd'.
用户具有角色'a'和'd',因此'a'和'd'应位于右侧面板上,'b'和'c'应位于左侧面板上.
编辑:
进一步说明.
我有三个用户列表.
所有列表都具有数据类型ArrayList<SelectItem>
.
我需要能够在列表编号1和列表编号2之间移动单个角色,然后保存新的角色集.我认为该选项列表将是该工作的最佳richfaces对象.
小智 6
似乎我找到了解决方案.
<rich:pickList value="#{aBean.rightSideValues}">
<f:selectItems value="#{aBean.leftSideValues}"/>
</rich:pickList>
Run Code Online (Sandbox Code Playgroud)
"#{aBean.rightSideValues}"
应该指向列表或对象数组.使用这些值将填充选择列表的右侧.
#{aBean.leftSideValues}
应该指向SelectItem对象的列表.
ONE NOTICE - SelectItem对象必须使用来自的对象构造"#{aBean.rightSideValues}"
.
例子.
class ABean{
...
List<SomeObject> getRightSideValues(){
...
}
List<SelectItem> getLeftSideValues(){
List<SomeObjects> someObjects = getAllAvailableObjects();
List<SelectItem> sItems = new ArrayList<SelectItem>();
for(SomeObject sObj : someObjects){
SelectItem sItem = new SelectItem(sObj, sObj.toString());
sItems.add(sItem);
}
return sItems;
}
Run Code Online (Sandbox Code Playgroud)
请注意,SelectItem接受第一个参数,此参数是SomeObject的引用.在内部丰富的面孔将比较来自方法的帮助的"#{aBean.rightSideValues}"
对象中的对象
#{aBean.leftSideValues}
SomeObject.equals()
你想要这段代码:
<h:outputText value="Roles" />
<rich:pickList showButtonsLabel="false" value="#{bean.chosenRoles}">
<f:selectItems value="#{Bean.allRoles}" />
</rich:pickList>
Run Code Online (Sandbox Code Playgroud)
在你的豆子中你想要:
private String[] chosenRoles;
+ getter/setter
Run Code Online (Sandbox Code Playgroud)
每当您想要创建默认角色时,只需将角色添加到 selectedRoles 数组中(例如在 bean 构造函数中)。这样,selectedRoles 将始终包含选项列表右侧的元素,而左侧的元素不在数组中。
希望这可以帮助!
归档时间: |
|
查看次数: |
19755 次 |
最近记录: |