PDA

View Full Version : Disappearing method?


Sickgrin
08-17-2007, 08:12 AM
Let me prefix this by saying that I've just started playing with openlaszlo, so I'm probably overlooking something really obvious here.

I have a grid with contact data. When a row in that grid is selected, I display a context menu with related options for that row. The options for the menuData dataset are dynamically generated by a coldfusion template. I pass the template the ID for the selected row by calling the getmenudata method of my contextmenu class which simply updates the query params for the menuData src, and initiates the request to the template. Nice and simple... And it all works fine for the first row I select. The next time I select a row I get:

ERROR: leadmanagertest.lzx:52: call to undefined method 'getmenudata'

I'm confused why the method is there the first time and gone the next. BTW, I'm using lps 4.0.3 if that makes a difference.

Thanks.


<canvas width="1000" bgcolor="0xeaeaea" debug="true">
<include href="lz/tabelement.lzx" />
<dataset name="leadData" request="true" type="http" src="http:leaddata.xml"/>
<dataset name="menuData" request="false" type="http" src="http://somewhere.on.my.network.com/LeadManager/LeadActions.cfm?"/>

<class name="contextmenu" height="23" bgcolor="0xE7E7D6" width="100%">
<attribute name="minheight" value="23"/>
<attribute name="maxheight" value="78"/>

<view name="menuitem" width="100%">
<basebutton resource="tabrsrc" clickable="true" width="${parent.width}" stretches="both" />
<text x="10" y="4" datapath="@text" width="100%"/>
</view>
<view name="bottom" width="100%" resource="tabshadow" stretches="both" height="2"/>
<stableborderlayout axis="y" />

<method name="getmenudata" args="lead_id">
var ds=canvas.datasets.menuData;
var p=new LzParam();
p.addValue("action","GetGridContextMenu",true);
p.addValue("lead_id",lead_id, true);
ds.setQueryString(p);
ds.doRequest();

Debug.write("GetMenuData Lead_ID: ", lead_id);
</method>
</class>


<view name="contextmenusection" datapath="menuData:/resultset" x="1" y="29" width="150" height="500" clip="true">
<contextmenu name="mainmenu" datapath="result"/>
<simplelayout axis="y"/>
</view>

<view name="tabsection" x="151" y="1" width="800" height="500">
<tabs width="100%" height="100%">
<tabpane text="Leads">
<grid datapath="leadData:/resultset" width="790" height="490" x="5" y="5" bgcolor0="#FFFFFF" bgcolor1="#F9F9FC">
<gridcolumn datapath="@id" name="imgcol" width="25" resizable="false" sortable="false">
<attribute name="myid" value="$path{'@id'}" />
<image src="images/icon_lead.gif" xoffset="-4" yoffset="-4" onclick="Debug.write(parent.datapath);" />
</gridcolumn>
<gridtext editable="false" width="100" datapath="@firstname">First </gridtext>
<gridtext editable="false" width="100" datapath="@lastname">Last </gridtext>
<gridtext editable="false" width="75" datapath="@status"> Status </gridtext>
<gridtext editable="false" width="200" datapath="@company"> Company </gridtext>
<gridtext editable="false" width="200" datapath="@email"> Email </gridtext>
<gridtext editable="false" width="75" datapath="@user"> User </gridtext>

<method event="onselect">
var id = this.getSelection()[0].p.attributes.id;
canvas.contextmenusection.mainmenu.getmenudata(id) ;
Debug.write("OnSelect Lead_ID:", id);
</method>
</grid>
</tabpane>
</tabs>
</view>
</canvas>

senshi
08-17-2007, 01:51 PM
Don't place your method in your "contextmenu"-class, because whenever a class, or better an instance of a class, will get replicated, the actual instance will be replaced by a replication-manager.
This did happen in your case, so after having called "getmenudata" the first time, your "mainmenu" was replicated. Thereafter you were acting on a replication-manager, when you used "canvas.contextmenusection.mainmenu".

So, I'd propose to put this method in "contextmenusection":


<view name="contextmenusection" datapath="menuData:/resultset" x="1" y="29" width="150" height="500" clip="true">
<contextmenu name="mainmenu" datapath="result"/>
<simplelayout axis="y"/>

<method name="getmenudata" args="lead_id">
var ds=canvas.datasets.menuData;
var p=new LzParam();
p.addValue("action","GetGridContextMenu",true);
p.addValue("lead_id",lead_id, true);
ds.setQueryString(p);
ds.doRequest();

Debug.write("GetMenuData Lead_ID: ", lead_id);
</method>
</view>

Sickgrin
08-17-2007, 02:01 PM
I actually realized that a few minutes after I posted... when I moved the method elsewhere and everything worked.

Thanks.