3 Replies Latest reply on Nov 25, 2009 6:21 PM by Francisco Jose Peredo Noguez

    It is working!: DWR integrated with Weld

    Francisco Jose Peredo Noguez Master

      I now have (as part of my mini Solder framework) an example of integration between DWR and Weld! (And of course reusable classes to make it easy for you to integrate DWR in your Weld project).


      All you have to do is mark you class with the @DwrBean annotation (@RemoteProxy and @RemoteMethod come with DWR):


      @DwrBean
      @Named
      @RemoteProxy
      class Hello
      {
          @RemoteMethod
          def sayHello(name:String)=
          {
              "Hello, " + name;
          }   
      }
      
      



      Add the Solder DWR servlet to web.xml:


      <servlet>
          <display-name>DWR Servlet</display-name>
          <servlet-name>dwr-invoker</servlet-name>    
          <servlet-class>com.googlecode.solder.dwr.DwrServlet</servlet-class>
          <init-param>
              <param-name>debug</param-name>
              <param-value>true</param-value>
          </init-param>
           </servlet>
           <servlet-mapping>
               <servlet-name>dwr-invoker</servlet-name>
               <url-pattern>/dwr/*</url-pattern>
           </servlet-mapping>
      



      And that is it, there is no need to have a dwr.xml file or manually add the list of the classes you want to expose in web.xml as a parameter for the servlet (as you had to do with Spring).


      This is just a proof of concept, so I do not recommend its use in production (I might remove my @DwrBean annotation and simply expose @Named beans that have the @RemoteProxy annotation). I worked around the Scala bug  by not using any of the functional programming features in my code, even then Scala is a very comfortable language to work with.... but please vote so that it gets fixed and we can all really enjoy Scala with Weld!


      Any proposals on how to integrate conversations and DWR?

        • 1. Re: It is working!: DWR integrated with Weld
          Gavin King Master

          I now have (as part of my mini Solder framework) an example of integration between DWR and Weld!

          Nice :-)



          (And of course reusable classes to make it easy for you to integrate DWR in your Weld project).

          What kind of reusable classes? A PE?



          And that is it, there is no need to have a dwr.xml file or manually add the list of the classes you want to expose in web.xml as a parameter for the servlet (as you had to do with Spring).

          Perfect.



          (I might remove my @DwrBean annotation and simply expose @Named beans that have the @RemoteProxy annotation).

          I think that would be best. I can't think why you would annotate something @RemoteProxy if you didn't want to expose it via DWR.



          I worked around the Scala bug by not using any of the functional programming features in my code, even then Scala is a very comfortable language to work with.... but please vote so that it gets fixed and we can all really enjoy Scala with Weld!

          What language did you implement this DWR integration in? Scala or Java?


          Do you have any opinion on the pros and cons of DWR vs. Seam remoting?

          • 3. Re: It is working!: DWR integrated with Weld
            Francisco Jose Peredo Noguez Master

            Gavin King wrote on Nov 25, 2009 08:52:


            What kind of reusable classes? A PE?


            All the classes of Solder are currently on a  single .jar, I plan on splitting them (a .jar for Solder-DWR, a .jar for Solder-JSP, etc,etc). When you say a PE, you mean having a class in my project implementing the Extension interface? So far, I have not found a need a need for it (but I do use the BeanManager a lot)... I guess the need will arise sooner or later...I guess sooner or later I'll have the kind of problems that kind of solution solves...



            I worked around the Scala bug by not using any of the functional programming features in my code, even then Scala is a very comfortable language to work with.... but please vote so that it gets fixed and we can all really enjoy Scala with Weld!

            What language did you implement this DWR integration in? Scala or Java?


            It is... 95% Scala and 5% Java It turns out that if I define annotations in Scala they are not recognized in Java, so I have to implement Annotations and AnnotationLiterals in Java. Hope this limitation gets fixed soon.




            Do you have any opinion on the pros and cons of DWR vs. Seam remoting?



            At first, I did not like Seam remoting because it did not have exception handling. After that was fixed a have not major complains against it any more (It was the Seam feature that was easier to sell inside my organization because its easy configuration). The main advantage of Seam remoting is IMO its support for Conversations and a Javascript API designed to be comfortable for Java Developers (things like Seam.Remoting.Map) and annotation based constraints.


            DWR on the other hand offers a nice autogenerated interactive test page, has support for several reverse ajax strategies, has less third party dependencies (pretty much all you need is the dwr.jar) and it is maintained by a team that nothing else as its ultimate goal (which IMO translates in faster new feature creation and bugfixing than Seam Remoting). Its Javascript API is designed to be confortable for JavaScript coding (POJOS and Maps are (when possible) automatically translated in to Javascript objects, so javascript coding feels more natural).


            I believe they are both really good projects, but I feel more a little inclined to DWR because doing a great remoting framework is their goal... while Seam has many different goals and that makes good remoting support one more thing to do and not the most important thing to do and, again, I think that translates in  faster new feature creation and bugfixing in DWR when compared with Seam Remoting