View Full Version : how to pass xml data path thru paramater
jmaster
12-30-2006, 11:38 PM
Hi how do you pass xml data path thru paramater? Please help? :confused:
Here is my problem because when i use state, the data in the view is still there after I change to a different state....
<dataset name="myBlog" src="blog.xml"/>
....
if(currentState=="wmbtnCurrent") {
var xp = "myBlog:/myblog/entry";
lfpCurrent.apply();
curHdlines.datapath.setPointer(xp);
lfpHome.remove();
}
....
<state name="lfpCurrent">
<view id="curHdlines" width="${parent.width}">
<datapath>
<text x="12" datapath="date/text()"/>
<text x="12" datapath="title/text()" />
</view>
</state>
Thanks
senshi
12-31-2006, 08:00 AM
First at all, it should be LzDatapointer#setXPath(..).
var xp = "myBlog:/myblog/entry";
curHdlines.datapath.setXPath(xp);
jmaster
12-31-2006, 08:52 AM
Thanks senshi for your great help!
I also have another problem when I go from one state to another state when there is view it keeps on duplicating the view...... How do you remove the view curHdlines created in lfpCurrent when I'm in state lfpHome so it does not create a new one each time?
Debugger Error Message:
load wmbtnCurrent
unload wmbtnHome
WARNING: Redefining #curHdlines from «LzReplicationManager#0| ReplicationManager
....
if(currentState=="wmbtnHome") {
var xp = null;
lfpHome.apply();
curHdlines.datapath.setXPath(xp);
lfpCurrent.remove();
}
if(currentState=="wmbtnCurrent") {
var xp = "myBlog:/myblog/entry";
lfpCurrent.apply();
curHdlines.datapath.setXPath(xp);
lfpHome.remove();
}
....
.....
<state name="lfpCurrent">
<view id="curHdlines" width="${parent.width}">
<datapath>
<text x="12" datapath="date/text()"/>
<text x="12" datapath="title/text()" />
</view>
</state>
<state name="lfpHome" apply="true">
<text width="${parent.width}">home</text>
</state>
senshi
12-31-2006, 10:07 AM
Due to replication "curHdlines" changes from being a normal view to a replication manager, but your state "lfpCurrent" still thinks it is a view. And the state won't control the replicated views, so they're still present even after removing the state.
So to avoid this state-replication-issue, wrap your "curHdlines"-view in another simple view (here: "wrapper"). This should do the trick.
Sample: Click first on "Current" and then back on "Home", this should show the desired layout.
<canvas debug="true" >
<dataset name="myBlog" >
<myblog>
<entry id="1">
<title>Newest Entry</title>
<date>01.01.07</date>
</entry>
<entry id="2">
<title>Happy New Year!</title>
<date>01.01.07</date>
</entry>
</myblog>
</dataset>
<view layout="axis:x;spacing:0" height="400">
<view layout="axis:y">
<button name="btnHome" text="Home" onclick="parent.setupContent('wmbtnHome')" />
<button name="btnCurrent" text="Current" onclick="parent.setupContent('wmbtnCurrent')" />
<method name="setupContent" args="currentState" >
if( currentState == "wmbtnHome" ) {
content.lfpHome.apply();
content.wrapper.curHdlines.datapath.setXPath( null );
content.lfpCurrent.remove();
}
else if( currentState == "wmbtnCurrent" ) {
content.lfpCurrent.apply();
content.wrapper.curHdlines.datapath.setXPath( "myBlog:/myblog/entry" );
content.lfpHome.remove();
}
</method>
</view>
<view height="100%" width="1" bgcolor="black" />
<view id="content" >
<state name="lfpCurrent">
<view name="wrapper" layout="axis:y;spacing:10">
<view name="curHdlines" width="${parent.width}" datapath="." layout="axis:y;spacing:5">
<text x="12" datapath="date/text()" resize="true" />
<text x="12" datapath="title/text()" resize="true" />
</view>
</view>
</state>
<state name="lfpHome" apply="true">
<text>home</text>
</state>
</view>
</view>
</canvas>
jmaster
12-31-2006, 12:49 PM
senshi
Excellent, this wrapper works very nicely !!! I'll still have to read and do more OL coding a bit more to fully understand this state-replication-issue...... I still don't fully know why a wrapper would help in this case.....
Thank you for your help man!!!
senshi
12-31-2006, 01:09 PM
I'll still have to read and do more OL coding a bit more to fully understand this state-replication-issue...... I still don't fully know why a wrapper would help in this case.....
I think I had once the same issue.
After going through the source code for states, I found out that the replicated views aren't affected by the state's scope. So removing the state won't remove the replicated views.
(As a matter of fact, nobody tells the state to "feel responsible" for the replicated views...)
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.