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

StackOverflow https://stackoverflow.com/questions/14468983

  •  17-01-2022
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول 2

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.

نصائح أخرى

This doesn't answer your question but explains why you cannot use a local dataset in your situation. When you have a local dataset in a class, the dataset can only be addressed in children of the class, e.g.:

<canvas debug="true">

    <class name="myclass">
        <dataset name="myds">
            <root>
                <property name="applyshadow" defaultvalue="false" type="boolean" />
            </root>
        </dataset>

        <text datapath="local:classroot.myds:/root/property[@name='applyshadow']/@defaultvalue" />

    </class>

    <myclass />

</canvas>

The <text> element can access the dataset of the parent class by prepending local: to the datapath value. If you don't select a name for your dataset, OpenLaszlo will automatically use the name localdata for the dataset. Datasets using that name can be addressed by omitting the dataset name in the datapath/xpath value, e.g.

    <class name="myclass">
        <dataset>
            <root>
                <property name="applyshadow" defaultvalue="false" type="boolean" />
            </root>
        </dataset>

        <text datapath="local:classroot:/root/property[@name='applyshadow']/@defaultvalue" />

    </class>

Note that the datapath does not have a name and that the datapath used for the <text> component is now local:classroot:/root/..., while local:classroot.localdata:/root/... would work as well.

I don't understand the design decision which makes it impossible to allow the use a local dataset in the datapath of a class containing that dataset, but maybe there were some technical reasons (initialization order, etc.) for it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top