Hi Matt,

There has been a discussion started about doing IoC and AOP in der openlaszlo backend recently. The problem is, that javarpc (which is used by webapprpc) tries to find the referenced object in a Map in session context, and creates a new one with Class.forName().newInstance() if there is none. (getServerInstance() in org.openlaszlo.data.JavaDataSource). There should really be a Factory creating new instances and possibly this Factory should be "injectable" so that you can use Spring provided objects here.

The quick work around is to prepopulate said Map with an object of you choice. I've done that in a servlet-filter with the following (ugly) code:

       Map laszloObjects = (Map)session.getAttribute("__lzobj");
       if(laszloObjects == null){
           System.out.println("Creating new Laszlo Session store");
           laszloObjects = new SessionBindingMap();
           session.setAttribute("__lzobj",laszloObjects);
       }
       if(!laszloObjects.containsKey(LASZLOFACADE_NAME)){
           System.out.println("Creating new LaszloFacade");
LaszloFacade facade = (LaszloFacade) context.getBean(LASZLOFACADE_BEANNAME);
           laszloObjects.put(LASZLOFACADE_NAME, facade);
       }

As you can see, this is no production quality code :-) No synchronization, System.out rather than logging.... which is because laszlo "repurposes" log4j programmatically, so that my loggers are lost (It took me quite some time to see that my code got called and laszlo just set the loglevel to INFO :-)

To come back to refactoring Laszlo to utilize IoC and AOP more... we've already agreed, that Spring is the way to go (ant not NanoContainer or EJB3 IoC or what else) and the process got somewhat stuck. The last mail on that subject was from Oliver Steele on the 17th Nov. I would start to work on it, but am uncertain, where to start. So I need advice (and possibly some help :-)!

Ahh yes, and there was a move to ant-1.6.x which I would recommend doing first and Tucker (P T Withington) is still working on migrating Python parts to java, but the latter is indepentent.

We'll see :-)

Cheers, Mika

Matt Raible schrieb:

I spent some time this weekend trying to get Laszlo to load my Spring
ApplicationContext into a page.  I was successful in getting it, but
I'm having trouble grabbing a bean from it, and calling it's methods. Is this possible with Laszlo? Here's what I have so far:


<canvas width="100%" height="500" debug="true">

   <debug x="300" y="20" width="500" height="400"/>

   <webapprpc id="webapp" autoload="true">

       <method event="onload">
           Debug.write('webapp object loaded');
           canvas.buttons.setAttribute('visible', true);
       </method>

       <remotecall name="getAttr" funcname="getAttribute"/>

   </webapprpc>


   <view name="buttons" x="10" y="10" layout="spacing: 5" visible="false">

       <view x="20" layout="spacing: 5">

           <attribute name="myDel" value="null" type="expression"/>

           <method event="oninit">
               this.myDel = new LzDelegate(this, 'handler');
           </method>

           <method name="handler" args="data">
               Debug.write('handler:', data);
           </method>

           <button text="getAttributeNames"
onclick="webapp.getAttributeNames.invoke()"/>

           <button text="getApplicationContext"
onclick="webapp.getAttr.invoke(['interface
org.springframework.web.context.WebApplicationContext.ROOT'])"/>

           <button text="getApplicationContext w/ delegate">
               <method event="onclick">
                   webapp.getAttr.invoke(['interface
org.springframework.web.context.WebApplicationContext.ROOT'],
parent.myDel);
               </method>
           </button>
       </view>
   </view>
</canvas>


<random thought>
Is there any interest/value in adding a <springrpc> tag that allows
getting beans and calling their methods directly from Laszlo? Personally, I don't know if this is a good idea b/c Laszlo seems to to
deal with XML much better than real Java objects.
</random thought>

Thanks,

Matt

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user


_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to