openlaszlolzx

What is the proper syntax to databind a class attribute in the OpenLaszlo language?


I am developing a class where I wish to databind the attributes of a class to a dataset. I have managed to get the following to work in the following simplified version of my class:

  <class name="myclass">

    <dataset name="attSettings"><settings>
        <property name="applyshadow" defaultvalue="false" type="boolean" />
    </settings></dataset>

    <attribute name="default_applyshadow" type="boolean" value="$once{(this.attSettings.getPointer()).xpathQuery('settings/property[@name=&quot;applyshadow&quot;]/@defaultvalue')}" />

  </class>

However, this syntax is very cumbersome and does not feel right so I am wondering if there is a better way to do this.


Solution

  • I figured out the proper syntax to do what I wanted:

     <dataset name="myclass_settings">
       <root>
         <property name="applyshadow" defaultvalue="false" type="boolean" />
       </root>
     </dataset>
    
     <class name="myclass" datapath="myclass_settings:/root">
        <attribute name="default_applyshadow" type="boolean" value=$path{'property[@name=&quot;applyshadow&quot;]/@defaultvalue'}" />
     </class>
    

    The $path{} constraint is used on the class attribute to link the value to the dataset via a relative xpath query. I also had to move the dataset outside of the class to get it to work.