The <remotecall> element allows for a more declarative style approach to using RPC functions. Calling function stubs will generally result in your code looking very scripty.
Remotecall requires the funcname attribute to be set. Funcname refers to the remote function name. By default, the name of the remotecall is the same as funcname unless explicitly set to something else. Multiple remotecalls can refer to the same funcname, but remotecall names must be unique within the same element context.
<param> elements declared in the remotecall body are used when invoking the remote function. The declaration order of <param>s should match what the remote function expects.
Example 80. Using RPC methods
<canvas
debug
="true
" height
="280
">
<debug
x
="10
" y
="40
" width
="470
" height
="230
"/>
<soap
name
="temperature
" autoload
="false
" wsdl
="http://developerdays.com/cgi-bin/tempconverter.exe/wsdl/ITempConverter
">
<method
name
="init
">
super.init();
Debug.debug('soap service loading...');
this.load();
</method
>
<handler
name
="onload
">
Debug.debug('temperature service loaded!');
Debug.debug('---');
// don't allow others to call RPC object until proxy is loaded.
canvas.convert.setAttribute('visible', true);
</handler
>
<handler
name
="ondata
" args
="value
">
Debug.debug('soap object parent ondata: %w', value);
</handler
>
<remotecall
name
="ftoc1
" funcname
="FtoC
">
<param
value
="100
"/>
</remotecall
>
<remotecall
name
="ftoc2
" funcname
="FtoC
">
<param
value
="200
"/>
<handler
name
="ondata
" args
="value
">
Debug.debug('ftoc ondata: %w', value);
</handler
>
</remotecall
>
</soap
>
<view
name
="convert
" x
="10
" y
="10
" visible
="false
" layout
="axis: x; spacing: 5
">
<button
text
="convert 100F to C
">
<handler
name
="onclick
">
canvas.temperature.ftoc1.invoke()
Debug.debug('Invoking FtoC 1...');
</handler
>
</button
>
<button
text
="convert 200F to C
">
<handler
name
="onclick
">
canvas.temperature.ftoc2.invoke()
Debug.debug('Invoking FtoC 2...');
</handler
>
</button
>
</view
>
</canvas
>
Any events not handled by remotecall can be handled by a remotecall's parent. A remotecall element can be declared anywhere in the view hierarchy. However, if it's not within an RPC object (like <soap>, <javarpc, <xmlrpc>), the remotecontext attribute must be set. The remotecontext tells the remotemethod which RPC object to refer to when invoking the remote method.
<canvas
debug
="true
" height
="280
">
<debug
x
="10
" y
="40
" width
="470
" height
="230
"/>
<soap
name
="temperature
" autoload
="false
" wsdl
="http://developerdays.com/cgi-bin/tempconverter.exe/wsdl/ITempConverter
">
<method
name
="init
">
super.init();
Debug.debug('soap service loading...');
this.load();
</method
>
<handler
name
="onload
">
Debug.debug('temperature service loaded!');
Debug.debug('---');
// don't allow others to call RPC object until proxy is loaded.
canvas.convert.setAttribute('visible', true);
</handler
>
<handler
name
="ondata
" args
="value
">
Debug.debug('soap object ondata: %w', value);
</handler
>
<handler
name
="onerror
" args
="errmsg
">
Debug.debug('error: %w', errmsg);
</handler
>
</soap
>
<view
name
="convert
" x
="10
" y
="10
" visible
="false
" layout
="axis: x; spacing: 5
">
<button
text
="convert 100F to C
">
<handler
name
="onclick
">
this.FtoC.invoke()
Debug.debug('Converting 100F to Celsius...');
</handler
>
<remotecall
funcname
="FtoC
" remotecontext
="$once{canvas.temperature}
">
<param
value
="100
"/>
</remotecall
>
</button
>
<button
text
="convert 200F to C
">
<handler
name
="onclick
">
this.FtoC.invoke()
Debug.debug('Converting 200F to Celsius...');
</handler
>
<remotecall
funcname
="FtoC
" remotecontext
="$once{canvas.temperature}
">
<param
value
="200
"/>
<handler
name
="ondata
" args
="value
">
Debug.debug('200F in Celsius is %w', value);
</handler
>
</remotecall
>
</button
>
</view
>
</canvas
>
The order in which events (ondata, onerror) are handled are as follow:
To databind to a successful return value, you can set the dataobject attribute to a dataset. For more information on databinding with RPC, see the RPC chapter
<canvas
debug
="true
" height
="300
" width
="680
">
<debug
x
="225
" width
="450
" height
="280
"/>
<dataset
name
="googleDset
"/>
<soap
name
="google
" wsdl
="http://api.google.com/GoogleSearch.wsdl
">
<handler
name
="onload
">
Debug.debug('google soap service stub loaded');
</handler
>
<handler
name
="onerror
" args
="error
">
Debug.debug('error: %w', error);
</handler
>
<remotecall
name
="search
" funcname
="doGoogleSearch
" dataobject
="googleDset
">
<param
value
="'2TKUw4ZQFHJ84ByemZK0EXV0Lj+7xGOx'
"/>
<param
value
="'sweet'
"/>
<param
value
="1
"/>
<param
value
="10
"/>
<param
value
="true
"/>
<param
value
="''
"/>
<param
value
="true
"/>
<param
value
="''
"/>
<param
value
="''
"/>
<param
value
="''
"/>
<handler
name
="ondata
" args
="value
">
Debug.debug('got result');
Debug.inspect(value);
</handler
>
</remotecall
>
</soap
>
<view
layout
="spacing: 5
">
<button
text
="search
" onclick
="google.search.invoke()
"/>
<view
bgcolor
="yellow
" layout
="axis: y
">
<view
>
<datapath
xpath
="googleDset:/resultElements/item
" pooling
="true
"/>
<text
datapath
="URL/text()
" resize
="true
"/>
</view
>
</view
>
</view
>
</canvas
>
See Also:
Name (CSS property) | Type (tag) | Type (js) | Default | Category |
---|---|---|---|---|
dataobject
|
expression | any | null | read/write |
If an LzDataset or an LzDataElement is set, return values will be mapped into the dataobject. | ||||
funcname
|
string | String | null | read/write |
Name of remote function this remotecall refers. | ||||
inforeturnvalue
|
boolean | boolean | false | read/write |
If true, a remote response returns an object. The object of a successful response will contain the return value (data), an object containing specific information about the request (info), and the associated unique sequence request number (seqnum), e.g., { data: ..., info: ..., seqnu: ...}. A failure response returns an object that contains the error message (message), the error type (error), an object containing specific information about the request (info), and the associated unique sequence request number (seqnum), e.g., { message: ..., error: ..., info: ..., seqnum: ...}. If false, an error just returns the error message and a successful response returns a value. Default is false. | ||||
name
|
expression | any | null | read/write |
Name of remotecall. Default is value of funcname attribute. | ||||
remotecontext
|
expression | any | null | read/write |
If set, this is the remote object context in which funcname is run from. |
classroot, cloneManager, data, datapath, defaultplacement, id, ignoreplacement, immediateparent, inited, initstage, name, nodeLevel, options, parent, placement, styleclass, subnodes, transition
Methods
invoke() |
---|
Parameter Name | Type | Description |
---|---|---|
params | Array | array of parameters. A parameter can be an object, array, or primitive type. This is optional if <param>s have been declared this remotecall''s body. |
delegate | lz.handler | (optional) the remotecall will use the passed in delegate, otherwise it will run the default. Note: if LzDelegate passed in contains a property called 'dataobject', the return value will be mapped to it. The dataobject property can be a dataset or a LzDataElement object. |
Returns | Type | Description |
---|---|---|
Number | the unique sequence request number associated with this call, or -1 if there was a problem invoking this method. |
animate, applyConstraintMethod, applyData, childOf, completeInstantiation, construct, createChildren, dataBindAttribute, destroy, determinePlacement, getOption, getUID, init, lookupSourceLocator, releaseConstraint, releaseConstraintMethod, searchImmediateSubnodes, searchSubnodes, setOption, setSelected, updateData
Copyright © 2002-2010 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.