-1

私はJSFに非常に慣れていないので、コースの本の例に従っているだけです。Net Beans で例を実行すると、次のエラーが表示されます。クラス 'java.lang.String' にはプロパティ 'lista' がありません。

私のBeanクラス:

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"));
    }

}

顔-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>

スタックトレース:

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)

誰かが私を助けることができますか?

4

5 に答える 5

1

var以外var=listaには別の名前を使用する必要がありますdatatable

于 2013-04-22T20:55:40.630 に答える
0

解決策は、モデル クラスをパブリックにする必要があることです。

public class Car implements Serializable{
于 2015-03-17T21:51:51.083 に答える
0

「JSF エラー: クラス 'java.lang.String' にプロパティ 'lista' がありません」というエラーを修正しました。新しいプロジェクトを作成し、優先言語を facelets ではなく jsp に設定します。

于 2013-04-21T18:15:14.437 に答える
0

<c:forTokens>の代わりに使用したときにこれを見ました<c:forEach>。オブジェクトとプロパティへのアクセスには forEach を使用します。

于 2017-08-07T12:59:30.350 に答える