0
I have this problem, specifically in the Selectmanycheckbox component.
Follow the code of my Bean:
package controle;
import java.io.Serializable; import java.util.List;
import javax.faces.bean.Managedbean; import javax.faces.bean.Viewscoped;
import exceptions.Negocioexception; import model.; import service.; import util. Messages;
@Managedbean @Viewscoped public class Cadastroatendimentobean Implements Serializable{
private static final long serialVersionUID = 1L;
private AtendimentoService atdService = new AtendimentoService();
private Atendimento atdSelecionado;
private Long idAtendimento;
private List<Pessoa> clientes;
private List<Servico> servicos;
private PessoaService pesService = new PessoaService();
private ServicoService serService = new ServicoService();
private Long indice;
public AtendimentoService getAtdService() {
return atdService;
}
public void setAtdService(AtendimentoService atdService) {
this.atdService = atdService;
}
public Atendimento getAtdSelecionado() {
return atdSelecionado;
}
public void setAtdelecionado(Atendimento atdSelecionado) {
this.atdSelecionado = atdSelecionado;
}
public Long getIdAtendimento() {
return idAtendimento;
}
public void setIdAtendimento(Long idAtendimento) {
this.idAtendimento = idAtendimento;
}
public List<Servico> getServicos() {
return servicos;
}
public void setServicos(List<Servico> servicos) {
this.servicos = servicos;
}
public PessoaService getPesService() {
return pesService;
}
public void setPesService(PessoaService pesService) {
this.pesService = pesService;
}
public List <Pessoa> getClientes() {
return clientes;
}
public void setClientes(List <Pessoa> clientes) {
this.clientes = clientes;
}
public ServicoService getSerService() {
return serService;
}
public void setSerService(ServicoService serService) {
this.serService = serService;
}
public Long getIndice() {
return indice;
}
public void setIndice(Long indice) {
this.indice = indice;
}
public void inicializar() {
clientes = pesService.buscarTodos();
setServicos(serService.buscarTodos());
if(this.getIdAtendimento() != null) {
this.atdSelecionado = this.atdService.buscaPorId(this.idAtendimento);
}
if(this.atdSelecionado == null) {
this.atdSelecionado = new Atendimento();
}
}
public void salvar() throws NegocioException {
if (atdSelecionado != null){
try {
this.atdService.salvar(this.atdSelecionado);
}catch(NegocioException e){
Mensagens.msgErro("Erro ao salvar", e.getMessage());
}
}else{
System.out.println("Cliente inválido!");
}
}
public boolean isEditing() {
return (atdSelecionado.getIdAntendimento() == null ? false : true);
}
}
The xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:o="http://omnifaces.org/ui"
template="/WEB-INF/templates/Layout.xhtml">
<ui:define name="titulo">
Atendimentos
</ui:define>
<ui:define name="conteudo">
<p:toolbar>
<p:toolbarGroup>
<p:commandButton value="Salvar" action="#{cadastroAtendimentoBean.salvar}"
update="@form"/>
</p:toolbarGroup>
<p:toolbarGroup align="right">
<p:button value="Pesquisa" outcome="/pessoa/pesquisaPessoa.xhtml" />
</p:toolbarGroup>
</p:toolbar>
<p:panelGrid columns="2" style="margin-bottom:10px" >
<p:outputLabel for="id-data" value="Data" />
<p:inputText id="id-data" value="#{cadastroAtendimentoBean.atdSelecionado.dataAtendimento}"
required="true" requiredMessage="Informe a data do atendimento"/>
<p:outputLabel for="id-valor" value="Valor" />
<p:inputText id="id-valor" value="#{cadastroAtendimentoBean.atdSelecionado.valorAtendimento}"
required="true" requiredMessage="Informe o valor do atendimento."/>
<p:outputLabel for="id-hrain" value="Hora início" />
<p:inputText id="id-hrain" value="#{cadastroAtendimentoBean.atdSelecionado.horaInAtendimento}"
required="true" requiredMessage="Informe a hora de início do atendimento."/>
<p:outputLabel for="id-hrout" value="Hora fim" />
<p:inputNumber id="id-hrout" value="#{cadastroAtendimentoBean.atdSelecionado.horaOutAtendimento}"
required="true" requiredMessage="Informe a hora do final do atendimento" />
<p:outputLabel for="id-cliAtendimento" value="Cliente" />
<p:selectOneMenu id="id-cliAtendimento" value="#{cadastroAtendimentoBean.atdSelecionado.pessoaAtendimento}"
required="true" requiredMessage="Cliente é obrigatório">
<f:selectItem itemLabel="Selecione o cliente" />
<f:selectItems value="#{cadastroAtendimentoBean.clientes}"
var="cli"
itemLabel="#{cli.nomePessoa}"
itemValue="#{cli}" />
</p:selectOneMenu>
<!-- ==================ERRO AQUI================ -->
<p:outputLabel for="id-servico" value="Servicos" />
<p:selectManyCheckbox id="id-servico"
value="#{cadastroAtendimentoBean.atdSelecionado.servicos}"
converter="servicoConverter" layout="grid">
<f:attribute name="collectionType" value="java.util.ArrayList"/>
<f:selectItems value="#{cadastroAtendimentoBean.servicos}"
var="servico"
itemLabel="#{servico.descricaoServico}"
itemValue="#{servico}" />
</p:selectManyCheckbox>
</p:panelGrid>
These are the main JSF error outputs:
Error Rendering View[/atendimento/cadastroAtendimento.xhtml]
Caused by: javax.faces.FacesException: The value of columns attribute must be greater than zero.
FATAL: JSF1073: javax.faces.FacesException obtido durante o processamento de RENDER_RESPONSE 6: UIComponent-ClientId=, Message=The value of columns attribute must be greater than zero.
I solved the error, I don’t know the meaning, but I removed the layout="grid" field and everything went as expected.
– Renato Lucas
Correcting, the "Columns" field was missing to indicate how many columns the grid should have.
– Renato Lucas