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

[8038 byte] By [Alexandre_Jaqueta] at [2007-11-26 18:12:35]
# 1
HI Alexandre,What kind of class is Hello? Java EE 5 annotation processing is only supported oncertain container-managed classes such as EJBs, servlets, JSF managed beans,EJB interceptors, Application Client main classes, etc.
ksaksa at 2007-7-9 5:45:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

First thanks for your response,

The Hello class is part from Click Framework, this class inherit from a Page class who contain

/** The request context. */

protected transient Context context;

I use Sun Application Server 9 and JEE 5

Message was edited by:

Alexandre_Jaquet

Message was edited by:

Alexandre_Jaquet

Alexandre_Jaqueta at 2007-7-9 5:45:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I'm not familiar with the Click framework but the class doesn't appear to be one of the

types that directly supports Java EE 5 environment annotations. You'll need to either

define the environment dependencies in web.xml or in some other class in the

web tier and then look up the dependencies in your Hello class.Here's one such

example from our EJB FAQ :

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB

ksaksa at 2007-7-9 5:45:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Ok thanks I will take a lookRegards
Alexandre_Jaqueta at 2007-7-9 5:45:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...