I cannot delete my object in datatable - JSF

Asked

Viewed 93 times

1

I am unable to delete an object in my datatable.

NOTE: I can already persisistir and change.

My Bean

    package com.irmaosuspension.controleservico.controller;

import java.io.Serializable;
import java.util.List;

import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.omnifaces.util.Messages;

import com.irmaosuspension.controleservico.modelo.Carro;
import com.irmaosuspension.controleservico.service.CarroService;
import com.irmaosuspension.controleservico.util.NegocioException;

@Named
@ViewScoped
public class ConsultaCarroBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private CarroService serviceCarro;

    private Carro carro;

    private Carro carroselecionado;

    private List<Carro> carros;

    public void inicializa() {
        if (carro == null) {
            limpar();
        }
        carros = serviceCarro.buscarTodos();
    }

    public void excluir(){
        try {
            serviceCarro.excluir(carroselecionado);
            carros.remove(carroselecionado);
            Messages.addGlobalInfo("Carro excluído com sucesso.");

        } catch (NegocioException e) {
            Messages.addGlobalError(e.getMessage());
        }
    }

    private void limpar() {
        this.carro = new Carro();
    }

    public List<Carro> getCarros() {
        return carros;
    }

    public Carro getCarro() {
        return carro;
    }

    public void setCarro(Carro carro) {
        this.carro = carro;
    }

    public Carro getCarroselecionado() {
        return carroselecionado;
    }

    public void setCarroselecionado(Carro carroselecionado) {
        this.carroselecionado = carroselecionado;
    }

}

My xhtml

<ui:define name="titulo">Pesquisa modelo de carro</ui:define>

<ui:define name="corpo">
    <h1>Pesquisa modelo de carro</h1>

    <h:form id="frmPesquisa">
        <p:messages id="messages" autoUpdate="true" closable="true" />
        <p:toolbar style="margin-top: 20px">
            <p:toolbarGroup>
                <p:button value="Novo" outcome="pesquisaModeloCarro" />
            </p:toolbarGroup>
        </p:toolbar>

        <p:dataTable id="modelosCarroTable" style="margin-top: 20px" 
                value="#{consultaModeloCarro.modeloCarros}" var="modelocarros"
                emptyMessage="Nenhum modelo de carro foi encontrado." rows="20"
                paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom">
            <p:column headerText="Código" style="text-align: center; width: 100px">
                <h:outputText  value="#{modelocarros.codigo}"/>
            </p:column>
            <p:column headerText="Modelo do Veículo" style="width: 200px; text-align:center">
                <h:outputText   value="#{modelocarros.nome}" />
            </p:column>
            <p:column headerText="Fabricante" style="width: 200px; text-align:center">
                <h:outputText  value="#{modelocarros.fabricante.nome}" />
            </p:column>
            <p:column headerText="Categoria" style="width: 200px; text-align:center">
                <h:outputText  value="#{modelocarros.categoria.descricao}" />
            </p:column>
            <p:column headerText="Editar / Excluir" style="width: 150px; text-align: center">
                <p:button outcome="cadastroModeloCarro" icon="ui-icon-pencil" title="Editar">
                    <f:param name="modelocarros" value="#{modelocarros.codigo}" />
                </p:button> 
                -
                <p:commandButton icon="ui-icon-trash" title="Excluir" oncomplete="PF('confirmacaoExclusao').show()"
                        process="@this" update=":frmPesquisa:confirmacaoExclusaoDialog">
                    <f:setPropertyActionListener value="#{modelocarros}" target="#{consultaModeloCarro.modeloCarroSelecionado}" />
                </p:commandButton>
            </p:column>
        </p:dataTable>

        <p:confirmDialog id="confirmacaoExclusaoDialog" widgetVar="confirmacaoExclusao"
                message="Tem certeza que deseja excluir o modelo #{consultaModeloCarro.modeloCarroSelecionado.nome}?"  
                header="Exclusão de modelo de carro" severity="alert">
            <p:button value="Não" onclick="PF('confirmacaoExclusao').hide(); return false;" />
            <p:commandButton value="Sim" action="#{consultaModeloCarro.excluir}" update=":frmPesquisa:modelosCarroTable" oncomplete="PF('confirmacaoExclusao').hide()" />
        </p:confirmDialog>
    </h:form>
</ui:define>

ERROR

   ADVERTÊNCIA: /modeloCarro/pesquisaModeloCarro.xhtml @47,117 target="#{consultaModeloCarro.modeloCarroSelecionado}": Property 'modeloCarroSelecionado' not writable on type com.irmaosuspension.controleservico.controller.ConsultaModeloCarro
javax.el.PropertyNotWritableException: /modeloCarro/pesquisaModeloCarro.xhtml @47,117 target="#{consultaModeloCarro.modeloCarroSelecionado}": Property 'modeloCarroSelecionado' not writable on type com.irmaosuspension.controleservico.controller.ConsultaModeloCarro
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
    at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:211)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:814)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIData.broadcast(UIData.java:1108)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotWritableException: Property 'modeloCarroSelecionado' not writable on type com.irmaosuspension.controleservico.controller.ConsultaModeloCarro
    at javax.el.BeanELResolver$BeanProperty.write(BeanELResolver.java:314)
    at javax.el.BeanELResolver$BeanProperty.access$100(BeanELResolver.java:274)
    at javax.el.BeanELResolver.setValue(BeanELResolver.java:120)
    at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
    at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
    at org.apache.el.parser.AstValue.setValue(AstValue.java:202)
    at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
    ... 33 more

mar 14, 2017 10:30:59 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: javax.el.PropertyNotWritableException: /modeloCarro/pesquisaModeloCarro.xhtml @47,117 target="#{consultaModeloCarro.modeloCarroSelecionado}": Property 'modeloCarroSelecionado' not writable on type com.irmaosuspension.controleservico.controller.ConsultaModeloCarro
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
    at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:211)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:814)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIData.broadcast(UIData.java:1108)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotWritableException: Property 'modeloCarroSelecionado' not writable on type com.irmaosuspension.controleservico.controller.ConsultaModeloCarro
    at javax.el.BeanELResolver$BeanProperty.write(BeanELResolver.java:314)
    at javax.el.BeanELResolver$BeanProperty.access$100(BeanELResolver.java:274)
    at javax.el.BeanELResolver.setValue(BeanELResolver.java:120)
    at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
    at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
    at org.apache.el.parser.AstValue.setValue(AstValue.java:202)
    at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
    ... 33 more
  • Isn’t set() method missing for this property modelCarroSelected? Another thing I would do to improve the code is to correctly capitalize on the carousel variable selected for driverSelected (changing the get and set), to stay in the default.

  • exactly, was missing the set. thanks!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.