[jboss-user] [JBoss Seam] - Re: Avoiding the DRY Principle with beans
iradix
do-not-reply at jboss.com
Wed Jul 12 16:27:08 EDT 2006
If you're concerned about typing, throw some generics in there.
public abstract class PersistentBean<T> implements Serializable, PersistentLocal {
|
| @PersistenceContext(unitName="hrsystem",
| type=PersistenceContextType.EXTENDED)
| private EntityManager entityManager;
|
| public abstract void setObject(T object);
|
| public abstract T getObject();
|
| public String update() {
| entityManager.merge(getObject());
| return "Success";
| }
|
| public String create() {
| entityManager.persist(getObject());
| return "Success";
| }
|
| public String delete() {
| entityManager.remove(getObject());
| return "Success";
| }
| }
@Stateful
| @Name(value="employeeBean")
| public class EmployeeBean extends PersistentBean<Employee> {
|
| public EmployeeBean() {
| }
|
| @In(create = true) @Out
| private Employee object;
|
| public void setObject(Employee object) {
| this.object = object;
| }
|
| public Employee getObject() {
| return object;
| }
|
| }
Should work. Pretty cool huh? Now not only will your outjected object work in your jsf pages, any other methods you add in your subclass will have the correct type to work with.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957520#3957520
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957520
More information about the jboss-user
mailing list