Je cherche à injecter un session bean dans mon prog de test mais celui-ci n'est pas invoker

a la place d'écrire le code de cette manière :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
/*
 * Hello.java
 *
 * Created on 11. février 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.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
 */
public class Hello extends Page {
 
    public Table tableToto = new Table();;    
    private NewEntityFacadeLocal newsEntityFacade;
    private int index, max, rowByPage;
 
    /** Creates a new instance of Hello */
    public Hello() {        
        if (newsEntityFacade == null) newsEntityFacade = lookupNewEntityFacade();
        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);
    }
 
    public void onRender() {        
        index = tableToto.getPageNumber() * rowByPage ;
        List<NewEntity> news = newsEntityFacade.findByIndex(index, rowByPage);        
        tableToto.setRowList(news);
 
    }
 
    private NewEntityFacadeLocal lookupNewEntityFacade() {
        try {
            Context c = new InitialContext();
            return (NewEntityFacadeLocal) c.lookup("java:comp/env/ejb/NewEntityFacade");
        }
        catch(NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne);
            throw new RuntimeException(ne);
        }
    }
 
    public void onDestroy() {
        newsEntityFacade = null;
    }
 
 
}
J'aimerais utilisé l'injection d'EJB :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
/*
 * Hello.java
 *
 * Created on 11. février 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
 */
public class Hello extends Page {
 
    public Table tableToto = new Table();    
    @EJB private NewEntityFacadeLocal newsEntityFacade;    
    @Resource private InitialContext context;
 
    private int 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);
    }
 
    public void onRender() {        
        index = tableToto.getPageNumber() * rowByPage ;
        List<NewEntity> news = newsEntityFacade.findByIndex(index, rowByPage);        
        tableToto.setRowList(news);
    }
 
 
    public void onDestroy() {
        newsEntityFacade = null;
    }
 
 
}
Mais mon EJB session est nul. Quelqu'un aurait une idée ?