users@glassfish.java.net

Re: How to invoke Client Callback Handler from EJB3 Session Bean

From: <glassfish_at_javadesktop.org>
Date: Thu, 08 May 2008 15:23:13 PDT

In traditional Java EE applications the client side initiates the actions and passes arguments to the server. What comes back is a return value as with any normal Java method invocation. Servers do not call clients.

Because the server side does not call the client side but merely returns to it, there is (again, in the traditional model) no idea of "passing arguments" from the server to the client.

I'll try to "draw" the difference between your original idea and my suggestion. I'm sure the spacing will look bad but I think you will get the idea

Your idea:

Client EJB
  --- call methodM ------- >

  <---- nested callback ------

[app client displays a dialog to get the additional info from the user]

  --- return from nested callback -->

  <--- return from first call --


In your idea, the "nested callback" would pass arguments that tell what added info to get from the user and the "return from nested callback" would return a single object as its return value that contains the added information the user supplied.

As I mentioned earlier the "nested callback" and "return from nested callback" are basically not a supported model in Java EE; servers cannot call clients.

Even in the approach you described, there are two parts to the EJB method: the part that runs before the (unsupported) nested call back to the client, and the part that runs after.

My suggestion is to do divide the EJB methodM into two separate methods, methodA and methodB.

Client EJB
  --- call methodA ----------------------->

  <--- return

[ client displays a dialog to collect the new required information from the user ]

  ---- call methodB ----------------------->

  <--- return ----------------------------------

In this approach the EJB's methodA returns a value is an object that indicates what further information is needed from the user. The app client uses that to display a dialog, collecting the required information. Then the app client invokes methodB on the EJB, passing the new information it just collected from the user.

I know this is not the approach you first had in mind, but I think it will meet your needs while also fitting the Java EE model in which the client calls the server and not the other way around.
[Message sent by forum member 'tjquinn' (tjquinn)]

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