Bom dia caros amigos do forum, estou com um probleminha que não consigo resolver. Permitam-me explicar.
Eu possuo a entidade abaixo sell
package br.com.loja.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
@Entity(name="sell")
public class Sell implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id")
private Integer id;
@JoinColumn(name="id_product",referencedColumnName="id")
@ManyToOne(fetch=FetchType.LAZY,optional=false)
private Product product;
@JoinColumn(name="id_vendor",referencedColumnName="id")
@ManyToOne(fetch=FetchType.LAZY,optional=false)
private User vendor;
@Column(name="number_of_itens")
private int numberOfItens;
@Version
private int version;
public Sell() {
}
public Sell(Integer id, Product product, User vendor, int numberOfItens,
int version) {
super();
this.id = id;
this.product = product;
this.vendor = vendor;
this.numberOfItens = numberOfItens;
this.version = version;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public User getVendor() {
return vendor;
}
public void setVendor(User vendor) {
this.vendor = vendor;
}
public int getNumberOfItens() {
return numberOfItens;
}
public void setNumberOfItens(int numberOfItens) {
this.numberOfItens = numberOfItens;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Sell other = (Sell) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
tenho aqui meu faces
package br.com.loja.ManagedBean;
import java.util.List;
import javax.faces.model.SelectItem;
import br.com.loja.dao.ProductDAO;
import br.com.loja.dao.SellDAO;
import br.com.loja.dao.UserDAO;
import br.com.loja.entity.Product;
import br.com.loja.entity.Sell;
import br.com.loja.entity.User;
public class SellFaces {
private final SellDAO dao = new SellDAO();
private final UserDAO daoUser = new UserDAO();
private final ProductDAO daoProduct = new ProductDAO();
private List<Sell> sells;
private Sell sellInAction;
public SellFaces() {
}
public String doStartSell(){
sellInAction = new Sell();
return "gotoAddSell";
}
public String finishStartSell(){
dao.addSell(sellInAction);
sells = null;
return "gotoListSell";
}
public SelectItem[] getVendors(){
List<User> users = daoUser.getAllUsers();
SelectItem[] retorno = new SelectItem[users.size()];
for (int i = 0; i < retorno.length; i++) {
retorno[i] = new SelectItem(users.get(i).getId(),users.get(i).getName());
}
return retorno;
}
public SelectItem[] getProducts(){
List<Product> products = daoProduct.getAllProducts();
SelectItem[] retorno = new SelectItem[products.size()];
for (int i = 0; i < retorno.length; i++) {
retorno[i] = new SelectItem(products.get(i).getId(),products.get(i).getName());
}
return retorno;
}
public void setSell(List<Sell> sell) {
this.sells = sell;
}
public List<Sell> getSell() {
if (sells == null){
sells = dao.getAllSells();
}
return sells;
}
public void setSellInAction(Sell sellInAction) {
this.sellInAction = sellInAction;
}
public Sell getSellInAction() {
return sellInAction;
}
}
aqui meu dao
package br.com.loja.dao;
import java.util.List;
import javax.persistence.EntityManager;
import br.com.loja.entity.Sell;
import br.com.loja.util.JPAUtil;
public class SellDAO {
public SellDAO() {
}
public int addSell(Sell sell) {
EntityManager em = JPAUtil.getInstance().getEntityManager();
em.persist(sell);
em.getTransaction().commit();
em.close();
return sell.getId();
}
public Sell getSell(int idSell) {
return JPAUtil.getInstance().getEntity(Sell.class, idSell);
}
public void removeSell(Sell sell) {
EntityManager em = JPAUtil.getInstance().getEntityManager();
sell = em.getReference(Sell.class, sell.getId());
em.remove(sell);
em.getTransaction().commit();
em.close();
}
public void updateSell(Sell sell) {
EntityManager em = JPAUtil.getInstance().getEntityManager();
em.merge(sell);
em.getTransaction().commit();
em.close();
}
public List<Sell> getAllSells() {
return JPAUtil.getInstance().getList(Sell.class,
"select sl from sell sl");
}
}
aqui esta minha pagina para adicionar
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head></head>
<body>
<h1>Add new Sale</h1>
<h:form>
<h:messages />
Id:<h:inputText id="id" value="#{sellFaces.sellInAction.id}" />
<br />
Product:<h:selectOneMenu id="product" value="#{sellFaces.sellInAction.product}">
<f:selectItems value="#{sellFaces.products}" />
<f:converter converterId="ProductConverter"/>
</h:selectOneMenu>
<br />
Vendor:<h:selectOneMenu id="vendor" value="#{sellFaces.sellInAction.vendor}">
<f:selectItems value="#{sellFaces.vendors}" />
</h:selectOneMenu>
<br />
Number of Itens:<h:inputText id="noi" value="#{sellFaces.sellInAction.numberOfItens}" />
<br />
<h:commandButton value="Inserir Venda" action="#{sellFaces.doStartSellfinishStartSell}" />
</h:form>
</body>
</html>
e quando tento adicionar os valores, isso aparece:
0/09/2009 10:21:13 com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: /pages/addSell.xhtml @11,67 value="#{sellFaces.sellInAction.id}": Target Unreachable, 'sellInAction' returned null
javax.el.PropertyNotFoundException: /pages/addSell.xhtml @11,67 value="#{sellFaces.sellInAction.id}": Target Unreachable, 'sellInAction' returned null
at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
at javax.faces.component.UIInput.validate(UIInput.java:868)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
at javax.faces.component.UIInput.processValidators(UIInput.java:672)
at javax.faces.component.UIForm.processValidators(UIForm.java:234)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:700)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Unknown Source)
10/09/2009 10:21:13 com.sun.faces.lifecycle.Phase doPhase
SEVERE: JSF1054: (Phase ID: PROCESS_VALIDATIONS 3, View ID: /pages/addSell.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@169d75d]
10/09/2009 10:21:13 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.el.PropertyNotFoundException: /pages/addSell.xhtml @11,67 value="#{sellFaces.sellInAction.id}": Target Unreachable, 'sellInAction' returned null
at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
at javax.faces.component.UIInput.validate(UIInput.java:868)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
at javax.faces.component.UIInput.processValidators(UIInput.java:672)
at javax.faces.component.UIForm.processValidators(UIForm.java:234)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:700)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Unknown Source)
Alguém teria ideia do que seja o problema ?