-1

I'm very new to JSF and I'm just following the example of a book in my course just as there is. When I'm executing the example in Net Beans I get the error: The class 'java.lang.String' does not have the property 'lista'.

My Bean class:

public class FuncionarioBean {

    private Funcionario dados;
    private FuncionarioDAO dao;
    private DataModel lista;

    public FuncionarioBean() {
        dados = new Funcionario();
        dao = new FuncionarioDAO();
    }

    public String inserir() {
        dados = new Funcionario();
        return "confirmarinserir";
    }

    public String executeInserir() {
        return dao.inserir(dados) ? "sucesso" : "erro";
    }

    public String excluir() {
        dados = dao.exibir(getId());
        return "confirmarexcluir";
    }

    public String executeExcluir() {
        return dao.excluir(dados) ? "sucesso" : "erro";
    }

    public String atualizar() {
        dados = dao.exibir(getId());
        return "confirmaratualizar";
    }

    public String executeAtualizar() {
        return dao.atualizar(dados) ? "sucesso" : "erro";
    }

    public DataModel getLista() {
        lista = new ListDataModel(dao.listar());
        return lista;
    }

        public void setLista(DataModel lista) {
                this.lista = lista;
        }

    public Funcionario getDados() {
            return dados;
        }
    public void setDados(Funcionario dados) {
            this.dados = dados;
        }

    public int getId() {
        FacesContext contexto = FacesContext.getCurrentInstance();
        HttpServletRequest req = (HttpServletRequest) contexto.getExternalContext().getRequest();
        return Integer.parseInt(req.getParameter("pid"));
    }

}

faces-config.xml

<faces-config version="2.1"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">

    <managed-bean>
        <managed-bean-name>func</managed-bean-name>
        <maged-bean-class>
            controle.FuncionarioBean
        </maged-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<f:view>
<html>
        <head>
            <f:loadBundle basename="util.configuracoes" var="conf" />
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title><h:outputText value="#{conf.Titulo}" /></title>
            <link rel="stylesheet" type="text/css" href="estilo.css">
        </head>
<body>
   <h1><h:outputText value="#{conf.Titulo}" /></h1>
<h:form>
<h:dataTable id="TabFuncionarios" value="#{func.lista}" var="lista" headerClass="cabecalho" rowClasses="linhaPar,linhaImpar">
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Id}" />
        </f:facet>
        <h:outputText value="#{lista.id}" />
    </h:column>
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Nome}" />
        </f:facet>
        <h:outputText value="#{lista.nome}" />  
    </h:column>
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Endereco}" />
        </f:facet>
        <h:outputText value="#{lista.endereco}" />
    </h:column>
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Bairro}" />
        </f:facet>
        <h:outputText value="#{lista.bairro}" />
    </h:column>
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Cidade}" />
        </f:facet>
        <h:outputText value="#{lista.cidade}" />
    </h:column>
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Cep}" />
        </f:facet>
        <h:outputText value="#{lista.cep}" />
    </h:column>
    <h:column>
        <f:facet name="header">
        <h:outputText value="#{conf.Salario}" />
        </f:facet>
        <h:outputText value="#{lista.salario}">
                    <f:convertNumber pattern="R$ ###,###,00" />
        </h:outputText>
    </h:column>
        <h:column>
        <h:commandLink action="#{func.atualizar}" value="atualizar">
            <f:param name="pid" value="#{lista.id}" />
        </h:commandLink>
    </h:column>
    <h:column>
        <h:commandLink action="#{func.excluir}" value="excluir">
            <f:param name="pid" value="#{lista.id}" />
        </h:commandLink>
    </h:column>
</h:dataTable>
<h:commandLink action="#{func.inserir}" value="Inserir Funcionário" />
</h:form>
</body>
</html>
</f:view>

Stack trace:

javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'lista'.
    at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:722)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:351)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIData.getValue(UIData.java:731)
    at javax.faces.component.UIData.getDataModel(UIData.java:1798)
    at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484)
    at javax.faces.component.UIData.setRowIndex(UIData.java:473)
    at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:820)
    at javax.faces.component.UIData.encodeBegin(UIData.java:1118)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1755)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(JspViewHandlingStrategy.java:432)
    at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:233)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)

Someone can help me?

Danilo Silva
  • 612
  • 2
  • 7
  • 16
  • Please post the stacktrace. Also, is your book teaching you JSF 2.1 or JSF 1.x? – Luiggi Mendoza Apr 21 '13 at 14:30
  • Can you point the exact line where you are getting this? – AllTooSir Apr 21 '13 at 14:35
  • The book is a pdf file that does not specify the version of JSF. – Danilo Silva Apr 21 '13 at 14:44
  • I think the line where the error ocurs is that: (I'm not sure) – Danilo Silva Apr 21 '13 at 14:45
  • @DaniloSilva then please it will be great to look for JSF 2 resources. There are good tutorials on [StackOverflow JSF wiki](http://stackoverflow.com/tags/jsf/info). I'm telling you this because since JSF 2 you use Facelets instead of JSP and almost all the configuration on managed beans (and other artifacts like converters and validators) are handled using annotations instead of faces-config file. – Luiggi Mendoza Apr 21 '13 at 14:47
  • @LuiggiMendoza I know that the pdf is a bit outdated and would like to learn new concepts later, but at the moment it would be important for me to make this example work, I think the teacher who wrote it could make it work somehow and I would like to know as. – Danilo Silva Apr 21 '13 at 14:53
  • 1
    The problem looks like `func` is being recognized as `String`. Try removing the `` configuration in your faces-config file and add these annotations to your `FuncionarioBean` class: `@ManagedBean(name="func") @SessionScoped` and add these imports: `import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped;` – Luiggi Mendoza Apr 21 '13 at 15:02
  • @LuiggiMendoza The NetBeans show me the error: cannot find symbol. symbol: method name() in @ManagedBean(name="func"). – Danilo Silva Apr 21 '13 at 15:10
  • Which symbol can't be found? I've just tested this right now and there's no problem. One more thing, make sure your JSF libraries are for JSF 2 and not for JSF 1.x. Are you working on Tomcat or GlassFish v3? – Luiggi Mendoza Apr 21 '13 at 15:17
  • The symbol is the word 'name' in: @ManagedBean(name="func") - I'm using GlassFish server 3.1.2, The JSF version: 2.1 – Danilo Silva Apr 21 '13 at 15:30
  • @DaniloSilva then there should be no problem. I've tested this on my NB just right now and compiles and run without problem. – Luiggi Mendoza Apr 21 '13 at 15:31
  • I've posted `@ManagedBean(name="func")` before the class definition: `@ManagedBean(name="func") @SessionScoped public class FuncionarioBean {` – Luiggi Mendoza Apr 21 '13 at 15:39
  • Is it possible your `faces-config.xml` is out of sync with Tomcat/Container? It is literally posing the value of "lista" as a string (hence the error). I've run into this before--a clean rebuild usually fixed it. – Daniel B. Chapman Apr 21 '13 at 16:58
  • I fixed this error creating a new project but this time setting the preferencial language in javaserverfaces configuration options to jsp and now I'm getting an exception on the connection with mysql database (classnotfoundexception - com.mysql.jdbc.Driver) – Danilo Silva Apr 21 '13 at 17:24
  • 3
    Please throw away that JSF 1.x book/tutorial/resource you're reading now and find a JSF 2.x one. JSP is **deprecated** since JSF 2.0 in 2009. – BalusC Apr 21 '13 at 21:32

5 Answers5

1

you should use another name for the var other than var=lista in datatable

Kenneth
  • 28,294
  • 6
  • 61
  • 84
  • I just had same issue, and changed the var name. I had `var="row"` and changed to `var="row_rf"`. I wasn't expecting something different to happen, it worked. Could you tell me why the heck? – unmultimedio Nov 25 '14 at 20:31
0

I fixed the error: "JSF error: The class 'java.lang.String' does not have the property 'lista'" creating a new project and setting the preferencial language to jsp instead facelets.

Danilo Silva
  • 612
  • 2
  • 7
  • 16
  • 1
    This solution is completely unrelated to this problem. Still, glad to know it worked in the end. – Luiggi Mendoza Apr 21 '13 at 19:04
  • @LuiggiMendoza The first problem of my post has solved. This answer is related with other problem that comes after the solution os the first problem, read my complete edited post to understand. – Danilo Silva Apr 22 '13 at 15:11
  • The main problem is stated in BalusC comment: you're using deprecated technologies, thus getting strange too-localized errors. If you really want to learn JSF, use JSF 2.x resources and Facelets that will enhance your experience with this technology. And a JDBC driver (or other non-JSF related libraries) won't solve the EL problem stated in your question. I could dare to say that this solution was a shot in the dark and you got lucky this time. – Luiggi Mendoza Apr 22 '13 at 15:27
  • @LuiggiMendoza My English is very bad, but I will try explain again: The solution related with the JDBC MySQL Driver is related with a exception with comes after I have fixed the exception related with the first question in my post, if you read the complete edited post you will understand. – Danilo Silva Apr 22 '13 at 16:06
  • 2
    I read the post, and I'm sure of what I'm saying: an EL problem **is not** a JDBC driver problem. – Luiggi Mendoza Apr 22 '13 at 16:07
  • Anyway, I messed up when I asked the question related to another problem in the same post. I should have opened a new post related to the new problem. Actually failed in relation to this. – Danilo Silva Apr 22 '13 at 16:08
0

I had the same problem after commenting some lines both in the java code and the .xhtml pages. But If I uncomment all the problem disappear. I have also tried to clean the browser cache. the solution seem to be either uncomment or delete the

Laura Liparulo
  • 2,849
  • 26
  • 27
0

A solution could be that your model class needs to be public:

public class Car implements Serializable{
ACV
  • 9,964
  • 5
  • 76
  • 81
0

I saw this when using <c:forTokens> instead of <c:forEach>. Use forEach for objects and property access.

J. Titor
  • 11
  • 2