Pesssoal como faço para fazer um opcão selecionar todos para um SelectManyCkeckBox ? Será que tem como fazer com javascript para selecionar os ckecks ? como fazer?
<h:selectManyCheckbox id="fundo" value="#{ManterSimulacao.fundosSelecionadosCarteira}" layout="pageDirection" >
<f:selectItems value="#{ManterSimulacao.listarFundosPorFiltro}"/>
</h:selectManyCheckbox>
<h:selectManyCheckbox value="" >
<h:outputLabel value="Selecionar Todos"/>
</h:selectManyCheckbox>
Exemplo básico:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:rich="http://richfaces.org/rich"
template="/templates/template.xhtml">
<ui:define name="corpo">
<h:form>
<h:messages infoStyle="color: green"/>
<rich:dataTable align="center" width="60%" id="listFinanciamentos"
rows="10" onRowMouseOver="this.style.backgroundColor='#CCCCCC'"
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.rowBackgroundColor}'"
rowClasses="odd-row,even-row" rendered="true" columnClasses="col"
var="row">
<f:facet name="header">
<rich:columnGroup>
<rich:column style="text-align:center">
<h:outputText value="Clientes"/>
</rich:column>
</rich:columnGroup>
</f:facet>
</rich:dataTable>
<a4j:outputPanel ajaxRendered="true">
<rich:dataTable align="center" width="60%" id="tabela"
rows="10" onRowMouseOver="this.style.backgroundColor='#CCCCCC'"
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.rowBackgroundColor}'"
rowClasses="odd-row,even-row" rendered="true" columnClasses="col"
var="row" value="#{clienteController.clientes}">
<f:facet name="header">
<rich:columnGroup>
<rich:column>
<h:outputText styleClass="headerText" value="Nome" />
</rich:column>
<rich:column>
<h:outputText styleClass="headerText" value="Ativo" />
</rich:column>
<rich:column />
</rich:columnGroup>
</f:facet>
<rich:column>
<h:outputText value="#{row.nome}" />
</rich:column>
<rich:column>
<h:selectBooleanCheckbox value="#{row.ativo}" />
</rich:column>
</rich:dataTable>
</a4j:outputPanel>
<h:commandButton value="Marcar Todos" action="#{clienteController.marcar}"/>
<h:commandButton value="DesMarcar Todos" action="#{clienteController.desmarcar}"/>
</h:form>
</ui:define>
</ui:composition>
MB:
public void marcar(){
for(Cliente c:clientes){
c.setAtivo(true);
}
}
public void desmarcar(){
for(Cliente c:clientes){
c.setAtivo(false);
}
}
fiz do lado clientes mesmo , acho que fico melhor utilizando javascript.
<h:selectManyCheckbox id="fundo" value="#{ManterSimulacao.fundosSelecionadosCarteira}" layout="pageDirection" >
<f:selectItems value="#{ManterSimulacao.listarFundosPorFiltro}"/>
</h:selectManyCheckbox>
<h:selectBooleanCheckbox id="btnCkeckSelecionaTodos" onclick="selecionarTodosFundos();"/>
<h:outputLabel value="Selecionar todos"/>
function selecionarTodosFundos(){
var marcar = false;
if(document.getElementById("Form1:j_id25:opcaoPainel:btnCkeckSelecionaTodos").checked){
marcar = true;
}
existeFundo = false;
i = 0;
do {
var fundo = document.getElementById("Form1:j_id25:opcaoPainel:fundo:"+i);
if(fundo != null){
fundo.checked = marcar;
existeFundo = true;
}else{
existeFundo = false;
}
i++;
}while(existeFundo);
}