2 Replies Latest reply on Apr 26, 2010 12:27 PM by Pete Muir

    adding functionality to weld-translator

    Arbi Sookazian Master

      I 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);

      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...

      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...

        • 1. Re: adding functionality to weld-translator
          Arbi Sookazian Master

          Good news: I was able to successfully insert a record into a hsqldb table!

          (minor) bad news: I found a potential bug in the jmx-console when I click on type=HotSpotDiagnostic.  I will post that to the JBoss AS forum.

          So I used the pastecode project and examples for the JPA 2 em.persist(code) method call. 

          so now the use case for weld-translator has morphed into the following:

          1) user enter text in h:inputText field
          2) user clicks translate commandButton
          3) event is raised in backing bean's TranslatorControllerBean.translate() method
          4) event is observed in MyObserverBean JavaBean
          5) the persist operation is invoked via codeEAO.addCode(code, true); in MyObserverBean
          6) I check the hsqldb Code table via JBoss JMX console's pasteCode startDatabaseManager.  Voila there is a new record!

          So does this sound jazzier for this particular translator example app or is this new functionality out of scope??  I can submit for review if anyone is interested.  The pastecode was a good idea, btw!

          • 2. Re: adding functionality to weld-translator
            Pete Muir Master

            The aim is that pastecode will replace translator at some point soon. You should talk to Martin Gencur about helping out with that example.