users@glassfish.java.net

Writing a Swing-EJB Client (with Netbeans 6.0)

From: <glassfish_at_javadesktop.org>
Date: Thu, 06 Mar 2008 08:18:42 PST

Hello folks!

I'm want to develop an Swing-based EJB-Client in the easiest possible way. How can I connect to the Session-Beans?

When I use Netbeans "Enterprise Ressources" -> "Call Enterprise Bean" Feature, it generates the following Code:

public class NewJFrame extends javax.swing.JFrame {
    @EJB
    private static AuftragsAbwicklungRemote auftragsAbwicklungBean;
....


The Main-Class is quite straight-forwarded:

package pi_praktikum1;
import javax.swing.JFrame;

public class Main {

    public static void main(String[] args) {
        
        JFrame gui = new NewJFrame();
        gui.setVisible(Boolean.TRUE);
    }
}


When I try to use the Session-Bean (even by starting the program with Webstart) I get an Null-Pointer Exception.

so my work-around is to develop a separate class, to access the Bean:

public class TestClass {
    public AuftragsAbwicklungRemote lookupAuftragsAbwicklungBean() {
        try {
            Context c = new InitialContext();
            return (AuftragsAbwicklungRemote) c.lookup("java:comp/env/AuftragsAbwicklungBean");
        } catch (NamingException ne) {
            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

}

My Question is: "Is there a simpler way (directly from the NewJFrame-Class)"
and: "Why doesnt Dependency Injection work?"

I would be happy if someone could help me.

Greetings,
Jan
[Message sent by forum member 'janmueller' (janmueller)]

http://forums.java.net/jive/thread.jspa?messageID=262666