aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 and Domain-GUI binding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB3 and Domain-GUI binding" Watch "EJB3 and Domain-GUI binding" New topic
Author

EJB3 and Domain-GUI binding

Pieter-Jan Malfait
Greenhorn

Joined: Aug 23, 2005
Posts: 26
Hello,

i'm thinking of incorporating a domain-gui binding (based on JGoodies binding) in my Swing GUI to work with my EJB3 objects. Currently i'm using modelToView and viewToModel methods to transfer values from the domain layer to the view layer and back. This approach is getting a bit limited though as i want forms to react on changes it makes, and i think the best way to handle this to propagate the changes from the domain layer.

For this approach i have to equip the domain objects (ie the EJB3 entity beans) setters with firePropertyChange operations. Would this be a good design choice or is it not-done to implement entity beans like this ?

thanks a lot in advance
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Are you thinking of having GUI code in an EJB? If so, then that's not at all good. Remember, an EJB is about business logic, it knows nothing about the client.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Pieter-Jan Malfait
Greenhorn

Joined: Aug 23, 2005
Posts: 26
i'm not thinking of specific GUI code (like building frames, or accessing swing components directly, ...) in my entity beans. I want to let them fire PropertyChangeEvents when a property changes. This is standard behaviour as for a regular JavaBean. For EJBs this was irrelevant before EJB 3.0 as beans couldn't be used outside a container. But now i can use the GUI to edit my EJB3 bean as if it were a regular JavaBean.

But still it feels kinda weird as i thought Entity Beans really were nothing else than a collection of properties without behaviour..
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
You'll need to explain what is meant by property changes. How do these changes fit into an entity bean's life cycle? For instance, the bean will only be available between activation and passivation at the end of a business method (other than remove()).
Pieter-Jan Malfait
Greenhorn

Joined: Aug 23, 2005
Posts: 26
i do the following :
i request a bean throug a method of a session bean (suppose i need a Person with certain id). My session bean has a method :

public Person getPerson(int id) {..}

My business delegate on the client side receives this Person object (which is an Entity Bean (3.0)) so can edit the object with my GUI classes like a normal JavaBean. The best way to make a binding between the GUI classes and the domain object being edited is through events. So when a certain GUI widget (say a JTextField) changes a property of the bean (fe the name of the BirthDate), the bean needs to fire a PropertyChangeEvent so other classes may respond to this (fe by updating the Persons age).

So my setter method in the bean would look like this :

public void setBirthDate(Date date) {
Date oldDate = this.brithdate;
this.birthdate = date;
firePropertyChangeEvent("birthDate",oldDate,date);
}

Is this acceptable in an Entity Bean ?
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I'd only use a PropertyChangeEvent on the GUI. If a change is notified, the relevant bean method can be called to change the DB.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB3 and Domain-GUI binding
 
Similar Threads
Pattern for DOS/console + Entity(ejb3)
implementation strategy for a simple ordering application.
Validation and copying
Architectural Evolution with Entity Beans
Business Objects