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;
}
}
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)
– Harry
@itasouza seu Managedbean está com escopo de Request. Change to scope of View
– igventurelli
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''.
– mari
@Good! I am on mobile. When I am on the pc update the response
– igventurelli
@updated territory
– igventurelli
I discovered the problem, I created a folder within Resources, META-INF, it solved the problem
– Harry