DuS*_*ant 3 jsf multiple-columns primefaces selectmanycheckbox
我需要selectManyCheckbox
在4列中显示列表,但问题是该组件生成一个表,所以我不知道如何定义列.
我正在使用PF 3.4,我无法升级到PF 4.x. 你们有这个解决方案吗?
EDITED
现在我在我的代码中有这个
<h:form id="formAdminAccesosXPerfil">
<h:panelGrid title="Accesos" columns="5">
<c:forEach items="#{accesosXPerfilMB.listadoAcceso}" var="availableItem" varStatus="loop">
<h:panelGroup>
<p:selectBooleanCheckbox id="box_#{loop.index}" value="#{accesosXPerfilMB.checkBoxItems[availableItem]}" />
<h:outputLabel for="box_#{loop.index}" value="#{availableItem.nombre}" />
</h:panelGroup>
</c:forEach>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
Managebean是@ViewScoped
我改变了建议的方法,因为它对我不起作用......
从:
public void save() {
List<E> selectedItems = checkboxItems.entrySet().stream()
.filter(e -> e.getValue() == Boolean.TRUE)
.map(e -> e.getKey())
.collect(Collectors.toList());
// ...
Run Code Online (Sandbox Code Playgroud)
}
对此:
public void guardarAccesos(){
try {
System.out.println("Size: "+getCheckBoxItems().entrySet().size());
for(BpAcceso acceso:getCheckBoxItems().keySet()){
System.out.println("Acceso Seleccionado: "+acceso.getNombre());
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
但是我没有在hashMap上获得任何选定的项目.只是为了确保我使用的是jdk1.6
selectBooleanCheckbox
在a中<c:forEach>
循环生成一组组件<h:panelGrid columns="X">
并将模型从更改List<E>
为Map<E, Boolean>
.
所以,而不是
private List<E> selectedItems;
private List<E> availableItems;
Run Code Online (Sandbox Code Playgroud)
<p:selectManyCheckbox value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
</p:selectBooleanCheckbox>
Run Code Online (Sandbox Code Playgroud)
做
private Map<E, Boolean> checkboxItems;
private List<E> availableItems;
@PostConstruct
public void init() {
checkboxItems = new HashMap<>();
}
Run Code Online (Sandbox Code Playgroud)
<h:panelGrid columns="4">
<c:forEach items="#{bean.availableItems}" var="availableItem" varStatus="loop">
<h:panelGroup>
<p:selectBooleanCheckbox id="box_#{loop.index}" value="#{bean.checkboxItems[availableItem]}" />
<h:outputLabel for="box_#{loop.index}" value="#{availableItem}" />
</h:panelGroup>
</c:forEach>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
public void save() {
List<E> selectedItems = checkboxItems.entrySet().stream()
.filter(e -> e.getValue() == Boolean.TRUE)
.map(e -> e.getKey())
.collect(Collectors.toList());
// ...
}
Run Code Online (Sandbox Code Playgroud)
注意,<ui:repeat>
由于这里解释的原因不适用于JSF2 Facelets中的JSTL ...有意义吗?
归档时间: |
|
查看次数: |
505 次 |
最近记录: |