Backing bind with JSF components

Asked

Viewed 303 times

2

I’m a beginner in Java EE and I’m using an e-book from Algaworks "Java EE 7, with JSF, Primefaces and CDI. Up to ManagedBean occurred normally, but when I started backing bean Java could not find the property with HtmlInputText. As the e-book example I changed the class NomeBean as follows:

Nomesbean.java

@ManagedBean
@ViewScoped
public class NomesBean {
    private String nome;
    private List<String> nomes = new ArrayList<>();
    private HtmlInputText inputNome;
    private HtmlCommandButton botaoAdicionar;

    public void adicionar() {
        this.nomes.add(nome);
        // desativa campo e botão quando mais que 3 nomes
        // forem adicionados
        if (this.nomes.size() > 3) {
        this.inputNome.setDisabled(true);
        this.botaoAdicionar.setDisabled(true);
        this.botaoAdicionar.setValue("Muitos nomes adicionados...");
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public List<String> getNomes() {
        return nomes;
    }

}

xhtml names.

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/199/xhtml"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
          xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
    <title>Lista Nomes</title>
    </h:head>
    <h:body>
        <h:form>
            Nome: <h:inputText value="#{nomesBean.nome}" binding="#{nomesBean.inputNome}" />
            <br/>
            <h:commandButton value="Adicionar" action="#{nomesBean.adicionar}" binding="#{nomesBean.botaoAdicionar}" />
            <ol>
                <ui:repeat var="nome" value="#{nomesBean.nomes}">
                    <li>#{nome}</li>
                </ui:repeat>
            </ol>
        </h:form>
    </h:body>
    </html>

Error output:

    HTTP Status 500 - /nomes.xhtml @10,85 binding="#{nomesBean.inputNome}": Property 'inputNome' not found on type com.algaworks.financeiro.model.NomesBean

    type Exception report

    message /nomes.xhtml @10,85 binding="#{nomesBean.inputNome}": Property 'inputNome' not found on type com.algaworks.financeiro.model.NomesBean

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: /nomes.xhtml @10,85 binding="#{nomesBean.inputNome}": Property 'inputNome' not found on type com.algaworks.financeiro.model.NomesBean
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    root cause

    javax.el.PropertyNotFoundException: /nomes.xhtml @10,85 binding="#{nomesBean.inputNome}": Property 'inputNome' not found on type com.algaworks.financeiro.model.NomesBean
        com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
        com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1943)
        com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1149)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(ComponentTagHandlerDelegateImpl.java:596)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:175)
        javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
        javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
        javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
        javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
        javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
        javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
        javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
        com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
        com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
        com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
        com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:991)
        com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
        com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    root cause

    javax.el.PropertyNotFoundException: Property 'inputNome' not found on type com.algaworks.financeiro.model.NomesBean
        javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:268)
        javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:221)
        javax.el.BeanELResolver.property(BeanELResolver.java:355)
        javax.el.BeanELResolver.getValue(BeanELResolver.java:95)
        com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
        com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
        org.apache.el.parser.AstValue.getValue(AstValue.java:167)
        org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
        com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
        com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1943)
        com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1149)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(ComponentTagHandlerDelegateImpl.java:596)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:175)
        javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
        javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
        javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
        javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
        javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
        com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
        javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
        javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
        com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
        com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
        com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
        com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:991)
        com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
        com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    note The full stack trace of the root cause is available in the Apache Tomcat/8.0.20 logs.

    Apache Tomcat/8.0.20

But there are more than three hours with Google search could not solve the problem.

  • Is the construction of this class of yours right? seems to me that this Nomebean would only be your class with the properties and you would have another class for example NomesLogicawhere to access the properties of NomeBean @adrianosymphony

  • getters and setters for the unput text? @adrianosymphony html component

2 answers

1

adrianosymphony, I will edit my answer as you edit the question

Add the getters and setters for inputNome and boot;

  • Even with these changes continued without access to property

  • put like this your getters and setters

  • @adrianosymphony, nothing at all?

  • I had the same error and when I followed the tip of the colleague above,I added the getters and setters the problem was solved.

0

The information of creating the getters and setters worked. The end of the Nomesbean class looked like this:

public HtmlInputText getInputNome() {
    return inputNome;
}

public void setInputNome(HtmlInputText inputNome) {
    this.inputNome = inputNome;
}

public HtmlCommandButton getBotaoAdicionar() {
    return botaoAdicionar;
}

public void setBotaoAdicionar(HtmlCommandButton botaoAdicionar) {
    this.botaoAdicionar = botaoAdicionar;
}

Browser other questions tagged

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