Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throw UserInterface GUI via Session Bean

 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its not goog idea creating GUI in session bean as What EJB specification tells
us
 
Rohit Suman
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the more appropriate way will be to use RMI
 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that makes sense...
Thanks I will try that...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly!! Make jsdl files on Java Web Start.
anyone happenin to have any good tutorials on that??

Thanks Mark!
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can list your jars in the JNLP file. If they have changed they will be updated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic