ejb@glassfish.java.net

RE: EJB3 injection in Glassfish

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Mon, 19 Oct 2009 15:40:17 +0100

Moha

 

 

I didn't released you was using JSP.

 

eve
 


Date: Mon, 19 Oct 2009 09:27:23 -0500
From: Timothy.Quinn_at_Sun.COM
To: ejb_at_glassfish.dev.java.net
Subject: Re: EJB3 injection in Glassfish

Static declarations will be injected only in a true Java EE application client, launched using the GlassFish appclient command (or using the built-in Java Web Start support for launching app clients).

JSPs are not application clients as defined in the Java EE spec. You'll want to inject an instance field for it to work in a JSP.

- Tim

Mohanapriyanka_Dasari wrote:




Hi Eve,
 
this is how my EJB3 app looks :
 
Interface:
 
@Remote
public interface Hello{
public String sayHello(String name);
}

 

Implementation class:(Stateless Session Bean)

 

@Stateless
public class HelloBean implements Hello
{
public String sayHello(String name){
System.out.println("Hello"+name);
return "Hello!!!";
}
}

 

In the AppClient(JSP)

 

<%!
@EJB
private static Hello hello = null;
public Hello getHello(){
return hello;
}
%>
<%
hello.sayHello("XYZ");
%>

 

result:Null Pointer Exception..

 

is there anything i missed out?


From: Eve Pokua [gorgeous65_at_msn.com]
Sent: Monday, October 19, 2009 6:53 PM
To: ejb glassfish
Subject: RE: EJB3 injection in Glassfish



Mohana,
 
Sorry correction -
 
3. hello.sayHello("xyz");

>
 
 
IT is supposed to be something like this -
 
Main.getHello().sayHello("xyz");

 
YOu call the static method by using Main as above.
 
I imagine you have a method similar -
 
sayHello(String s)
 
in your interface class Hello?
 
eve




 

From: gorgeous65_at_msn.com
To: ejb_at_glassfish.dev.java.net
Date: Mon, 19 Oct 2009 10:13:19 +0100
Subject: RE: EJB3 injection in Glassfish




 



From: Mohanapriyanka_Dasari_at_mahindrasatyam.net
To: ejb_at_glassfish.dev.java.net
Date: Mon, 19 Oct 2009 13:40:52 +0530
Subject: EJB3 injection in Glassfish

<




Hi Eve,
 
I followed the steps mentioned in the provided thread:
 
1. @EJB
private static Hello hello;

2.static Hello getHello() {
    return hello;
   }

3. hello.sayHello("xyz");
>
 
 
Try this:
Main.getHello("xyz");
 
eve



it did not work.. it showed null pointer exception..
 
Regards,
Priyanka.


From: Eve Pokua [gorgeous65_at_msn.com]
Sent: Friday, October 16, 2009 8:31 PM
To: ejb glassfish
Subject: RE: EJB3 worked in Glassfish


Mohanna,
 
Take a look at this thread. I Had years of problems with injections and
it took me ages to get people to understand the problem I was experiencing.
 
Date: Mon, 13 Oct 2008 16:26:56 -0500
From: Timothy.Quinn_at_Sun.COM
To: ejb_at_glassfish.dev.java.net
CC: persistence_at_glassfish.dev.java.net
Subject: Re: injections

Eve,

It's important to note that the Java EE 5 spec specifies that injection take place only in "managed" classes. In the app client, there are only two managed classes: the main class (as specified either in the manifest or on the appclient command line) and the optional log-in callback class.

Also, the spec also mandates that in the app client main class only static elements can be injected.

Here is one general approach that some people find works for them:

1. Define the injected static fields on the app client's main class:

@EJB
private static UsersRemote usersRemote;

2. Write a static accessor method on the app client's main class:
static UserRemote getUserRemote() {
    return usersRemote;
}

3. From anywhere in any of the classes in your app client use Main.getUserRemote() when you need to use the EJB.

- Tim

Eve Pokua wrote:





Hello Ian/Everyone,
 
Yes,
 
I have carried out a lot more testing and found that this seems to work
on the first main class or any class that is run with appclient. Any other class
that I call from the main class, results as NullPointer when I try to insert. E.g:
 
If I try insert data of the same bean from the main class, I get the following:
 
C:\jee\STOCKINFOR2>appclient -client STOCKINFOR2-app-client.jar
successfully recorded new Department details
 
However, if I call the class from the main class, then I get the following:
 
C:\jee\STOCKINFOR2>appclient -client STOCKINFOR2-app-client.jar
Caught an Exception: can not insert new Department details
java.lang.NullPointerException
        at stockinfor2.NewDepartclient.saveNewDeptdetails(NewDepartclient.java:1
22)
        at stockinfor2.NewDepartclient.newdepatbutActionPerformed(NewDepartclien
t.java:113)

So I guess, I have to use just one JFrame client and use containers such as panels and so forth, to separate this.
Or I have to use lookups - Context.
 
This' now the limitation with server side JEE combined with Client side programming.
 
Thanks for your help.
 
eve







> Date: Thu, 2 Oct 2008 14:06:29 -0700
> From: Ian.Evans_at_Sun.COM
> To: ejb_at_glassfish.dev.java.net
> CC: persistence_at_glassfish.dev.java.net
> Subject: Re: injections
>
> Eve Pokua wrote:
> > I followed your advice and created a whole new application. Took a copy
> > of the tutorial client:
> >
> > package newapplication;
> > import javax.ejb.EJB;
> > import machinedetails2.*;
> > /**
> > *
> > * @author Administrator
> > */
> > public class Main {
> >
> > @EJB
> > private static UsersRemote usersRemote;
> > public Main(String[] args) {
> > }
> > /**
> > * @param args the command line arguments
> > */
> > public static void main(String[] args) {
> > Main client = new Main(args);
> > client.doTest();
> > }
> >
> > public void doTest() {
> > try {
> > usersRemote.createUser("t7","testing7","null","null");
> > System.out.println("successfull");
> >
> > } catch (Exception ex) {
> > System.err.println("Caught a Exception: not working ");
> >
> > ex.printStackTrace();
> > //System.exit(0);
> > }
> > }
> > }
> >
> >
> >
> > amended it, tested it on my application and for the first time in
> > a hundred years it works.
> >
> > So, sorry everyone, it was all my mistake trying to mix swing user interface
> > with JEE 5 injection. I also took a look at the dukesbank application
> > and got
> > confuse with the BankAdmin.java swing application. Thought I could do it.
>
> You can use injection in Swing apps provided the application is run via
> the application client container (appclient in GlassFish). It's possible
> that problem you had with your original Swing app was your use of an
> injected resource in your nested class. Or you may not have instantiated
> the inner class before calling actionPerformed().
>
> In general, it's easier to test your server application with a simple
> console test client, as you did above, before coding the GUI application.
>
> > Thanking you all for your patience and excuse me if I offended anyone.
>
> No offense at all. Glad you got through one tough patch to getting your
> app running.
>
> -ian
> --
> Ian Evans
> ian dot evans at sun dot com
> Java EE technical documentation
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>
 
I am not sure if this is addressed in glassfish v3 though.
 
eve

 


From: Mohanapriyanka_Dasari_at_mahindrasatyam.net
To: ejb_at_glassfish.dev.java.net
Date: Fri, 16 Oct 2009 20:19:11 +0530
Subject: RE: EJB3 worked in Glassfish




Tried with Injections(@EJB in client) when i wanted to try the EJB3 first application in Glassfish.
It did not work.
 


From: Eve Pokua [gorgeous65_at_msn.com]
Sent: Friday, October 16, 2009 8:01 PM
To: ejb glassfish
Subject: RE: EJB3 worked in Glassfish


Or you could just use injections.
 
eve
 


From: Mohanapriyanka_Dasari_at_mahindrasatyam.net
To: ejb_at_glassfish.dev.java.net
Date: Fri, 16 Oct 2009 19:36:12 +0530
Subject: EJB3 worked in Glassfish




 
Hi
 
It worked for me when i changed code like this:
 
@Stateless(mappedName="HelloBeanJNDI")
public class HelloBean implements Hello
{
 
 
and creating instance for Remote interface like this in JSP
hello = (Hello) ic.lookup("HelloBeanJNDI");
 
Thank you.
 
Priyanka


DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.



Use Windows Live Messenger for free on selected mobiles. Learn more.


DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.



Chat to your friends for free on selected mobiles. Learn more.


DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.



Chat to your friends for free on selected mobiles. Learn more.


Use Windows Live Messenger for free on selected mobiles. Learn more.


DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.

                                               
_________________________________________________________________
Download Messenger onto your mobile for free
http://clk.atdmt.com/UKM/go/174426567/direct/01/
--_37a4563a-5850-42b4-b5b7-ca9ca78f07ff_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Moha<BR>
&nbsp;<BR>
&nbsp;<BR>
I didn't released you was using JSP.<BR>
&nbsp;<BR>
eve<BR>&nbsp;<BR>
<HR id=stopSpelling>
Date: Mon, 19 Oct 2009 09:27:23 -0500<BR>From: Timothy.Quinn_at_Sun.COM<BR>To: ejb_at_glassfish.dev.java.net<BR>Subject: Re: EJB3 injection in Glassfish<BR><BR>Static declarations will be injected only in a true Java EE application client, launched using the GlassFish appclient command (or using the built-in Java Web Start support for launching app clients).<BR><BR>JSPs are not application clients as defined in the Java EE spec.&nbsp; You'll want to inject an instance field for it to work in a JSP.<BR><BR>- Tim<BR><BR>Mohanapriyanka_Dasari wrote:
<BLOCKQUOTE cite=mid:0189C8F1557A5E48AA095E365AE5A22C0412EAEB85_at_hstmbx002.corp.satyam.ad>
<STYLE>
.ExternalClass .ecxhmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.ecxhmmessage
{font-size:10pt;font-family:Verdana;}
</STYLE>

<DIV dir=ltr><FONT color=#000000 size=2 face=Tahoma><FONT color=#646464 size=2><FONT color=#646464 size=2>
<P align=left>Hi Eve,</P>
<P align=left>&nbsp;</P>
<P align=left><FONT face=tahoma>this is how my EJB3 app looks :</FONT></P>
<P align=left>&nbsp;</P>
<P align=left><FONT face=tahoma>Interface:</FONT></P>
<P align=left>&nbsp;</P>
<P align=left>@Remote</P></FONT></FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2></FONT></FONT></B></FONT>
<P align=left><FONT color=#000000 size=2 face=Tahoma><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>public</FONT></FONT></B><FONT size=2> </FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>interface</FONT></FONT></B><FONT size=2> Hello{</FONT></FONT></P><FONT color=#000000 size=2 face=Tahoma><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2></FONT></FONT></B></FONT>
<P align=left><FONT color=#000000 size=2 face=Tahoma><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>public</FONT></FONT></B><FONT size=2> String sayHello(String name);</FONT></FONT></P>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2>}</FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2>&nbsp;</FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT face=tahoma>Implementation class:(Stateless Session Bean)</FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2>&nbsp;</FONT></FONT><BR><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT color=#646464 size=2><FONT color=#646464 size=2>
<P align=left>@Stateless</P></FONT></FONT><FONT size=2></FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2></FONT></FONT></B></FONT></FONT>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>public</FONT></FONT></B><FONT size=2> </FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>class</FONT></FONT></B><FONT size=2> HelloBean </FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>implements</FONT></FONT></B><FONT size=2> Hello</FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2>{</FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>public</FONT></FONT></B><FONT size=2> String sayHello(String name){</FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2>System.</FONT><I><FONT color=#0000c0 size=2><FONT color=#0000c0 size=2>out</FONT></FONT></I><FONT size=2>.println(</FONT><FONT color=#2a00ff size=2><FONT color=#2a00ff size=2>"Hello"</FONT></FONT><FONT size=2>+name);</FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>return</FONT></FONT></B><FONT size=2> </FONT><FONT color=#2a00ff size=2><FONT color=#2a00ff size=2>"Hello!!!"</FONT></FONT><FONT size=2>;</FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2>}</FONT></FONT></FONT></P>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2>}</FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2>&nbsp;</FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT face=tahoma>In the AppClient(JSP)</FONT></FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2>&nbsp;</FONT></FONT></FONT><BR><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2></FONT></FONT></FONT></FONT></FONT></FONT>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2>&lt;%!</FONT></FONT><FONT size=2> </FONT></FONT></FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT size=2>@EJB</FONT></FONT></FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>private</FONT></FONT></B><FONT size=2> </FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>static</FONT></FONT></B><FONT size=2> Hello hello = </FONT><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>null</FONT></FONT></B><FONT size=2>; </FONT></FONT></FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>public</FONT></FONT></B><FONT size=2> Hello getHello(){</FONT></FONT></FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><B><FONT color=#7f0055 size=2><FONT color=#7f0055 size=2>return</FONT></FONT></B><FONT size=2> hello;</FONT></FONT></FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT size=2>}</FONT></FONT></FONT></FONT></FONT></P>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2>%&gt;</FONT></FONT></FONT></FONT></FONT></FONT></P><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT size=2></FONT><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2>
<P align=left>&lt;%</P></FONT></FONT><FONT size=2></FONT></FONT></FONT></FONT></FONT>
<P align=left><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT size=2>hello.sayHello(</FONT><FONT color=#2a00ff size=2><FONT color=#2a00ff size=2>"XYZ"</FONT></FONT><FONT size=2>);</FONT></FONT></FONT></FONT></FONT></P><FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2></FONT></FONT></FONT></FONT></FONT></FONT>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2>%&gt;</FONT></FONT></FONT></FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2>&nbsp;</FONT></FONT></FONT></FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2><FONT face=tahoma>result:Null Pointer Exception.. </FONT></FONT></FONT></FONT></FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2>&nbsp;</FONT></FONT></FONT></FONT></FONT></FONT><BR>
<FONT color=#000000 size=2 face=Tahoma><FONT size=2><FONT size=2><FONT size=2><FONT color=#bf5f3f size=2><FONT color=#bf5f3f size=2><FONT face=tahoma>is there anything i missed out?</FONT></FONT></FONT></FONT></FONT></FONT></FONT><BR>
<HR>
<FONT size=2 face=Tahoma><B>From:</B> Eve Pokua [<A class=ecxmoz-txt-link-abbreviated href="mailto:gorgeous65_at_msn.com">gorgeous65_at_msn.com</A>]<BR><B>Sent:</B> Monday, October 19, 2009 6:53 PM<BR><B>To:</B> ejb glassfish<BR><B>Subject:</B> RE: EJB3 injection in Glassfish<BR></FONT><BR></DIV>
<DIV><BR>Mohana,<BR>&nbsp;<BR>Sorry correction -<BR>&nbsp;<BR>3. hello.sayHello("xyz");<BR>
<DIV dir=ltr>&gt;</DIV><SPAN lang=EN>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>IT is supposed to be something like this -</P>
<P dir=ltr>&nbsp;</P></SPAN><BR>Main.getHello().sayHello("xyz");<BR>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>YOu call&nbsp;the static method by using Main as above. </P>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>I imagine you have a method&nbsp; similar -</P>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>sayHello(String s) </P>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>in your interface class Hello?</P>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>eve<BR></P>
<DIV dir=ltr><BR><BR><BR>&nbsp;</DIV>
<HR id=ecxstopSpelling>
From: <A class=ecxmoz-txt-link-abbreviated href="mailto:gorgeous65_at_msn.com">gorgeous65_at_msn.com</A><BR>To: <A class=ecxmoz-txt-link-abbreviated href="mailto:ejb_at_glassfish.dev.java.net">ejb_at_glassfish.dev.java.net</A><BR>Date: Mon, 19 Oct 2009 10:13:19 +0100<BR>Subject: RE: EJB3 injection in Glassfish<BR><BR>
<STYLE>
.ExternalClass .ecxhmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.ecxhmmessage
{font-size:10pt;font-family:Verdana;}
</STYLE>
<BR>&nbsp;<BR>
<HR id=ecxecxstopSpelling>
<BR>From: <A class=ecxmoz-txt-link-abbreviated href="mailto:Mohanapriyanka_Dasari_at_mahindrasatyam.net">Mohanapriyanka_Dasari_at_mahindrasatyam.net</A><BR>To: <A class=ecxmoz-txt-link-abbreviated href="mailto:ejb_at_glassfish.dev.java.net">ejb_at_glassfish.dev.java.net</A><BR>Date: Mon, 19 Oct 2009 13:40:52 +0530<BR>Subject: EJB3 injection in Glassfish<BR><BR>&lt;<BR><BR>
<STYLE>
.ExternalClass .ecxhmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.ecxhmmessage
{font-size:10pt;font-family:Verdana;}
</STYLE>

<DIV dir=ltr><FONT color=#000000 size=2 face=Tahoma>Hi Eve,</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT face=tahoma>I followed the steps mentioned in the provided thread:</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr>1. @EJB<BR>private static&nbsp;Hello hello;<BR><BR>2.static&nbsp;Hello getHello() {<BR>&nbsp;&nbsp;&nbsp; return hello;<BR>&nbsp;&nbsp; }<BR><BR>3. hello.sayHello("xyz");</DIV>
<DIV dir=ltr>&gt;</DIV><SPAN lang=EN>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>&nbsp;</P>
<P dir=ltr>Try this:</P></SPAN>&nbsp;<BR>Main.getHello("xyz");<BR>&nbsp;<BR>eve<BR>
<DIV dir=ltr><BR><BR>it did not work.. it showed null pointer exception..</DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT face=verdana>Regards,</FONT></DIV>
<DIV dir=ltr><FONT face=verdana>Priyanka.</FONT></DIV>
<DIV style="DIRECTION: ltr" id=ecxecxecxdivRpF886>
<HR>
<FONT size=2 face=Tahoma><B>From:</B> Eve Pokua [<A class=ecxmoz-txt-link-abbreviated href="mailto:gorgeous65_at_msn.com">gorgeous65_at_msn.com</A>]<BR><B>Sent:</B> Friday, October 16, 2009 8:31 PM<BR><B>To:</B> ejb glassfish<BR><B>Subject:</B> RE: EJB3 worked in Glassfish<BR></FONT><BR></DIV>
<DIV>Mohanna,<BR>&nbsp;<BR>Take a look at this thread.&nbsp;&nbsp;I Had&nbsp;years of problems with&nbsp;injections&nbsp;and<BR>it took me ages to&nbsp;get&nbsp;people to understand the problem I was experiencing.<BR>&nbsp;<BR>Date: Mon, 13 Oct 2008 16:26:56 -0500<BR>From: <A class=ecxmoz-txt-link-abbreviated href="mailto:Timothy.Quinn_at_Sun.COM">Timothy.Quinn_at_Sun.COM</A><BR>To: <A class=ecxmoz-txt-link-abbreviated href="mailto:ejb_at_glassfish.dev.java.net">ejb_at_glassfish.dev.java.net</A><BR>CC: <A class=ecxmoz-txt-link-abbreviated href="mailto:persistence_at_glassfish.dev.java.net">persistence_at_glassfish.dev.java.net</A><BR>Subject: Re: injections<BR><BR>Eve,<BR><BR>It's important to note that the Java EE 5 spec specifies that injection take place only in "managed" classes.&nbsp; In the app client, there are only two managed classes:&nbsp; the main class (as specified either in the manifest or on the appclient command line) and the optional log-in callback class.<BR><BR>Also, the spec also mandates that in the app client main class only static elements can be injected.&nbsp; <BR><BR>Here is one general approach that some people find works for them:<BR><BR>1. Define the injected static fields on the app client's main class:<BR><BR>@EJB<BR>private static UsersRemote usersRemote;<BR><BR>2. Write a static accessor method on the app client's main class:<BR>static UserRemote getUserRemote() {<BR>&nbsp;&nbsp;&nbsp; return usersRemote;<BR>}<BR><BR>3. From anywhere in any of the classes in your app client use Main.getUserRemote() when you need to use the EJB.<BR><BR>- Tim<BR><BR>Eve Pokua wrote: <BR><BR>
<BLOCKQUOTE>
<STYLE>
.ExternalClass .EC_hmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.EC_hmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>
<BR>Hello Ian/Everyone,<BR>&nbsp;<BR>Yes,<BR>&nbsp;<BR>I have carried out a lot more testing and found that this seems to work<BR>on the first main class or any class that is run with appclient.&nbsp; Any other class<BR>that I call from the main class, results as NullPointer when I try to insert. E.g:<BR>&nbsp;<BR>If I try insert data of the same bean from the main class, I get the following:<BR>&nbsp;<BR>C:\jee\STOCKINFOR2&gt;appclient -client STOCKINFOR2-app-client.jar<BR>successfully recorded new Department details<BR>&nbsp;<BR>However, if I call the class from the main class, then I get the following:<BR>&nbsp;<BR>C:\jee\STOCKINFOR2&gt;appclient -client STOCKINFOR2-app-client.jar<BR>Caught an Exception: can not insert new Department details<BR>java.lang.NullPointerException<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at stockinfor2.NewDepartclient.saveNewDeptdetails(NewDepartclient.java:1<BR>22)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at stockinfor2.NewDepartclient.newdepatbutActionPerformed(NewDepartclien<BR>t.java:113)<BR><BR>So I guess, I have to use just one JFrame client and use containers such as panels and so forth, to separate this.<BR>Or I have to use lookups - Context.<BR>&nbsp;<BR>This' now the limitation with server side JEE combined with Client side programming.<BR>&nbsp;<BR>Thanks for your help.<BR>&nbsp;<BR>eve<BR><BR><BR><BR>
<HR id=ecxecxecxecxEC_stopSpelling>
<BR><BR>&gt; Date: Thu, 2 Oct 2008 14:06:29 -0700<BR>&gt; From: <A class=ecxecxecxecxEC_moz-txt-link-abbreviated href="mailto:Ian.Evans_at_Sun.COM"><FONT color=#0068cf>Ian.Evans_at_Sun.COM</FONT></A><BR>&gt; To: <A class=ecxecxecxecxEC_moz-txt-link-abbreviated href="mailto:ejb_at_glassfish.dev.java.net"><FONT color=#0068cf>ejb_at_glassfish.dev.java.net</FONT></A><BR>&gt; CC: <A class=ecxecxecxecxEC_moz-txt-link-abbreviated href="mailto:persistence_at_glassfish.dev.java.net"><FONT color=#0068cf>persistence_at_glassfish.dev.java.net</FONT></A><BR>&gt; Subject: Re: injections<BR>&gt; <BR>&gt; Eve Pokua wrote:<BR>&gt; &gt; I followed your advice and created a whole new application. Took a copy <BR>&gt; &gt; of the tutorial client:<BR>&gt; &gt; <BR>&gt; &gt; package newapplication;<BR>&gt; &gt; import javax.ejb.EJB;<BR>&gt; &gt; import machinedetails2.*;<BR>&gt; &gt; /**<BR>&gt; &gt; *<BR>&gt; &gt; * @author Administrator<BR>&gt; &gt; */<BR>&gt; &gt; public class Main {<BR>&gt; &gt; <BR>&gt; &gt; @EJB<BR>&gt; &gt; private static UsersRemote usersRemote;<BR>&gt; &gt; public Main(String[] args) {<BR>&gt; &gt; }<BR>&gt; &gt; /**<BR>&gt; &gt; * @param args the command line arguments<BR>&gt; &gt; */<BR>&gt; &gt; public static void main(String[] args) {<BR>&gt; &gt; Main client = new Main(args);<BR>&gt; &gt; client.doTest();<BR>&gt; &gt; }<BR>&gt; &gt; <BR>&gt; &gt; public void doTest() {<BR>&gt; &gt; try {<BR>&gt; &gt; usersRemote.createUser("t7","testing7","null","null");<BR>&gt; &gt; System.out.println("successfull");<BR>&gt; &gt; <BR>&gt; &gt; } catch (Exception ex) {<BR>&gt; &gt; System.err.println("Caught a Exception: not working ");<BR>&gt; &gt; <BR>&gt; &gt; ex.printStackTrace();<BR>&gt; &gt; //System.exit(0);<BR>&gt; &gt; }<BR>&gt; &gt; }<BR>&gt; &gt; }<BR>&gt; &gt; <BR>&gt; &gt; <BR>&gt; &gt; <BR>&gt; &gt; amended it, tested it on my application and for the first time in<BR>&gt; &gt; a hundred years it works. <BR>&gt; &gt; <BR>&gt; &gt; So, sorry everyone, it was all my mistake trying to mix swing user interface<BR>&gt; &gt; with JEE 5 injection. I also took a look at the dukesbank application <BR>&gt; &gt; and got<BR>&gt; &gt; confuse with the BankAdmin.java swing application. Thought I could do it. <BR>&gt; <BR>&gt; You can use injection in Swing apps provided the application is run via <BR>&gt; the application client container (appclient in GlassFish). It's possible <BR>&gt; that problem you had with your original Swing app was your use of an <BR>&gt; injected resource in your nested class. Or you may not have instantiated <BR>&gt; the inner class before calling actionPerformed().<BR>&gt; <BR>&gt; In general, it's easier to test your server application with a simple <BR>&gt; console test client, as you did above, before coding the GUI application.<BR>&gt; <BR>&gt; &gt; Thanking you all for your patience and excuse me if I offended anyone.<BR>&gt; <BR>&gt; No offense at all. Glad you got through one tough patch to getting your <BR>&gt; app running.<BR>&gt; <BR>&gt; -ian<BR>&gt; -- <BR>&gt; Ian Evans<BR>&gt; ian dot evans at sun dot com<BR>&gt; Java EE technical documentation<BR>&gt; <BR>&gt; ---------------------------------------------------------------------<BR>&gt; To unsubscribe, e-mail: <A class=ecxecxecxecxEC_moz-txt-link-abbreviated href="mailto:ejb-unsubscribe_at_glassfish.dev.java.net"><FONT color=#0068cf>ejb-unsubscribe_at_glassfish.dev.java.net</FONT></A><BR>&gt; For additional commands, e-mail: <A class=ecxecxecxecxEC_moz-txt-link-abbreviated href="mailto:ejb-help_at_glassfish.dev.java.net"><FONT color=#0068cf>ejb-help_at_glassfish.dev.java.net</FONT></A><BR>&gt;&nbsp;<BR>&nbsp;<BR>I am not&nbsp;sure if this is addressed in glassfish v3 though.&nbsp;&nbsp;<BR>&nbsp;<BR>eve<BR><BR>&nbsp;<BR></BLOCKQUOTE>
<HR id=ecxecxecxstopSpelling>
From: <A class=ecxmoz-txt-link-abbreviated href="mailto:Mohanapriyanka_Dasari_at_mahindrasatyam.net">Mohanapriyanka_Dasari_at_mahindrasatyam.net</A><BR>To: <A class=ecxmoz-txt-link-abbreviated href="mailto:ejb_at_glassfish.dev.java.net">ejb_at_glassfish.dev.java.net</A><BR>Date: Fri, 16 Oct 2009 20:19:11 +0530<BR>Subject: RE: EJB3 worked in Glassfish<BR><BR>
<STYLE>
.ExternalClass .ecxhmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.ecxhmmessage
{font-size:10pt;font-family:Verdana;}
</STYLE>

<DIV dir=ltr><FONT color=#000000 size=2 face=Tahoma>Tried with Injections(@EJB in client)&nbsp;when i wanted to try the EJB3&nbsp;first application&nbsp;in Glassfish.</FONT></DIV>
<DIV dir=ltr><FONT face=tahoma>It did not work.</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV style="DIRECTION: ltr" id=ecxecxecxecxdivRpF401890>
<HR>
<FONT size=2 face=Tahoma><B>From:</B> Eve Pokua [<A class=ecxmoz-txt-link-abbreviated href="mailto:gorgeous65_at_msn.com">gorgeous65_at_msn.com</A>]<BR><B>Sent:</B> Friday, October 16, 2009 8:01 PM<BR><B>To:</B> ejb glassfish<BR><B>Subject:</B> RE: EJB3 worked in Glassfish<BR></FONT><BR></DIV>
<DIV>Or you could just use injections.<BR>&nbsp;<BR>eve<BR>&nbsp;<BR>
<HR id=ecxecxecxecxstopSpelling>
From: <A class=ecxmoz-txt-link-abbreviated href="mailto:Mohanapriyanka_Dasari_at_mahindrasatyam.net">Mohanapriyanka_Dasari_at_mahindrasatyam.net</A><BR>To: <A class=ecxmoz-txt-link-abbreviated href="mailto:ejb_at_glassfish.dev.java.net">ejb_at_glassfish.dev.java.net</A><BR>Date: Fri, 16 Oct 2009 19:36:12 +0530<BR>Subject: EJB3 worked in Glassfish<BR><BR>
<STYLE title=owaParaStyle>
.ExternalClass P
{margin-bottom:0px;}
</STYLE>

<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT color=#000000 size=2 face=Tahoma>Hi</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT size=2 face=tahoma>It worked for me when i changed code like this:</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr>@Stateless(mappedName="HelloBeanJNDI") </DIV>
<DIV dir=ltr>public class&nbsp; HelloBean implements Hello<BR>{</DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT size=2 face=tahoma>and creating instance for Remote interface like this in JSP</FONT></DIV>
<DIV dir=ltr><FONT color=#000000 size=2 face=Tahoma>hello = (Hello) ic.lookup("HelloBeanJNDI");</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT size=2 face=tahoma>Thank you.</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV>
<DIV dir=ltr><FONT size=2 face=tahoma>Priyanka</FONT></DIV><BR>
<HR>
<FONT color=navy size=2 face=Arial>DISCLAIMER:<BR>This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.<BR></FONT><BR>
<HR>
Use Windows Live Messenger for free on selected mobiles. <A href="http://clk.atdmt.com/UKM/go/174426567/direct/01/">Learn more.</A> </DIV><BR>
<HR>
<FONT color=navy size=2 face=Arial>DISCLAIMER:<BR>This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.<BR></FONT><BR>
<HR>
Chat to your friends for free on selected mobiles. <A href="http://clk.atdmt.com/UKM/go/174426567/direct/01/">Learn more.</A> </DIV><BR>
<HR>
<FONT color=navy size=2 face=Arial>DISCLAIMER:<BR>This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.<BR></FONT><BR>
<HR>
Chat to your friends for free on selected mobiles. <A href="http://clk.atdmt.com/UKM/go/174426567/direct/01/">Learn more.</A> <BR>
<HR>
Use Windows Live Messenger for free on selected mobiles. <A href="http://clk.atdmt.com/UKM/go/174426567/direct/01/">Learn more.</A> </DIV><BR>
<HR>
<FONT color=navy size=2 face=Arial>DISCLAIMER:<BR>This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.<BR></FONT></BLOCKQUOTE><BR> <br /><hr />Download Messenger onto your mobile for free. <a href='http://clk.atdmt.com/UKM/go/174426567/direct/01/' target='_new'>Learn more.</a></body>
</html>
--_37a4563a-5850-42b4-b5b7-ca9ca78f07ff_--