📄 dmi.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
//> @class DMI// // Direct Method Invocation (DMI) allows background HTTP requests to directly// invoke methods on server-side objects via XML configuration.// <P>// DMI is an alternative to the +link{RPCManager.actionURL} approach where your server code// receives a generalized +link{RPCRequest,request object} which you route to appropriate// methods yourself. Which interface (DMI or RPCManager) you choose is largely a matter of// preference - they provide equivalent functionality. Note that there are also several// approaches for +link{group:nonJavaBackend,non-Java backends} and/or Java backends not// running the ISC server.// <p>// When using DMI, inbound request data is translated to Java objects and passed as method// parameters to the designated method, with available request data matched to each declared// parameter by Java type. The return value of your method is automatically wrapped as a valid// response and delivered to the browser.// <P>// <u><b>DataSource DMI</b></u>// <br>// To enable DMI for a given DataSource, simply include a <code><serverObject></code>// configuration block in that DataSource's configuration either at// +link{DataSource.serverObject} or on a particular operationBinding via// +link{OperationBinding.serverObject}. The ServerObject specifies the target of the method// invocation and +link{OperationBinding.serverMethod} specifies the method that will be// called.// <P>// For example, the following Datasource DMI declaration would route "fetch" operations for// this DataSource to the method "fetch" on an object stored in the servlet session under the// name "beanFetcher":// <pre>// <DataSource>// <operationBindings>// <binding operationType="fetch" serverMethod="fetch">// <serverObject // lookupStyle="attribute" // attributeScope="session" // attributeName="beanFetcher"/>// </binding>// </operationBindings>// ...// </DataSource>// </pre>// Method overloading is not supported - there must be exactly one method on the target class// with the name specified in +link{OperationBinding.serverMethod}. The method must be public,// but can be either an instance or static method. If no operationBinding is specified or the// operationBinding does not specify a <code>serverMethod</code> then it defaults to the name of// the operation (eg "fetch").// <p>// By default, the DSResponse data sent back by DataSource DMIs is filtered to just the set of// fields specified on the DataSource. This allows you to simply return beans that potentially// have getter methods for fields other than are defined in the DataSource without that// (potentially private) data being sent to the client. If you want to disable this// functionality, you can do so by on a per-operation basis by setting// +link{ServerObject.dropExtraFields}, on a per-DataSource level by setting// +link{DataSource.dropExtraFields}, or globally by setting the config parameter// <code>DMI.dropExtraFields</code> to <code>false</code> in// <code>[webroot]/WEB-INF/classes/server.properties</code>. Non-DMI DSResponse data is, by// default, not filtered in this matter for backwards compatibility reasons. If you want to// enable this type of filtering for non-DMI DSResponse data, you can do so by setting the// config parameter <code>DSResponse.dropExtraFields</code> to <code>true</code> in// <code>[webroot]/WEB-INF/classes/server.properties</code>. <code>DMI.dropExtraFields</code>// and <code>DSResponse.dropExtraFields</code> can be enabled/disabled independently of each// other - that is, setting one does not side-effect the other. <code>server.properties</code>// settings can be overridden by an explicit setting in +link{dataSource.dropExtraFields} which// in turn can be overridden by an explicit setting in +link{serverObject.dropExtraFields} (this// last one for DMI only since non-DMI operations don't have a serverObject context).// <p>// <u><b>RPC DMI</b></u>// <br>// RPC DMI makes a set of methods from a server-side class available as client-side methods for// direct invocation. RPC DMI also uses a +link{ServerObject} configuration block to specify// the server-side DMI end-point, but in the case of RPCs, the +link{ServerObject} definition// goes into an <code>rpcBindings</code> section of an <code>Application</code> definition in a// .app.xml file. For an example, see the <code>example.app.xml</code> file in the /shared/app// directory of the SmartClient SDK. The only difference between the RPC DMI// ServerObject definition and the DataSource DMI version is the addition of the// +link{ServerObject.visibleMethods} block that specifies which methods are callable on this// ServerObject. This section is not consulted for DataSource DMIs because the// +link{OperationBinding.serverMethod} is used to specify the callable method in that case.// <p>// <u><b>Method Invocation</b></u>// <br>// SmartClient can pass a set of stock context variables to your DMI method and also performs// some type adaptation logic to make this interface more flexible. For DataSource DMI, you// can declare your method to take any number of the following types of arguments and they will// be passed to you:// <ul>// <li>HttpServletRequest// <li>HttpServletResponse// <li>ServletContext// <li>HttpSession// <li>RPCManager// <li>DSRequest// <li>RequestContext (from com.isomorphic.servlet)// <li>DataSource (same as DSRequest.getDataSource())// <li>Map (same as DSRequest.getValues())// <li>Bean (auto-populated from DSRequest.getValues())// </ul>// DataSource DMI methods can return any of the following types of values:// <ul>// <li>DSResponse (used as the DSResponse verbatim)// <li>List (valid response to a fetch operation - gets auto-popuplated into a DSResponse for// you via setData())// <li>Map or Bean (valid response to add, update, remove operations - gets auto-populated// into a DSResponse for you via setData()).// </ul>// Note that to take advantage of some SmartClient features like paging and custom validation,// you need to return a DSResponse and provide the required metadata (like// startRow/endRow/totalRows for paging). You can simply return a <code>List</code> instead,// but this won't work for large datasets.// <p>// So, for example, all of the following DataSource DMI method signatures are valid:// <pre>// public List myFetch(Map criteria)// public List myFetch(SupplyItem criteria)// public DSResponse myAdd(HttpSession session, // DataSource ds, // DSRequest dsRequest)// </pre>// <p>// See// +externalLink{/examples/server_integration/#customDataSourceIntegrationDMI,the supplyItemDMI example}// for an example of DataSource DMI.// <p>// <p>// RPC DMIs work slighly differently. Unlike DataSource DMIs, RPC DMIs can have an arbitrary// number of required arguments, and also some optional context arguments. For example, let's// say you call a method from the client like so (note that there's a cleaner way to invoke// DMIs if you use the +link{group:loadDMIStubsTag} JSP tag):// <pre>// DMI.call("myApp", "com.foo.MyClass", "doSomething",// 1, "zoo", [1, 2, 3], "clientCallback()");// </pre>// The server-side implementation of method <code>doSomething</code> must take a least three// arguments of the type used above - specifically a Number, String, and List. SmartClient// will try to adapt arguments where possible - so for example the first argument can be a Long// or an Integer instead and the invocation will still work. Also, an object literal passed// from the client becomes a Map on the server and will be automatically applied to a bean if// the method argument takes a Bean in that position. See +link{RPCRequest.data} for a table// of type conversions. You can use native types in the server-side signature for things like// Integer, Long, etc - so e.g. you can specify your method taking an int or long. In addition// to the required arguments, you can pass the following optional arguments:// <ul>// <li>HttpServletRequest// <li>HttpServletResponse// <li>HttpSession// <li>RPCManager// <li>RPCRequest// </ul>// See// +externalLink{/examples/server_integration/#genericRPCIntegrationDMI,the getTimeStampDMI example}// for an example of RPC DMI.//// @see group:loadDMIStubsTag// @see ServerObject // @see DataSource.serverObject// @see OperationBinding.serverObject//// @see group:clientServerIntegration//// @treeLocation Client Reference/RPC// @requiresModules SCServer// @visibility external//<isc.defineClass("DMI").addClassProperties({actionURL: isc.RPCManager.actionURL, //> @classMethod DMI.call()//// Calls a server-side DMI method. At a minimum, you need to specify the appID (.app.xml// file), +link{serverObject.className} or +link{serverObject.ID} and methodName to call.// Arguments and callback are optional. There are two ways to invoke this method:// <pre>// DMI.call(appID, className, methodName, // arg1, arg2 ...argN, callback);// </pre>// or:// <pre>// DMI.call({// appID: appID,// className: className,// methodName: methodName,// arguments: [arg1, arg2, ...argN], //optional// callback: callback, //optional// requestParams: requestProps // optional// });// </pre>// If you use the first signature, you must either specify a callback or if you don't want a// callback, pass a <code>null</code> as the last argument. The second signature allows you to// specify requestParams that are applied to the +link{RPCRequest} generated by this DMI call.// This allows you to override some defaults - for example to suppress the "Contacting Server"// prompt, change it's text; change the timeout or set any other property settable on// +link{RPCRequest}.// <p>// Note that you can use the +link{group:loadDMIStubsTag} tag to bind all methods of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -