[Laszlo-checkins] r8522 - openlaszlo/trunk/lps/components/rpc
lou@openlaszlo.org
lou at openlaszlo.org
Wed Apr 2 10:31:04 PDT 2008
Author: lou
Date: 2008-04-02 10:30:39 -0700 (Wed, 02 Apr 2008)
New Revision: 8522
Modified:
openlaszlo/trunk/lps/components/rpc/javarpc.lzx
Log:
Change 20080402-lou-T by lou at loumac.local on 2008-04-02 13:26:58 AST
in /Users/lou/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: add introductory pages and code examples from revision 3.4
New Features:
Bugs Fixed: LPP-5633
Technical Reviewer: (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)
Tests: visual verify
Modified: openlaszlo/trunk/lps/components/rpc/javarpc.lzx
===================================================================
--- openlaszlo/trunk/lps/components/rpc/javarpc.lzx 2008-04-02 17:29:25 UTC (rev 8521)
+++ openlaszlo/trunk/lps/components/rpc/javarpc.lzx 2008-04-02 17:30:39 UTC (rev 8522)
@@ -180,12 +180,224 @@
if (this.onremove) this.onremove.sendEvent();
]]>
</method>
-
+ <doc>
+ <tag name="shortdesc"><text>java remote procedure call</text></tag>
+ <text>
+ <p>javaRPC is a feature that allows server-side Java objects and methods
+ to be accessed from a client application. JavaRPC is part of the Laszlo
+ RPC family and shares similar APIs with SOAP and XML-RPC. See the
+ <a href="../developers/rpc.html">RPC</a> and <a href="../developers/rpc-xmlrpc.html">
+ XML RPC</a> chapters of the Developer's Guide
+ for more information.</p>
+ <p>This tag causes the creation of a JavaRPC object. The classname attribute
+ specifies what class javarpc represents. To use a class, place it in
+ WEB-INF/classes or, if it exists in a jar, in WEB-INF lib. This will ensure
+ that the class is accessible to the OpenLaszlo Server.</p>
+ <p>Java classes used in an application must be declared in a security element.
+ Classes not defined in a security element are not allowed to be accessed or
+ instantiated. The format of the security element looks like this:</p>
+ <programlisting>
+ <security>
+ <allow>
+ <pattern>CLASS1</pattern>
+ <pattern>CLASS2</pattern>
+ ...
+ <pattern>CLASSN</pattern>
+ </allow>
+ </security>
+ </programlisting>
+ <p>Each <pattern> is a regular expression.</p>
+ <programlisting>
+ <security>
+ <allow>
+ <pattern>^org\.openlaszlo</pattern>
+ </allow>
+ </security>
+ </programlisting>
+ <p>This example demonstrates how to call methods in a java object that exists remotely in the server:</p>
+ <example>
+ <canvas debug="true" height="300" width="800">
+
+ <debug x="250" y="10" width="500" height="275" />
+
+ <security>
+ <allow>
+ <pattern>^examples\.TypesExample</pattern>
+ </allow>
+ </security>
+
+ <!-- See WEB-INF/classes/TypesExample.java for java source. -->
+ <javarpc name="types_example_rpc" scope="none"
+ remoteclassname="examples.TypesExample">
+
+ <handler name="onload">
+ // Set buttons visible only after JavaRPC object loads
+ canvas.buttons.setAttribute('visible', true);
+ </handler>
+
+ <handler name="ondata" args="res">
+ Debug.write('(types ondata) response is:', res);
+ </handler>
+
+ <handler name="onerror" args="errmsg">
+ Debug.write('(types onerror) error:', errmsg);
+ </handler>
+
+ <!-- Declaratively pass an integer. -->
+ <remotecall funcname="passInteger">
+ <param value="42" />
+ </remotecall>
+
+ <!-- Declaratively pass a double. Note that we name this function pd1
+ because we have multiple remotecall declarations that call
+ passDouble but with different parameters. -->
+ <remotecall name="pd1" funcname="passDouble">
+ <param value="42.1" />
+ </remotecall>
+
+ <!-- Declaratively pass a double with 0 decimal. The 0 decimal will
+ truncate and the number will become an integer type when it reaches
+ the server. This call will fail. -->
+ <remotecall name="pd2" funcname="passDouble">
+ <param value="42.0" />
+ </remotecall>
+
+ <!-- Declaratively pass a double with 0 decimal. Wrapping the double in
+ DoubleWrapper will ensure the value will remain a double when
+ reaching the server. -->
+ <remotecall name="pd3" funcname="passDouble">
+ <param>
+ <method name="getValue">
+ return new LzRPC.DoubleWrapper(42.0);
+ </method>
+ </param>
+ </remotecall>
+
+ </javarpc>
+
+
+ <view name="buttons" visible="false" layout="spacing: 10" >
+
+ <button text="pass integer"
+ onclick="types_example_rpc.passInteger.invoke()" />
+
+ <button text="pass double"
+ onclick="types_example_rpc.pd1.invoke()" />
+
+ <button text="pass double (will fail)"
+ onclick="types_example_rpc.pd2.invoke()" />
+
+ <button text="pass double w/LzRPC.DoubleWrapper"
+ onclick="types_example_rpc.pd3.invoke()" />
+
+ <button text="pass boolean" onclick="this.passBoolean.invoke()">
+ <!-- This is a way to declare a remotecall closer to where it's being
+ used. The remotecontext must be set. -->
+ <remotecall funcname="passBoolean"
+ remotecontext="$once{ types_example_rpc }">
+ <param value="true" />
+ </remotecall>
+ </button>
+
+ <button text="pass array" onclick="this.passArray.invoke()">
+ <remotecall name="passArray" funcname="passClientArray"
+ remotecontext="$once{ types_example_rpc }">
+ <param value="[1, 'a string', 4.5, false]" />
+ </remotecall>
+ </button>
+
+ <button text="pass hash" onclick="this.passObject.invoke()">
+ <remotecall name="passObject" funcname="passClientObject"
+ remotecontext="$once{ types_example_rpc }">
+ <param value="{ a: 1, b: 3.14159, c: 'a string value', d: true}">
+ </param>
+ </remotecall>
+ </button>
+
+ </view>
+
+ </canvas>
+ </example>
+ <p>The java source code, which can be found in $LPS_HOME/WEB-INF/classes/examples, looks like:</p>
+ <programlisting>
+ package examples;
+
+ import java.util.Vector;
+ import java.util.Hashtable;
+
+ public class TypesExample {
+
+ public static String passInteger(int i) {
+ return "got integer parameter: " + i;
+ }
+
+ public static String passDouble(double d) {
+ return "got double parameter: " + d;
+ }
+
+ public static String passBoolean(boolean b) {
+ return "got boolean parameter: " + b;
+ }
+
+ public static String passClientArray(Vector v) {
+ return "got vector parameter: " + v;
+ }
+
+ public static String passClientObject(Hashtable t) {
+ return "got hashtable parameter: " + t;
+ }
+
+ }
+ </programlisting>
+
+ <table border="1">
+
+ <tr>
+ <th rowspan="1" colspan="1">JavaScript data type</th><th rowspan="1" colspan="1">Parameter types expected by java method</th>
+ </tr>
+
+ <tr>
+ <td rowspan="1" colspan="1">Number (int)</td><td rowspan="1" colspan="1">int</td>
+ </tr>
+
+ <tr>
+ <td rowspan="1" colspan="1">Number (double)*</td><td rowspan="1" colspan="1">double</td>
+ </tr>
+
+ <tr>
+ <td rowspan="1" colspan="1">LzRPC.DoubleWrapper</td><td rowspan="1" colspan="1">double</td>
+ </tr>
+
+ <tr>
+ <td rowspan="1" colspan="1">Boolean</td><td rowspan="1" colspan="1">boolean</td>
+ </tr>
+
+ <tr>
+ <td rowspan="1" colspan="1">Array</td><td rowspan="1" colspan="1">Vector</td>
+ </tr>
+
+ <tr>
+ <td rowspan="1" colspan="1">Object</td><td rowspan="1" colspan="1">Hashtable</td>
+ </tr>
+
+ </table>
+ <p>* Any floating point number with a zero decimal value is considered to be an
+ integer, i.e., 1.0 is really 1. Use LzRPC.DoubleWrapper to ensure a number is
+ considered a double. For example:</p>
+ <programlisting>
+ // assume myrpc is a javarpc object and myrpc.proxy.myMethod is a function
+ // that expects a single double as a parameter
+ var mydouble = new LzRPC.DoubleWrapper(1.0);
+ myrpc.proxy.myMethod([ mydouble ], new LzDelegate(...));
+ </programlisting>
+
+ </text>
+ </doc>
</class>
</library>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2008 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<!-- @LZX_VERSION@ -->
More information about the Laszlo-checkins
mailing list