I need to show the selectManyCheckbox list in 4 columns, but the problem is that this component generates a table, so I do not have any idea of how to define the columns.
I am working with PF 3.4, I can't upgrade to PF 4.x. Do you guys have any solution for this?
EDITED
Now i have this in my code
<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>
The Managebean which is @ViewScoped
I changed the method suggested because it did not work for me...
from:
public void save() {
List<E> selectedItems = checkboxItems.entrySet().stream()
.filter(e -> e.getValue() == Boolean.TRUE)
.map(e -> e.getKey())
.collect(Collectors.toList());
// ...
}
to this:
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();
}
}
But i do not get any selected item on the hashMap. Just to make sure i am using jdk1.6
Generate a bunch of selectBooleanCheckbox components in a <c:forEach> loop in a <h:panelGrid columns="X"> and alter the model from List<E> to Map<E, Boolean>.
So, instead of
private List<E> selectedItems;
private List<E> availableItems;
<p:selectManyCheckbox value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
</p:selectBooleanCheckbox>
do
private Map<E, Boolean> checkboxItems;
private List<E> availableItems;
@PostConstruct
public void init() {
checkboxItems = new HashMap<>();
}
<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>
public void save() {
List<E> selectedItems = checkboxItems.entrySet().stream()
.filter(e -> e.getValue() == Boolean.TRUE)
.map(e -> e.getKey())
.collect(Collectors.toList());
// ...
}
Note that an <ui:repeat> is not applicable for the reasons explained here JSTL in JSF2 Facelets... makes sense?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With