adding functionality to weld-translator
asookazian Apr 23, 2010 10:57 PMI successfully added raise event/observe event functionality to the weld-translator example. IMO, that example, and perhaps the others as well, are too simplistic and needs to be beefed up
.
public void translate() { translatedText = translator.translate(inputText); documentEvent.fire(document); }
public class MyObserverBean { public void onAnyDocumentEvent(@Observes Document document) { System.out.println("observing event now!"); } public void afterDocumentUpdate(@Observes @Updated Document document) { System.out.println("afterDocumentUpdate event now!"); } }
NOTE: afterDocumentUpdate() does not get invoked, not sure why...
@Named("document") public class Document implements Serializable { private static final long serialVersionUID = -923116208546353275L; private String name = "myDoc1"; private String id = "1234"; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } }
I noticed that JBoss/Weld throws an exception if the Document class does not implement Serializable b/c it is being @Injected into the TranslatorControllerBean SFSB which is by definition serializable due to passivation/activation of SFSB in ejb container. It would be nice if JBoss automatically adjusted and hot reloaded the class as impelements Serializable but whatever, no big deal. Anyways, the source code would have to be modified behind the back of the developer which is probably not a good thing.
Perhaps adding some JPA 2.0 data access functionality to the weld-translator would be nice as well. Any examples anywhere on how to do simple entityManager.createQuery() using JPA 2.0. I'm wondering if the new spec requires any new changes to the persistence.xml, etc.
AFAIK there are no JPA 2.0 examples in the distro (what about Seam 3?) Something simple using hsqldb would be good...