• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Communication between a EJB and its container

 
Dave Elwood
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a desktop app BigForm which has a member JPanel object with special talents
The talented JPanel is an EJB project named MyPanel.

(I'm working with NetBeans).

Now I'd like the MyPanel to send events to the container BigForm, however
MyPanel doesn't see the package of BigForm.

BigForm sees the package of MyPanel, but not the other way around.

Is the following a good way to avoit mucking about with events ??? :
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

I don't know what this has to do with EJBs, or what you mean by that final question -- but I can tell you that the "new Widget(this)" pattern you're using is common and a good way to do things. Telling an object you create "here is how to get back to me" is a good idea.
 
Dave Elwood
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, the code is not !! that of the desktop app with the EJB MyPanel. No, the code shows what I wondered could be a way out.

Actually I expected you people to say that passing a "this" to a member constructor would be really bad, recursive chaos and things like that, but your answer rested my fears.

Many Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can pass a this reference into something inside the class in your constructor. That panel is a field of the class, so it is "inside". Now, letting a this reference get outside the class from inside the constructor, that is something altogether different.

Don't Swing components have a getParent() method, and automatically record their parent component? Or have I misunderstood the problem?
 
Dave Elwood
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a getParent() function? Excuse me, I fell off my chair.

Very interesting. I have some testing to do now.

P.S. the "this" won't only be outside the class,
it will be outside the BigForm project and transferred to another project, the EJB MyPanel project. !!!
 
Dave Elwood
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well guys, getParent() doesn't work

I've got two projects...BigForm and the EJB MyPanel,
these are two different classes,
in two different packages,
in two different projects.

in MyPanel I tried to use the getParent() to call the signal() function way back in BigForm.

The call looked like this :


in the MyPanel class, the pkBigForm package is not visible !!!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might need to import that class into the panel class. Have you checked the return type of getParent()? It might not be the right return type.

If it doesn't work, it doesn't work. If the method works, so much the better, if it doesn't, you have learned something useful for future reference.
 
Dave Elwood
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

>>You might need to import that class into the panel class.

Tried that. Didn't work. The panel can't see the BigForm class.

>>Have you checked the return type of getParent()?

Yes, it's Object. And casting it to BigForm doesn't work because
BigForm is not visible to the panel class, as I said.

>>If it doesn't work, it doesn't work.

Thanks a lot.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the return type of Component#getParent is Container. You can add only a few Listeners to a Container.
Dave Elwood wrote: . . . >>If it doesn't work, it doesn't work.

Thanks a lot.
I didn't mean it like that!

Maybe you should have some sort of class which incorporates the connection, and add both the EJB and the container to it.
Or create a Mouse Listener which takes a click ffrom the container and calls a method in the EJB

Can't think of anything else to suggest. Sorry. Anybody else?
 
Dave Elwood
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AAAARRRRGGGHHHH

I've got it.

Events : the wrong way :

1. in BigForm call

2. the Panel has a javax.swing.event.EventListenerList to hold it in. Not in BigForm, but in Panel. Very strange.

3. the Panel creates a BurpEvent object and calls processBurps() with it. Again in the dumbest place possible,
in the event source object, Panel.

4. processBurps() picks out the MyBurpListener object and calls the BurpOccured() member.

Problem : I want things to happen in BigForm, not in MyBurpListener. I'm forced to put MyBurpListener in the Panel project
area so as a result BigForm in inaccessible to MyBurpListener. Why there? Because it's the only place to
put MyBurpListener so that both the Panel project and the BigForm project have access to it.

Solution : Anonymous Inner Class

Events : the right way :

1. in BigForm call


2. - 4. as above

 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic