Hi Philip,

 

I don't know if you already have the answer, but here are still two ways to
do the trick:

 

1/ Use data replication: instead of using the code for getting all the
values from the XML by hand, you should try :

(typed in the mail and not tested, so it may contain some typos, but the
idea is here)

 

      <class name="bgpot" height="58" width="66">

            <attribute name="bgid" type="number"
value="$path{'id/text()'}"/>

            <attribute name="iconpath" value="$path{'icon/text()'}"/>

            <attribute name="imagepath" value="$path{'path/text()'}/>

            <attribute name="listener" type="expression"/>

            <method event="onclick">

                  listener.changeBackground(this.getAttribute('bgid'),

this.getAttribute('imagepath'));

            </method>

            <view bgcolor="#444444" height="56" width="64">

                  <image name="bgicon" resource="${parent.iconpath}"
height="54"

width="64"/>

            </view>

      </class>

 

Inside your class "BackgroundChooser", in the view "bgdisplay", insert 

<bgpot name="list" datapath="backgroundsRequest:/response/imageList/image"/>

 

I’m guessing the name of the last tag.

You should get an id to your dataset, I’ve had trouble with local datasets
you can try datapath="local:parent.parent.backgroundsRequest:/…" for
accessing the local dataset.

 

 

2/ use setAttribute instead of directly using the properties in the code :

 

bg.bgid = nodes[n].getElementsByTagName("id")[0].childNodes[0].data;

 

should be 

 

bg.setAttribute('bgid',
nodes[n].getElementsByTagName("id")[0].childNodes[0].data);

 

otherwise the eventing mechanism will not fire and the result will be that
the dependencies won’t be updated, and since the resource is specified with
a dependency in the bgicon view, the image will not be loaded.

 

Hope this helped.

 

++

Julien

 

-----Message d'origine-----
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] De la part de Philip A. Chapman
Envoyé : vendredi 21 décembre 2007 17:14
À : [email protected]
Objet : [Laszlo-user] Dynamically adding views with resources from a dataset

 

-----BEGIN PGP SIGNED MESSAGE-----

Hash: SHA1

 

Guys,

 

I'm trying to create a dialog which will request a list of images from

the server.  The XML returns a list with a bunch of URLs.  I'm trying to

use the URLs to build a list of thumbnails in the dialog.  However, the

thumbnails I create don't show up on the dialog.  I know that the images

are not being requested.  Any help would be great:

 

 

<library>

 

      <class name="bgpot" height="58" width="66">

            <attribute name="bgid" type="number" value="0"/>

            <attribute name="iconpath"/>

            <attribute name="imagepath"/>

            <attribute name="listener" type="expression"/>

            <method event="onclick">

                  listener.changeBackground(this.getAttribute('bgid'),

this.getAttribute('imagepath'));

            </method>

            <view bgcolor="#444444" height="56" width="64">

                  <image name="bgicon" resource="${parent.iconpath}"
height="54"

width="64"/>

            </view>

      </class>

 

      <class

            name="BackgroundChooser" extends="modaldialog" width="322"
height="245"

            bgcolor="#10F60A" visible="false"

      >

            <attribute name="selectedBackground" type="number" value="0"/>

 

            <method name="changeBackground" args="c">

                  <![CDATA[

                        this.setAttribute('selectedBackground', c);

                        this.close();

                  ]]>

            </method>

            

            <view x="-333" y="0" height="245" width="322" visible="false"

name="bgdisplay">

                  <wrappinglayout axis="x" spacing="5"/>

            </view>

            

            <dataset

                  name="backgroundsRequest" querytype="post" type="http"

onerror="classroot.loadError()"

                  src="../datatransfer" ondata="classroot.loadSuccess()"

            />

            <method name="open"><![CDATA[

                  Debug.write("Requesting backgrounds...");

                  

                  var ds = backgroundsRequest;

                  var p = new LzParam();

                  p.addValue("sessionid", canvas.drawingStatus.sessionid,
true);

                  p.addValue("requesttype", "GetBackgrounds", true);

                  ds.setQueryString(p);

                  ds.doRequest();

                  super.open();

            ]]></method>

            <method name="loadError"><![CDATA[

                  Debug.write('Backgrounds load error');

                  Debug.write('Response data: ' +
backgroundsRequest.serialize());

            ]]></method>

            <method name="loadSuccess">

                  var node =

backgroundsRequest.getElementsByTagName("response")[0].getElementsByTagName(
"code")[0].childNodes[0];

                  if (node.data == "100") {

                        var nodes =

backgroundsRequest.getElementsByTagName("response")[0].getElementsByTagName(
"imageList")[0].childNodes;

                        Debug.inspect(this.bgdisplay);

                        for (n in nodes) {

                             var bg = new bgpot(this.bgdisplay);

                             bg.bgid =
nodes[n].getElementsByTagName("id")[0].childNodes[0].data;

                             bg.iconpath =

nodes[n].getElementsByTagName("iconpath")[0].childNodes[0].data;

                             bg.imagepath =

nodes[n].getElementsByTagName("path")[0].childNodes[0].data;

                             this.bgdisplay.addSubview(bg);

                        }

                        Debug.write('Backgrounds Loaded successful');

                  } else {

                        Debug.write('Backgrounds load failed');

                        Debug.write('Response data: ' +
backgroundsRequest.serialize());

                  }

            </method>

      </class>

</library>

 

 

 

Thanks,

- --

Philip A. Chapman

 

Desktop and Web Application Development:

Java, .NET, PostgreSQL, MySQL, MSSQL

Linux, Windows 2000, Windows XP

 

-----BEGIN PGP SIGNATURE-----

Version: GnuPG v1.4.6 (GNU/Linux)

Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

 

iD8DBQFHa+YsAdpynRSGw3URAtxHAJ93G/KHxVWgb4roV+CJcipWICsUqQCdF5JY

WR8+KWmPJQZRexBHg4vHKQw=

=1YRl

-----END PGP SIGNATURE-----

Reply via email to