• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

EJB3 and Domain-GUI binding

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Pieter-Jan Malfait
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic