bonjour a tous,
g besoin de vos connaissances car je débute dans la programmation de java (STRUTS+AJAX+JPA+SPriNG)
mon projet est donc de réaliser une application sur de l'intranet ou net de mon entreprise d'ou l'uttilisation du code HTML dans une page JSP.
je vous met tout mon code et le code erreur aprés compilation
au fait je travail sur éclipse.
Bean : lotpackage com.st.mcc.wam.bean;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
@Entity(name ="Lot")
@Table(name = "LOT")
@NamedQueries(
@NamedQuery(name = "getAllLots", query="select object(l) from Lot l")
)
public class Lot implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "LOTID")
private String lotId = null;
private String lattice_code = null;
private int quantity = 0;
private String priority = null;
private String status_lot = null;
private String hold = null;
private String override = null;
private int date_debut = 0;
private int date_fin = 0;
private String jalon = null;
private String technology = null;
/
**
* @return the lattice_code
*/
public String getLattice_code() {
return lattice_code;
}
/**
* @param lattice_code the lattice_code to set
*/
public void setLattice_code(String lattice_code) {
this.lattice_code = lattice_code;
}
/**
* @return the quantity
*/
public int getQuantity() {
return quantity;
}
/**
* @param quantity the quantity to set
*/
public void setQuantity(int quantity) {
this.quantity = quantity;
}
/**
* @return the route
*/
/**
* @return the priority
*/
public String getPriority() {
return priority;
}
/**
* @param priority the priority to set
*/
public void setPriority(String priority) {
this.priority = priority;
}
/**
* @return the status_lot
*/
public String getStatus_lot() {
return status_lot;
}
/**
* @param status_lot the status_lot to set
*/
public void setStatus_lot(String status_lot) {
this.status_lot = status_lot;
}
/**
* @return the hold
*/
public String getHold() {
return hold;
}
/**
* @param hold the hold to set
*/
public void setHold(String hold) {
this.hold = hold;
}
/**
* @return the override
*/
public String getOverride() {
return override;
}
/**
* @param override the override to set
*/
public void setOverride(String override) {
this.override = override;
}
/**
* @return the date_debut
*/
public int getDate_debut() {
return date_debut;
}
/**
* @param date_debut the date_debut to set
*/
public void setDate_debut(int date_debut) {
this.date_debut = date_debut;
}
/**
* @return the date_fin
*/
public int getDate_fin() {
return date_fin;
}
/**
* @param date_fin the date_fin to set
*/
public void setDate_fin(int date_fin) {
this.date_fin = date_fin;
}
/**
* @return the lotId
*/
public String getLotId() {
return lotId;
}
/**
* @param lotId the lotId to set
*/
public void setLotId(String lotId) {
this.lotId = lotId;
}
/**
* @return the jalon
*/
public String getJalon() {
return jalon;
}
/**
* @param jalon the jalon to set
*/
public void setJalon(String jalon) {
this.jalon = jalon;
}
/**
* @return the technology
*/
public String getTechnology() {
return technology;
}
/**
* @param technology the technology to set
*/
public void setTechnology(String technology) {
this.technology = technology;
}
}
Ensuite avec ce bean j'implémente un form +action+factory ou(DAO) +interface
'lotinfoform' : formulaire:
import
java.util.List;import
org.apache.struts.action.ActionForm;import
com.st.mcc.wam.bean.Lot;publicclass LotInfoForm extends ActionForm {/****/privatestaticfinallongserialVersionUID = 1L;protected String lotId = null;protected List<Lot> lotList = null;/***@returnthelot*/public String getLotId() {returnlotId;}
/***@paramlotthelottoset*/publicvoid setLotId(String lot) {this.lotId = lot;}
/***@returnthelotList*/public List<Lot> getLotList() {
returnlotList;}
/***@paramlotListthelotListtoset*/publicvoid setLotList(List<Lot> lotList) {this.lotList = lotList;}
}
'lotinfoAction' : action:
package
com.st.mcc.wam.action;import
java.util.List;import
javax.servlet.http.HttpServletRequest;import
javax.servlet.http.HttpServletResponse;import
org.apache.struts.action.ActionForm;import
org.apache.struts.action.ActionForward;import
org.apache.struts.action.ActionMapping;import
org.apache.struts.actions.DispatchAction;import
com.st.mcc.wam.bean.Lot;import
com.st.mcc.wam.form.LotInfoForm;import
com.st.mcc.wam.service.LotFactory;import
com.st.mcc.wam.service.LotFactoryImpl;publicclass LotInfoAction extends DispatchAction {public ActionForward getLotInfo(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
throws Exception {LotFactory lf =
new LotFactoryImpl(); // FactoryList<Lot> lotList = lf.getLots();
//bean job((LotInfoForm) form).setLotList(lotList);
System.
out.println(" HI HA !");System.
out.println(" " + ((LotInfoForm) form).getLotId() + " !");return mapping.findForward("success");}
}
'lotinfoFactory : FACTORYpackage
com.st.mcc.wam.service;import
java.util.List;import
com.st.mcc.wam.bean.Lot;/* create an interface CRUD(Create Read Update Delete) */public
interface LotFactory {
public Lot createLot(Lot lot); /* create class Lot (Type attribute) */public Lot getLot(String lotId); /* String = return a character string LotId */publicvoid updateLot(Lot lot); /* return nothing because its update a Lot */publicvoid deleteLot(Lot lot); /*return nothing because its delete a Lot */public List<Lot> getLots(); /* return a list of lot */}
'lotinfoFactoryImpl' : action:
package com.st.mcc.wam.service;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.transaction.annotation.Transactional;
import com.st.mcc.wam.bean.Lot;
* This class is a Factory Method to creation of a list lot
*/
/** Pour ce design pattern il faudra indiquer :
*Préciser le nom de la classe.
*Préciser le type d'objet qui seront gérés par la Factory.
*Indiquer si vous désirez que cette factory deviennent aussi un manager,
* c.a.d qu'il est possible de lui confier des objets instanciés à l'extérieur
* de la classe.
*/
/* create a class LotFactoryImpl to implement interface LotFactory */
public class LotFactoryImpl implements LotFactory
{
/** Logger. */
private static final Log LOG = LogFactory.getLog(LotFactoryImpl.class);
private JpaTemplate jpaTemplate= null; /* object JpaTemplate(type) jpaTemplate(attribute) */
private EntityManager entityManager = null;
//private EntityManagerImpl = null;
public LotFactoryImpl()
{
// default constructor
}
/* (non-Javadoc)
* @see com.st.mcc.wam.service.CRUDLotfactory#createLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional /* an annotation */
public Lot createLot(Lot lot) /*Create a Lot */
{
LOG.debug("create of lot (begin)");
LOG.debug("id = " + lot.getLotId());
/* try a LOG with jpaTemplate */
try {
jpaTemplate.persist(lot);/*.persist(lot)= persistence Object(Lot) */
jpaTemplate.flush(); /* .flush = empty a memory or up to date of memory */
LOG.debug("create of lot (end)");
return lot;
}
/* Failure so catch an exception to runtime */
catch (RuntimeException e)
{
LOG.error("problem !");
return null;
}
}
/* (non-Javadoc)
* @see com.st.mcc.wam.service.CRUDLotFactory#deleteLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
public void deleteLot(Lot lot) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.st.mcc.wam.service.CRUDLotFactory#readLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
public Lot getLot(String lotId) {
LOG.debug("search of lot (begin)");
LOG.debug("id = " + lotId);
try {
Lot lot = jpaTemplate.find(Lot.class, lotId);/* .find serve to find a lot */
LOG.debug("search of lot (end)");
return lot; /*find a lot so return a lot*/
} catch (RuntimeException e) {
LOG.error("problem !");
return null; /* not find a lot so return null and to start again a search */
}
}
/* (non-Javadoc)
* @see com.st.mcc.wam.service.CRUDLotFactory#updateLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
public void updateLot(Lot lot)
{
// TODO Auto-generated method stub
}
/*the connection at BDD = EntityManagerFactory */
public void setEntityManagerFactory(EntityManagerFactory emf)
{
this.jpaTemplate = new JpaTemplate(emf);
this.entityManager = emf.createEntityManager();
}
@Transactional
public List<Lot> getLots()
{
for(int i=0; i<10; i++)
{
Lot l = new Lot();
l.setLotId("GXXXXXX_"+ i);
l.setLattice_code("ET_CONT_VIA");
l.setQuantity(3);
l.setJalon("J05");
l.setTechnology("M10");
l.setPriority("P12");
l.setStatus_lot("Wait");
l.setHold("N");
l.setOverride("Y");
int date_begin = 06/02/2008;
l.setDate_debut(date_begin);
l.setDate_debut(06/02/2008);
int date_end = 17/04/2008;
l.setDate_fin(date_end);
this.createLot(l);
LOG.debug("Lot = " + l.getLotId() );
}
List<Lot> lotList=jpaTemplate.find("SELECT LOTID FROM LOT ");
jpaTemplate.findByNamedQuery("getAllLots",lotList);
/** This is the list of object **/
return lotList;
}
}
erreur lors de l'ouverture de la page WEB:
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449) javax.servlet.http.HttpServlet.service(HttpServlet.java:697) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
java.lang.NullPointerException com.st.mcc.wam.service.LotFactoryImpl.getLots(LotFactoryImpl.java:149) com.st.mcc.wam.action.LotInfoAction.getLotInfo(LotInfoAction.java:33) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:585) org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449) javax.servlet.http.HttpServlet.service(HttpServlet.java:697) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
voila 
, je vous remercie d'avance