EJB injection in bean
Hi,
I^m facing a problem while I'm trying to use new JEE notations on bean declaration.
I've an old fashioned code
/*
* Hello.java
*
* Created on 11. f関rier 2007, 07:41
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.test.page;
import com.test.ejb.entity.NewEntity;
import com.test.ejb.entity.NewEntityFacade;
import com.test.ejb.entity.NewEntityFacadeLocal;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.sf.click.Page;
import net.sf.click.control.Column;
import net.sf.click.control.Table;
/**
*
* @author alex
*/
publicclass Helloextends Page{
public Table tableToto =new Table();
@EJB
private NewEntityFacadeLocal newsEntityFacade;
@Resource
private InitialContext context;
privateint index, max, rowByPage;
/** Creates a new instance of Hello */
public Hello(){
tableToto.setClass("simple");
tableToto.setPageSize(40);
tableToto.setName("tableToto");
tableToto.addColumn(new Column("id"));
tableToto.addColumn(new Column("title"));
tableToto.addColumn(new Column("body"));
index = 0;
max = newsEntityFacade.count();
rowByPage = tableToto.getPageSize();
tableToto.setRowCount(max / rowByPage);
}
publicvoid onRender(){
index = tableToto.getPageNumber() * rowByPage ;
List<NewEntity> news = newsEntityFacade.findByIndex(index, rowByPage);
tableToto.setRowList(news);
}
publicvoid onDestroy(){
newsEntityFacade =null;
}
private NewEntityFacadeLocal lookupnewsEntityFacade(){
try{
return (com.test.ejb.entity.NewEntityFacadeLocal) context.lookup("java:comp/env/newsEntityFacade");
}
catch(javax.naming.NamingException ne){
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
thrownew RuntimeException(ne);
}
}
}
And I want to integrate new annotation allowed by EJB 3.0 + JDK 1.5
/*
* Hello.java
*
* Created on 11. f関rier 2007, 07:41
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.test.page;
import com.test.ejb.entity.NewEntity;
import com.test.ejb.entity.NewEntityFacade;
import com.test.ejb.entity.NewEntityFacadeLocal;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.sf.click.Page;
import net.sf.click.control.Column;
import net.sf.click.control.Table;
/**
*
* @author alex
*/
publicclass Helloextends Page{
public Table tableToto =new Table();
@EJB
private NewEntityFacadeLocal newsEntityFacade;
@Resource
private InitialContext context;
privateint index, max, rowByPage;
/** Creates a new instance of Hello */
public Hello(){
tableToto.setClass("simple");
tableToto.setPageSize(40);
tableToto.setName("tableToto");
tableToto.addColumn(new Column("id"));
tableToto.addColumn(new Column("title"));
tableToto.addColumn(new Column("body"));
index = 0;
max = newsEntityFacade.count();
rowByPage = tableToto.getPageSize();
tableToto.setRowCount(max / rowByPage);
}
publicvoid onRender(){
index = tableToto.getPageNumber() * rowByPage ;
List<NewEntity> news = newsEntityFacade.findByIndex(index, rowByPage);
tableToto.setRowList(news);
}
publicvoid onDestroy(){
newsEntityFacade =null;
}
}
I got null pointer exception for the newsEntityFacade .
Any idea what^s I'm doing wrong ?
Thanks.
Alexandre Jaquet

