Registration error "Does not recognize the property"

Asked

Viewed 91 times

1

I’m studying Java EE and I came across a mistake, if anyone knows the answer I appreciate it. I have my form:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core">



    <h:form>
       <div>
           <h:outputLabel value="Título"/>
           <h:inputText value="#{adminLivrosBean.Livro.titulo}"/>
       </div>  
       <div>
           <h:outputLabel value="Descrição"/>
           <h:inputTextarea rows="4" cols="20" value="#{adminLivrosBean.livro.descricao}"/>
       </div>    
        <div>
           <h:outputLabel value="Número Páginas"/>
           <h:inputText value="#{adminLivrosBean.Livro.numeroPaginas}"/>
       </div>    
        <div>
           <h:outputLabel value="Preço"/>
           <h:inputText value="#{adminLivrosBean.Livro.preco}"/>
       </div>  

       <h:commandButton value="Cadastrar" action="#{adminLivrosBean.salvar}"/>

    </h:form>



</html>

Tenho Bean:

package br.com.casadocodigo.loja.beans;

import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.inject.Named;
import br.com.casadocodigo.loja.models.Livro;

//CDI
@Named
@RequestScoped
@ManagedBean(name="adminLivrosBean")
public class AdminLivrosBean {

    private Livro livro = new Livro();


    public void salvar(){

        System.out.println("Livro Cadastrado:" + livro);

    }


    public Livro getLivro() {
        return livro;
    }


    public void setLivro(Livro livro) {
        this.livro = livro;
    }
}

inserir a descrição da imagem aqui

3 answers

1

Java is case sensitive, that is, it differs between upper and lower case.

Exchange all XHTML references from Livro for livro and it will work:

Of:

<h:form>
   <div>
       <h:outputLabel value="Título"/>
       <h:inputText value="#{adminLivrosBean.Livro.titulo}"/>
   </div>  
   <div>
       <h:outputLabel value="Descrição"/>
       <h:inputTextarea rows="4" cols="20" value="#{adminLivrosBean.livro.descricao}"/>
   </div>    
    <div>
       <h:outputLabel value="Número Páginas"/>
       <h:inputText value="#{adminLivrosBean.Livro.numeroPaginas}"/>
   </div>    
    <div>
       <h:outputLabel value="Preço"/>
       <h:inputText value="#{adminLivrosBean.Livro.preco}"/>
   </div>  

   <h:commandButton value="Cadastrar" action="#{adminLivrosBean.salvar}"/>

</h:form>

To:

<h:form>
   <div>
       <h:outputLabel value="Título"/>
       <h:inputText value="#{adminLivrosBean.livro.titulo}"/>
   </div>  
   <div>
       <h:outputLabel value="Descrição"/>
       <h:inputTextarea rows="4" cols="20" value="#{adminLivrosBean.livro.descricao}"/>
   </div>    
    <div>
       <h:outputLabel value="Número Páginas"/>
       <h:inputText value="#{adminLivrosBean.livro.numeroPaginas}"/>
   </div>    
    <div>
       <h:outputLabel value="Preço"/>
       <h:inputText value="#{adminLivrosBean.livro.preco}"/>
   </div>  

   <h:commandButton value="Cadastrar" action="#{adminLivrosBean.salvar}"/>

</h:form>
  • Igor, I appreciate the help, I did exactly what you show, but now I have another error: javax.servlet.Servletexception: /books/form.xhtml @13,62 value="#{adminLivrosBean.livro.titulo}": Target Unreachable, Identifier 'adminLivrosBean' resolved to null javax.faces.webapp.FacesServlet.service(Facesservlet.java:671)

  • @itasouza seu Managedbean está com escopo de Request. Change to scope of View

  • It does not directly use the attribute 'book' but the getter 'getLivro()'. For example, even if you have the book attribute but don’t have a getLivro() you will get the error 'does not have the Property' book''.

  • @Good! I am on mobile. When I am on the pc update the response

  • @updated territory

  • 1

    I discovered the problem, I created a folder within Resources, META-INF, it solved the problem

Show 1 more comment

1

Where you have adminLivrosBean.Book, switch to adminLivrosBean.Book with 'l' minimum.

Servlet when viewing adminLivrosBean.book will search in the Adminlivrosbean class (class with @Managedbean annotation(name="adminLivrosBean")) for a getter getLivBean().

0

Remember to follow the Javabeans convention. If your bean has a book property, most frameworks will look for a getLivro and setLivro method to retrieve and write data to this property. Swap Book in template for book.

You can learn more about javabeans patterns this link that leads to an oracle document

Browser other questions tagged

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