1

Good night people. I'm a beginner in Java, very basic (I'm still studying the language). I am building an application aimed at auto workshops; it must manage vehicle maintenance data. I am at the very beginning, starting with a small piece of the project to experiment with, gradually expanding and learning. I'm using the old JDBC that I learned at College (I still have to understand JPA + Hibernate, still very raw). I use Eclipse 2020 with Maven, Java 8, JSF 2.2, BD MySql and Primefaces on the front.

Adapting part of another project that works well and that I learned in a Java course, after successfully filling a Data Table with a "select * from ORDSERV" statement in a prepareStatement, which worked normally, pulling all the records from the database, I wanted to try cross that same array with 2 criteria, service order number + service category ("select * from ORDSERV where OSCTRL_NR_OS =? AND CATEG_CD_CATEG =?") and everything worked fine in the persistence layer and in the tests, but in Bean .. the thing went crazy!

The project does not run. Eclipse points out an error on the page saying that the method I am invoking cannot be called because it is not identified with a bean member! ("searchOS cannot be resolved as a member of osb").

Can someone please give me a light ?? The codes and the error stack follow.

My native language is Portuguese, from Brazil. The code is writing in this language, naturally.

Persistence layer:

package br.com.agoraeuquero.carrotop.repositorio;

import java.util.ArrayList;
import java.util.List;
import br.com.agoraeuquero.carrotop.modelo.ControleOS;
import br.com.agoraeuquero.carrotop.modelo.OrdemServico;


public class OrdemServicoDao extends Dao {

    
    // LISTAR TODAS AS ORDENS DE SERVICO
    
    public List<OrdemServico> listaTodasOS() throws Exception {
        open();
        stmt = con.prepareStatement("select * from ORDSERV");
        rs = stmt.executeQuery();
        List<OrdemServico> lista = new ArrayList<OrdemServico>();
        while (rs.next()) {
            OrdemServico os = new OrdemServico(rs.getInt(1), rs.getInt(2), rs.getString(3), rs.getString(4),
                    rs.getString(5), rs.getString(6), rs.getString(7), rs.getDate(8), rs.getDate(9), rs.getString(10),
                    rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14));
            lista.add(os);
        }
        close();
        return lista;
    }
    
    // LISTA AS ORDENS DE SERVIÇO CONFORME CRITERIOS DE PESQUISA
    
    public List<OrdemServico> pesquisaOS() throws Exception {
        open();
        Integer nrOrdemServico = 0;
        String categoria = null;
        
        stmt = con.prepareStatement("select * from ORDSERV where OSCTRL_NR_OS=? AND CATEG_CD_CATEG=?");
        stmt.setInt(1, nrOrdemServico);
        stmt.setString(2, categoria);
        rs = stmt.executeQuery();
        List<OrdemServico> lista = new ArrayList<OrdemServico>();
        while (rs.next()) {
            OrdemServico os = new OrdemServico(rs.getInt(1),rs.getInt(2),
            rs.getString(3), rs.getString(4),rs.getString(5),rs.getString(6),
            rs.getString(7),rs.getDate(8),rs.getDate(9),rs.getString(10),
            rs.getString(11),rs.getString(12),rs.getString(13),rs.getString(14));
            lista.add(os);
        }
        close();
        return lista;
    }
    
    
    
    // LISTA TODOS OS NUMEROS E DATAS DE ORDENS DE SERVIÇO
    
    public List<ControleOS> listaNrsOS() throws Exception {
        open();
        stmt = con.prepareStatement("select * from OSCTRL");
        rs = stmt.executeQuery();
        List<ControleOS> lista = new ArrayList<ControleOS>();
        while (rs.next()) {
            ControleOS cos = new ControleOS(rs.getInt(1), rs.getDate(2));
            lista.add(cos);
            
        }
        close();
        return lista;
    }

}

Here is the main one, the Bean (control layer), which is the central question. The method getlistaTodasOS()works normally, the question is what do I need to do to correct the method getpesquisaOS .

package br.com.agoraeuquero.carrotop.controle;

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

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import br.com.agoraeuquero.carrotop.modelo.ControleOS;
import br.com.agoraeuquero.carrotop.modelo.OrdemServico;
import br.com.agoraeuquero.carrotop.repositorio.OrdemServicoDao;

@RequestScoped
@ManagedBean(name = "osb")
public class ServicoBean implements Serializable {

    private static final long serialVersionUID = 1L;

    private OrdemServico ordemServico;
    private List<OrdemServico> ordemServicoLista;
    private ControleOS controleOS;
    private List<ControleOS> controleOSLista;
    HttpSession session;

    public ServicoBean() {
    }

    public OrdemServico getOrdemServico() {
        return ordemServico;
    }

    public ControleOS getControleOS() {
        return controleOS;
    }

    public void setControleOS(ControleOS controleOS) {
        this.controleOS = controleOS;
    }

    public List<ControleOS> getControleOSLista() {
        return controleOSLista;
    }

    public void setControleOSLista(List<ControleOS> controleOSLista) {
        this.controleOSLista = controleOSLista;
    }

    public void setOrdemServico(OrdemServico ordemServico) {
        this.ordemServico = ordemServico;
    }

    public List<OrdemServico> getOrdemServicoLista() {
        return ordemServicoLista;
    }

    public void setOrdemServicoLista(List<OrdemServico> ordemServicoLista) {
        this.ordemServicoLista = ordemServicoLista;
    }

    public HttpSession getSession() {
        return session;
    }

    public void setSession(HttpSession session) {
        this.session = session;
    }
    
    // LISTA TODAS AS ORDENS DE SERVIÇO

    public List<OrdemServico> getlistaTodasOS() {
        FacesContext fc = FacesContext.getCurrentInstance();
        try {
            ordemServicoLista = new OrdemServicoDao().listaTodasOS();
        } catch (Exception ex) {
            ex.printStackTrace();
            fc.addMessage(null, new FacesMessage("Erro :" + ex.getMessage()));
        }
        return ordemServicoLista;
    }
    
    // ## PRINCIPAL: PEDE 2 PARAMETROS (NR OS E COD CATEGORIA) PARA PESQUISAR ORDENS DE SERVICO
    
    public List<OrdemServico> getpesquisaOS (Integer nrOrdemServico, String categoria) {
        FacesContext facec = FacesContext.getCurrentInstance();
        setOrdemServicoLista(ordemServicoLista);
        try
        {
            ordemServicoLista = new OrdemServicoDao().pesquisaOS();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            facec.addMessage(null, new FacesMessage("Erro :" + ex.getMessage()));
        }
        return ordemServicoLista;
    }
    
    
    // LISTA TODOS OS NUMEROS E DATAS DE ORDENS DE SERVIÇO (TABELA CONTROLE DE O.S.)
    
    public List<ControleOS> getlistaNrsOS() {
        FacesContext fc = FacesContext.getCurrentInstance();
        try {
            controleOSLista = new OrdemServicoDao().listaNrsOS();
        } catch (Exception ex) {
            ex.printStackTrace();
            fc.addMessage(null, new FacesMessage("Erro :" + ex.getMessage()));
        }
        return controleOSLista;
    }

}

Below, the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<!--    O metodo abaixo so é validado se o bean que o executa corresponder ao criterio do login -->

<h:head>
    <f:metadata>
        <f:event listener="#{mb.verificarLogin}" type="preRenderView">
        </f:event>
    </f:metadata>
</h:head>

<h:body>

    <p:panel header="CarroTop - Pesquisa Ordens de Serviço"
        style="font-size: 15px">
        <h:form id="form1">
        </h:form>
        <h:form id="form3">
            <p:commandButton value="Sair" action="#{mb.logout}" ajax="false"></p:commandButton>
        </h:form>
    </p:panel>
    
    <p:panel header="Pesquisar Ordens de Serviço - Informe 2 Criterios">
        <h:form id="form3">
            <p:panelGrid columns="2">
                <h:outputText value="Nº Ordem Serviço"/>
                <p:inputText value="#{osb.pesquisaOS.nrAmostra}">
                </p:inputText>
                <h:outputText value="Nº Grupo (1, 3, 7 ou 9) "/>
                <p:inputText value="#{osb.pesquisaOS.grupo}">
                </p:inputText>
                <p:commandButton value="Pesquisar" update=":form1;" ajax="true" action="#{osb.pesquisaOS}">
                </p:commandButton>      
                    <p:growl>
                    </p:growl>
            </p:panelGrid>
        </h:form>
    </p:panel>

    <p:panel header="Resultado da pesquisa" style="font-size: 15px">
        <h:form id="form2">
            <p:dataTable var="pesquisaOS" value="#{osb.pesquisaOS}"
                style="font-size: 13px">
                <p:column headerText="Id">
                    <h:outputText value="#{pesquisaOS.id}" />
                </p:column>
                <p:column headerText="Nº O.S.">
                    <h:outputText value="#{pesquisaOS.nrOrdemServico}" />
                </p:column>
                <p:column headerText="Categoria">
                    <h:outputText value="#{pesquisaOS.categoria}" />
                </p:column>
                <p:column headerText="Serviço">
                    <h:outputText value="#{pesquisaOS.servico}" />
                </p:column>
                <p:column headerText="Nº Renavam">
                    <h:outputText value="#{pesquisaOS.nrRenavam}" />
                </p:column>
                <p:column headerText="Nº Orçamento">
                    <h:outputText value="#{pesquisaOS.nrOrcamento}" />
                </p:column>
                <p:column headerText="Nº Chave DANFE (NFE)">
                    <h:outputText value="#{pesquisaOS.nrChaveDanfe}" />
                </p:column>
                <p:column headerText="Data Início Serviço">
                    <h:outputText value="#{pesquisaOS.dataInicioServico}">
                        <f:convertDateTime type="date" dateStyle="short"
                            pattern="dd/MM/yyyy">
                        </f:convertDateTime>
                    </h:outputText>
                </p:column>
                
                <p:column headerText="Data Final Serviço">
                    <h:outputText value="#{pesquisaOS.dataFinalServico}">
                        <f:convertDateTime type="date" dateStyle="short"
                        pattern="dd/MM/yyyy">
                        </f:convertDateTime>
                    </h:outputText>
                </p:column>
                
                <p:column headerText="Código Ocorrência">
                    <h:outputText value="#{pesquisaOS.codOcorrencia}" />
                </p:column>
                <p:column headerText="Mecânico Executor">
                    <h:outputText value="#{pesquisaOS.usuarioExecutor}" />
                </p:column>
                <p:column headerText="Serviço Autorizado por">
                    <h:outputText value="#{pesquisaOS.usuarioAutorizador}" />
                </p:column>
                
                <p:column headerText="Valor Orçado R$">
                    <h:outputText value="#{pesquisaOS.valorPrevisto}">
                        <f:convertNumber pattern="#.##0,00" type="currency" locale="pt_BR" >
                        </f:convertNumber>      
                    
                    </h:outputText>
                </p:column>
                
                <p:column headerText="Valor Real R$">
                    <h:outputText value="#{pesquisaOS.valorEfetivo}" />
                </p:column>

            </p:dataTable>
        </h:form>
    </p:panel>

</h:body>
</html>

Finally, the Error Stack:

GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/carrotop] threw exception [/ct3/logado.xhtml @32,54 value="#{osb.pesquisaOS.nrAmostra}": Property 'pesquisaOS' not found on type br.com.agoraeuquero.carrotop.controle.ServicoBean] with root cause
javax.el.PropertyNotFoundException: Property 'pesquisaOS' not found on type br.com.agoraeuquero.carrotop.controle.ServicoBean
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:268)
    at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:221)
    at javax.el.BeanELResolver.property(BeanELResolver.java:355)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:95)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
    at javax.faces.component.UIInput.getValue(UIInput.java:291)
    at org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:75)
    at org.primefaces.component.inputtext.InputTextRenderer.encodeMarkup(InputTextRenderer.java:71)
    at org.primefaces.component.inputtext.InputTextRenderer.encodeEnd(InputTextRenderer.java:52)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:89)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:81)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204)
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121)
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)



Thanks in advance!

  • See https://stackoverflow.com/questions/8577545/javax-el-propertynotfoundexception-property-foo-not-found-on-type-com-example – శ్రీ Jul 11 '20 at 06:18

1 Answers1

1

The ServicoBean class has methods getpesquisaOS() and getlistaNrsOS().

Should be: getPesquisaOS() getListaNrsOS().

Serge
  • 194
  • 6
  • Hello Serge, thanks for your reply. I just tried it, but unfortunately it didn't work, the error returned was `Property 'PesquisaOS' not found on type br.com.agoraeuquero.carrotop.controle.ServicoBean javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)` . I believe the problem is that I didn't initialize variables inside the method, to throw them in the array, I don't know how to do that. It can't even be done ... I never saw a method like this ... – Rogerio Cordeiro Jul 11 '20 at 15:55
  • Method: getPesquisaOS(). Property access: value="#{osb.pesquisaOS.nrAmostra}". Do you have like that? – Serge Jul 11 '20 at 19:00
  • Yes I have, Serge. That's right. – Rogerio Cordeiro Jul 11 '20 at 21:09
  • value="#{osb.pesquisaOS}" accesses the whole list. Why does getPesquisaOS() have arguments that do not seem to be used? Generally, getters should have no arguments. – Serge Jul 11 '20 at 22:19
  • Serge, the getPesquisaOS method needs to ask for these two arguments "nrOrdemServico" and "String category" because, a few lines below (see) it calls: `"OrdemServicoLista = new OrdemServicoDao (). BuscaOS ();"` You can follow my logic when creating this, noting that in the "OrderServicoDao" class, this "searchOS" method, uses these two parameters in the query `stmt = con.prepareStatement("select * from ORDSERV where OSCTRL_NR_OS=? AND CATEG_CD_CATEG=?");` – Rogerio Cordeiro Jul 12 '20 at 20:40
  • What do I think may be happening? I don't know how to receive these two values in the getPesquisaOS method, if I knew, I probably wouldn't have this error in execution (when I delete the snippet `(Integer nrOrdemServico, String category)` and put (), the error disappears in eclipse, but the Sql error is reported in Apache , because I didn't deliver the two parameters I need in the persistence layer ("OSCTRL_NR_OS =? AND CATEG_CD_CATEG =?"). Here's my dilemma ... – Rogerio Cordeiro Jul 12 '20 at 20:44
  • The approach should be view driven. What does your jsf page expect as a list? All orders and categories? Then create a DAO method with an SQL for all orders and categories. If jsp expects a list with a particular order and category, hard code it in getPesquisaOS(). In both cases, getPesquisaOS() should take no arguments. – Serge Jul 12 '20 at 21:16
  • Serge, reviewing my position: you are right. I found study material explaining that the methods in the bean don't take parameters, at least that way. I'm going to study some more, getting to understand better and advance, posted here. But I am already thanking you for your attention. – Rogerio Cordeiro Jul 13 '20 at 00:59
  • There is only one point to clarify: the page has two search elements that must be selected by the user. So I need to collect two parameters, to return the query in response to the parameters selected by the user. I will try to rewrite the Bean and the Dao class, so that Dao receives the parameters. That is what I think is necessary. – Rogerio Cordeiro Jul 13 '20 at 01:39
  • Search criteria as request parameters are the right way to go. If there are no more points to clarify, could you please accept the answer. – Serge Jul 13 '20 at 05:28