aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes throw UserInterface GUI via Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "throw UserInterface GUI via Session Bean" Watch "throw UserInterface GUI via Session Bean" New topic
Author

throw UserInterface GUI via Session Bean

Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
dear ranchers...
I have been using EJBs for the past 6 months,
I have come across a situation in my current scenario...
My clients are spread across a wide area network, and thier business requirements oftens change which I can easily change/implement in my session bean etc.

Sometimes thier business requiremets, prompt me to change something in the user interface screen (like adding an extra TextField). So inorder to do that I have to change the client file and redistribute the client file across the whole network (for consistency). Right??

So where is the J2EE moto of develop once run everywhere...?? This is a mighty problem to me.

So here is a solution that came across my mind..
in one method of the session bean I have created an object of a JFrame extended class. the client file only has a main() funtion which makes the SessionObject thru jndi and calls that method... The pseudocode is entered below:

=======================================================
package client;
...
public static void main(String args[]){
...
try{
SessionHome home = getHome();
Session session = home.create();
session.getGUIScreen();
}...
}

package bean;
...
public class SimpleSessionBean implements SessionBean{
...
public void getGUIScreen(){
new myGUIScreen();
}
...
}

public class myGUIScreen extends JFrame{
....
}
===================================================================
Apparently this seems to work quite nicely and the only dubious thing that I encountered was a message of "Applet Started" on the bottom left corner of the screen (however this is an application not an applet).
I can easily change the User GUI and the changes will reflect to everyone.

THE QUESTION: Should this be done?? Is this a good software practice (merging User Interface with business Logic)?? Is there any alternative method for doing this??

Thank YOU!!!
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
its not goog idea creating GUI in session bean as What EJB specification tells
us
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
the appropriate way will be creating the GUI class on the client side and you can instantiate the class from the main method
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
and the code where you are accessing the GUI by getting reference to the SessionBean doesn't have a written type so when then client will run the GUI will be created at server if your code works
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
You are correct...
but that is the problem I am facing...
Suppose I want to add an extra text field in the client code..
will I have to update the client file across all users?
My guess is to use Message Driven Beans for such idiosynchrasies
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
the more appropriate way will be to use RMI
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
that makes sense...
Thanks I will try that...
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well that is one of the reasons for Java WebStart. Basically, when you run your client GUI, it will check on a server if there is a new version and update the client for you.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
exactly!! Make jsdl files on Java Web Start.
anyone happenin to have any good tutorials on that??

Thanks Mark!
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
I second the Java Web Start suggestion. Its pretty easy to cobble up a JNLP file and stick it and the JARs on a web server somewhere. Even better if you can take advantage of jar diffs to speed deployment.

The Java motto "write once, run everyone" doesn't mean you don't still have to deploy your code. It means you don't have to write a windows version, a linux version, a mac version etc.

The problem with your EJB is the "new myGUIScreen()" will run on the server as this class extends JFrame. JFrame (it extends java.awt.Frame) is a heavy weight object and therefore relies on native code to be created - its serialization support (quote from JavaDoc) - "appropriate for short term storage or RMI between applications running the same version of Swing". This may cause problems with different versions of Java installed on Client machines - and you don't have a good way to specific required versions like JWS provides.

In short I think in the long run this will cause far more problems then it will solve and there does exist Java solutions for this exact problem. Have fun!

Looking closer at your code - my guess is that you were testing this with the client and the server on the same machine. What you saw was the JFrame the server created. You never even tried to return the JFrame to the client.
[ September 12, 2006: Message edited by: Tim LeMaster ]
Ashimashi Kabashi
Ranch Hand

Joined: Sep 11, 2006
Posts: 84
Hello all!! Thanks for all your replies!

I have tried working on jnlp files and it seems to working quite nicely!
But... and its not only the client file I need to redistribute its also the client stub jar file....
Any changes in the EJB would require me to send all users the new cliet stub file??
Do we use any uitility like FTP?? to check for any updates on the .jar file and automatically update on the client??
What is the industry standard?
Thanks!!!
[ September 14, 2006: Message edited by: Ashimashi Kabashi ]
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
You can list your jars in the JNLP file. If they have changed they will be updated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: throw UserInterface GUI via Session Bean
 
Similar Threads
Passed Part One with 87%
EJB help, very confused with gui's and JFrames with J2EE
General design question
Simple question about Data Access Component
How can we use JNDI?