public class RPCManager
extends java.lang.Object
Smart GWT's powerful databinding subsystem (see DataSource
,
DataBoundComponents
) automatically make use of this class to
issue
RPCs as necessary, based on the
DataSource protocol
. To integrate DataBoundComponents
with your server, start here
.
For arbitrary client/server interactions outside of the DataSource subsystem, the
Smart GWT server also provides the Direct Method Invocation
feature.
The RPCManager class can also be used directly to send data to a URL of your choosing and optionally be called back with server-returned data when the server replies.
The Smart GWT server code
has APIs for processing RPC requests
providing features such as automatic Java <--> JavaScript object translation
and handling of queued requests.
The IDACall servlet
makes use of these features to handle standard
DataSource
requests and DMI calls. Developers can also override the
actionURL
of specific requests and use these APIs directly in a
JSP, Servlet or Filter.
Note: the client-side RPCManager class can also be used without the Smart GWT server.
For an overview of client/server interactions without the Smart GWT server, see
this overview
.
Simple arbitrary Remote Procedure Call example (client code):
RPCRequest request = new RPCRequest(); // Note data could be a String, Map or Record request.setData("Some data to send to the client"); request.setActionURL("/rpcHandler.jsp"); RPCManager.sendRequest(request, new RPCCallback () { public void execute(RPCResponse response, Object rawData, RPCRequest request) { SC.say("Response from the server:" + rawData); } } );
Simple arbitrary Remote Procedure Call example (server code: /rpcHandler.jsp):
RPCManager rpc = new RPCManager(request, response, out); Object data = rpc.getData(); System.out.println("client sent: " + data.toString()); rpc.send("here's a response");
Queuing
Because of browser limitations on the total number of simultaneous HTTP connections to a given
server, batching multiple RPC requests into a single HTTP request is highly advisable whenever
possible. The RPCManager provides a queuing mechanism that allows this.
Queuing example (client code):
boolean wasQueuing = RPCManager.startQueue(); RPCCallback callback = new RPCCallback() { public void execute(RPCResponse response, Object rawData, RPCRequest request) { Window.alert("response from server:" + rawData); } }; RPCRequest request1 = new RPCRequest(); request1.setActionURL("/rpcHandler.jsp"); request1.setData("A String of Data"); RPCManager.sendRequest(request1, callback); RPCRequest request2 = new RPCRequest(); request2.setActionURL("/rpcHandler.jsp"); request2.setData("Another String of Data"); RPCManager.sendRequest(request2, callback); if (!wasQueuing) RPCManager.sendQueue();
Queuing example (server code: /rpcHandler.jsp):
RPCManager rpc = new RPCManager(request, response, out); for(Iterator i = rpc.getRequests().iterator(); i.hasNext();) { RPCRequest rpcRequest = (RPCRequest)i.next(); Object data = rpcRequest.getData(); System.out.println("client sent:" + data.toString()); //send back the data sent to us by the client rpc.send(rpcRequest, new RPCResponse(data)); }
separate article
on error handling.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALL_GLOBALS
ALL_GLOBALS constant used by the
loadScreen(String, LoadScreenCallback, String[]) API. |
Constructor and Description |
---|
RPCManager() |
Modifier and Type | Method and Description |
---|---|
static void |
cacheScreens(java.lang.String[] screenName,
Function callback)
Loads the definitions of a set of screens saved in
Component XML format,
using the ScreenLoaderServlet . |
static void |
cacheScreens(java.lang.String[] screenName,
Function callback,
java.lang.String locale) |
static void |
cacheScreens(java.lang.String[] screenName,
Function callback,
java.lang.String locale,
RPCRequest requestProperties)
Loads the definitions of a set of screens saved in
Component XML format,
using the ScreenLoaderServlet . |
static void |
cancelDefaultErrorHandling()
Cancels default error handling for all
DSResponse s in
the current transaction, ensuring that the default error handling or current
error handler is not called for any
of them. |
static void |
cancelQueue()
Cancel a queue of requests (also called a transaction).
|
static void |
cancelQueue(int transactionNum)
Cancel a queue of requests (also called a transaction).
|
static void |
cancelQueue(java.lang.String transactionNum)
Deprecated.
please use int methods when dealing with transaction number.
|
static void |
clearTransaction(int transactionNum)
Erase all client-side record of a transaction, such that any response from the server will be ignored.
|
static void |
clearTransaction(java.lang.String transactionNum)
Deprecated.
please use int methods when dealing with transaction number.
|
static Canvas |
createScreen(java.lang.String screenName)
Creates a screen previously cached by a call to
cacheScreens(String[], Function, String, RPCRequest) . |
static Canvas |
createScreen(java.lang.String screenName,
java.lang.String[] globals)
Creates a screen previously cached by a call to
cacheScreens(String[], Function, String, RPCRequest) . |
static void |
exportContent(Canvas canvas)
Exports the printable representation of a set of widgets as a .pdf that is then
downloaded to the user (triggering the "Save As.." dialog).
|
static void |
exportContent(Canvas[] canvas)
Exports the printable representation of a set of widgets as a .pdf that is then
downloaded to the user (triggering the "Save As.." dialog).
|
static void |
exportContent(Canvas[] components,
DSRequest requestProperties)
Converts
printable HTML generated from live UI components
into a .pdf and downloads it ("Save As.." dialog). |
static void |
exportContent(Canvas canvas,
DSRequest requestProperties)
Exports the printable representation of a set of widgets as a .pdf that is then
downloaded to the user (triggering the "Save As.." dialog).
|
static void |
exportContent(java.lang.String canvas)
Exports the printable representation of a set of widgets as a .pdf that is then
downloaded to the user (triggering the "Save As.." dialog).
|
static void |
exportContent(java.lang.String htmlFragment,
DSRequest requestProperties)
Converts
printable HTML generated from live UI components
into a .pdf and downloads it ("Save As.." dialog). |
static void |
exportImage(java.lang.String svgString) |
static void |
exportImage(java.lang.String svgString,
DSRequest requestProperties) |
static void |
exportImage(java.lang.String svgString,
DSRequest requestProperties,
ExportImageCallback callback)
Converts an SVG string to one of several possible image formats, and can either initiate
a download or return the base64-encoded image data.
|
static java.lang.String |
getActionURL()
Specifies the default URL for RPCRequests and DSRequests that do not specify a URL.
|
static java.lang.String |
getCredentialsURL()
Specifies URL where credentials should be submitted to attempt relogin when session timeout is encountered during a
background RPC.
|
static java.lang.String |
getCurrentTransactionId()
Deprecated.
please use int methods when dealing with transaction number.
|
static int |
getCurrentTransactionIdAsInt()
Same as getQueueTransactionId() but returns
-1 instead of null
if there's no currently queued requests. |
static java.lang.String |
getLoginRequiredMarker()
Marker the system will look for in order to detect when login is required.
|
static java.lang.String |
getLoginStatusCodeMarker()
String sequence which marks the response as a one which contains login status information.
|
static java.lang.String |
getLoginSuccessMarker()
Marker the system will look for in order to detect when login was successfull.
|
static void |
getMaxLoginAttemptsExceededMarker()
Get the marker the system will look for in order to detect when the number of maximum logins was exceeded.
|
static java.lang.Integer |
getQueueTransactionId()
Returns the id of the current transaction (a queue of requests).
|
static java.lang.Boolean |
hasCurrentTransactionQueued()
Returns true if there is a current transaction (queue of requests)
|
static void |
loadScreen(java.lang.String screenName,
LoadScreenCallback callback)
Loads a screen saved in
Component XML format. |
static void |
loadScreen(java.lang.String screenName,
LoadScreenCallback callback,
java.lang.String[] globals)
Loads a screen saved in
Component XML format. |
static void |
loadScreen(java.lang.String screenName,
LoadScreenCallback callback,
java.lang.String[] globals,
RPCRequest requestProperties)
Loads a screen saved in
Component XML format. |
static void |
loadScreen(java.lang.String screenName,
LoadScreenCallback callback,
java.lang.String[] globals,
java.lang.String locale,
RPCRequest requestProperties)
Loads a screen saved in
Component XML format, using the
ScreenLoaderServlet . |
static java.lang.Boolean |
requestsArePending()
Returns whether there are any pending RPC requests.
|
static void |
resendTransaction()
Resend a suspended transaction to the server.
|
static void |
resendTransaction(int transactionNum)
Resend a suspended transaction to the server.
|
static void |
resendTransaction(java.lang.String transactionNum)
Deprecated.
please use int methods when dealing with transaction number.
|
static void |
runDefaultErrorHandling(DSResponse response,
DSRequest request)
Runs the default error handling normally performed by
HandleErrorCallback.handleError() . |
static void |
send(com.google.gwt.core.client.JavaScriptObject data,
RPCCallback callback,
java.util.Map requestParams)
This method is a convenience wrapper on RPCManager.sendRequest() - it calls through to sendRequest().
|
static void |
send(com.google.gwt.core.client.JavaScriptObject data,
RPCCallback callback,
RPCRequest requestParams)
This method is a convenience wrapper on RPCManager.sendRequest() - it calls through to sendRequest().
|
static void |
send(java.lang.String data,
RPCCallback callback,
java.util.Map requestParams)
This method is a convenience wrapper on RPCManager.sendRequest() - it calls through to sendRequest().
|
static void |
send(java.lang.String data,
RPCCallback callback,
RPCRequest requestParams)
This method is a convenience wrapper on RPCManager.sendRequest() - it calls through to sendRequest().
|
static void |
sendProxied(RPCRequest request,
RPCCallback callback)
Send an HTTP request to a remote host, potentially through the HttpProxy servlet installed on the Smart GWT Server.
|
static void |
sendQueue()
Send all currently queued requests to the server.
|
static void |
sendQueue(RPCQueueCallback callback)
Send all currently queued requests to the server.
|
static void |
sendRequest(RPCRequest rpcRequestProperties)
Send the passed RPCRequest to the server.
|
static void |
sendRequest(RPCRequest rpcRequestProperties,
RPCCallback callback)
Send the passed RPCRequest to the server.
|
static void |
setActionURL(java.lang.String actionURL)
Specifies the default URL for RPCRequests and DSRequests that do not specify a URL.
|
static void |
setAllowCrossDomainCalls(java.lang.Boolean allowCrossDomainCalls)
By default Smart GWT will show a warning message on attempted requests to another domain as this is usually not
supported at the browser level by default due to security considerations.
|
static void |
setAllowIE9Leak(boolean allowLeak)
In Internet Explorer 9, when a string of
JavaScript is evaluated via the native
eval() function, objects created
within that evaluation are not released from browser memory until the page is
reloaded. |
static void |
setCredentialsURL(java.lang.String credentialsURL)
Specifies URL where credentials should be submitted to attempt relogin when session timeout is encountered during a
background RPC.
|
static void |
setDefaultPrompt(java.lang.String defaultPrompt)
If showPrompt is enabled for a given transaction, this is the defaultPrompt to be shown to the user in a modal dialog
while the transaction occurs.
|
static void |
setDefaultTimeout(double defaultTimeout)
In milliseconds, how long the RPCManager waits for an RPC request to complete before returning an error.
|
static void |
setFetchDataPrompt(java.lang.String fetchDataPrompt)
Default prompt displayed to the user while an operation is running to fetch data from the server.
|
static void |
setHandleErrorCallback(HandleErrorCallback callback)
handleError() will be called if RPCResponse.status is
negative and RPCRequest.willHandleError was not set. |
static void |
setHandleTransportErrorCallback(HandleTransportErrorCallback callback)
Sets callback to handle server error responses for submitted transactions.
|
static void |
setLoginRequiredCallback(LoginRequiredCallback callback)
Called when a session timeout is encountered while trying to do a background RPC.
|
static void |
setLoginRequiredMarker(java.lang.String loginRequiredMarker)
Marker the system will look for in order to detect when login is required.
|
static void |
setLoginStatusCodeMarker(java.lang.String loginStatusCodeMarker)
String sequence which marks the response as a one which contains login status information.
|
static void |
setLoginSuccessMarker(java.lang.String loginSuccessMarker)
Marker the system will look for in order to detect when login was successfull.
|
static java.lang.String |
setMaxLoginAttemptsExceededMarker(java.lang.String maxLoginAttemptsExceededMarker)
Set the marker the system will look for in order to detect when the number of maximum logins was exceeded.
|
static void |
setPromptCursor(java.lang.String promptCursor)
Controls the default cursor shown when RPCManager.promptStyle is set to "cursor".
|
static void |
setPromptStyle(PromptStyle promptStyle)
Controls the default prompt style.
|
static void |
setQueueSentCallback(QueueSentCallback callback)
This method is called by the RPCManager every time it sends a queue of requests to the server (note that if you are not
using queuing, the system simply sends queues containing just one request, so this API is valid regardless).
|
static void |
setRemoveDataPrompt(java.lang.String removeDataPrompt)
Default prompt displayed to user while an operation is running to remove data from the server.
|
static void |
setSaveDataPrompt(java.lang.String saveDataPrompt)
Default prompt displayed to the user while an operation is running to save data to the server.
|
static void |
setShowPrompt(boolean showPrompt)
If set to
true , the RPCManager will block the UI with a modal dialog containing the text from
RPCManager.defaultPrompt (or the per-RPCRequest override) until the RPC to the server completes. |
static void |
setTimeoutErrorMessage(java.lang.String timeoutErrorMessage)
Default message displayed to user when an operation fails to return from the server within the timeout period specified
by
defaultTimeout . |
static void |
setUseCursorTracking(boolean useCursorTracking)
If true, an image is shown to the right of the cursor when RPCRequest.promptStyle is set to "cursor", otherwise the cursor itself is modified via css to the value of RPCRequest.promptCursor.
|
static void |
setUseHttpProxy(java.lang.Boolean useHttpProxy)
Whether the
HttpProxyServlet should be used in order to get around the
"same origin policy" that prevents web pages from contacting other sites. |
static boolean |
startQueue()
Start queuing
DSRequests and RPCRequests system-wide, for later sending when RPCManager.sendQueue() is called, at which time all queued requests
will be sent as a single, combined HTTP request. |
static boolean |
startQueue(boolean shouldQueue)
Start queuing
DSRequests and RPCRequests system-wide, for later sending when RPCManager.sendQueue() is called, at which time all queued requests
will be sent as a single, combined HTTP request. |
static void |
suspendTransaction()
Suspends the current transaction, such that all processing of the transaction is halted, any remaining
callback in the
transaction won't fire, and the transaction can never timeout . |
static void |
suspendTransaction(int transactionID)
Suspends the current transaction, such that all processing of the transaction is halted, any remaining
callback in
the transaction won't fire, and the transaction can never timeout . |
static void |
suspendTransaction(java.lang.String transactionID)
Deprecated.
please use int methods when dealing with transaction number.
|
static java.lang.Boolean |
xmlHttpRequestAvailable()
Returns true if the XMLHttpRequest object is available, false otherwise.
|
public static final java.lang.String ALL_GLOBALS
loadScreen(String, LoadScreenCallback, String[])
API.public static void setActionURL(java.lang.String actionURL)
URLs can be set on a per-request
basis via RPCRequest.actionURL
, or on a per-DataSource or
per-operationType basis via DataSource.dataURL
and OperationBinding.dataURL
respectively. However, note that in
order to be able to make use of queuing
, you should have all data
loading and saving requests go to a single URL unless you are forced to use distinct URLs by legacy services.
The
primary use case for setting the default actionURL
is to add a CSRF / XSRF (Cross-site Request Forgery) token.
Assuming you are using a single URL for all data requests as covered above, adding a CSRF token to the default
actionURL
as a simple HTTP parameter will cause the CSRF token to be included in all RPCRequests and
DSRequests from all DataSources without further effort.
If the actionURL
is changed while transactions
are suspended, any suspended transactions whose actionURL
was defaulted to this property (e.g. because
RPCRequest.actionURL
wasn't set) will be updated to have the new
actionURL
.
actionURL
- new actionURL. Default value is RPCManager.actionURL.public static java.lang.String getActionURL()
URLs can be set on a per-request
basis via RPCRequest.actionURL
, or on a per-DataSource or
per-operationType basis via DataSource.dataURL
and OperationBinding.dataURL
respectively. However, note that in
order to be able to make use of queuing
, you should have all data
loading and saving requests go to a single URL unless you are forced to use distinct URLs by legacy services.
The
primary use case for setting the default actionURL
is to add a CSRF / XSRF (Cross-site Request Forgery) token.
Assuming you are using a single URL for all data requests as covered above, adding a CSRF token to the default
actionURL
as a simple HTTP parameter will cause the CSRF token to be included in all RPCRequests and
DSRequests from all DataSources without further effort.
If the actionURL
is changed while transactions
are suspended, any suspended transactions whose actionURL
was defaulted to this property (e.g. because
RPCRequest.actionURL
wasn't set) will be updated to have the new
actionURL
.
public static void setAllowCrossDomainCalls(java.lang.Boolean allowCrossDomainCalls)
Some browsers now do support cross domain
requests through the use of Http Access Control headers (See the W3C Cross-Origin Resource Sharing recommendation). If your application intends to rely on this
behavior to perform cross-domain requests, you can set allowCrossDomainCalls
to true to disable the
standard Smart GWT warning when such calls occur.
Note also that this is typically not an issue if you are using
the Smart GWT server (part of Pro, Power and Enterprise editions of Smart GWT), as this includes the HTTPProxy servlet
.
allowCrossDomainCalls
- new allowCrossDomainCalls. Default value is false.public static void setCredentialsURL(java.lang.String credentialsURL)
Relogin
credentialsURL
- new credentialsURL. Default value is http://localhost:8080/isomorphic/login/loginSuccessMarker.html.public static java.lang.String getCredentialsURL()
Relogin
public static void setLoginRequiredMarker(java.lang.String loginRequiredMarker)
The default loginRequired marker should
generally not be customized. It is designed to be safe to insert into any HTML page or other server response
without affecting display or functionality, for example, within an HTML comment. You should *only* customize the
loginRequiredMarker
if you have absolutely no ability to change the response that the server will send when
login is required.
If you do customize the loginRequiredMarker
, then the loginRequiredMarker, loginSuccessMarker
and maxLoginAttemptsExceededMarker
should all start with
the loginStatusCodeMarker
. If they do not, there will
be a small impact on performance as every response must be separately scanned for each marker, instead of just scanning
once for the loginStatusCodeMarker
.
In addition,
the loginStatusCodeMarker
should ideally contain text
that could not possibly validly appear as a data value in a normal response, since if that were possible, end users
could enter the loginRequiredMarker as a data value and cause Smart GWT to falsely detect session timeout when handling
an ordinary data response. This is why the default marker has characters that make it impossible for it to be validly
interpreted as a JavaScript String, XML document or HTML content - there is no way that an end user could enter this as
a data value in an application and have it appear verbatim in a server response.
loginRequiredMarker
- new loginRequiredMarker. Default value is <SCRIPT>//'\"]]>>isc_loginRequired.public static java.lang.String getLoginRequiredMarker()
The default loginRequired marker should
generally not be customized. It is designed to be safe to insert into any HTML page or other server response
without affecting display or functionality, for example, within an HTML comment. You should *only* customize the
loginRequiredMarker
if you have absolutely no ability to change the response that the server will send when
login is required.
If you do customize the loginRequiredMarker
, then the loginRequiredMarker, loginSuccessMarker
and maxLoginAttemptsExceededMarker
should all start with
the loginStatusCodeMarker
. If they do not, there will
be a small impact on performance as every response must be separately scanned for each marker, instead of just scanning
once for the loginStatusCodeMarker
.
In addition,
the loginStatusCodeMarker
should ideally contain text
that could not possibly validly appear as a data value in a normal response, since if that were possible, end users
could enter the loginRequiredMarker as a data value and cause Smart GWT to falsely detect session timeout when handling
an ordinary data response. This is why the default marker has characters that make it impossible for it to be validly
interpreted as a JavaScript String, XML document or HTML content - there is no way that an end user could enter this as
a data value in an application and have it appear verbatim in a server response.
public static void setLoginStatusCodeMarker(java.lang.String loginStatusCodeMarker)
loginStatusCodeMarker
- new loginStatusCodeMarker. Default value is <SCRIPT>//'\"]]>>isc_.public static java.lang.String getLoginStatusCodeMarker()
public static void setLoginSuccessMarker(java.lang.String loginSuccessMarker)
loginSuccessMarker
- new loginSuccessMarker. Default value is <SCRIPT>//'\"]]>>isc_loginSuccess.public static java.lang.String getLoginSuccessMarker()
public static void setShowPrompt(boolean showPrompt)
true
, the RPCManager will block the UI with a modal dialog containing the text from
RPCManager.defaultPrompt (or the per-RPCRequest override) until the RPC to the server completes. If set to
false
, the RPC happens transparently, allowing the user to continue interacting with the UI.
DataSource
requests, which are a particular type of RPCRequest, are controlled by the more-specific DataSource-level setting DataSource.showPrompt
.
showPrompt
- new showPrompt. Default value is RPCManager.showPrompt.public static void setTimeoutErrorMessage(java.lang.String timeoutErrorMessage)
defaultTimeout
.timeoutErrorMessage
- new timeoutErrorMessage. Default value is "Operation timed out".public static void setUseHttpProxy(java.lang.Boolean useHttpProxy)
HttpProxyServlet
should be used in order to get around the
"same origin policy" that prevents web pages from contacting other sites. Default behavior is to use the
HttpProxyServlet whenever a URL appears to be pointing to another site. Set RPCRequest.useHttpProxy
false to have a particular request avoid
using the HttpProxyServlet even when it appears to be necessary, or set RPCManager.useHttpProxy
to false to
avoid ever attempting to use the HttpProxyServlet.
useHttpProxy
- new useHttpProxy. Default value is true.public static void cacheScreens(java.lang.String[] screenName, Function callback)
Component XML
format,
using the ScreenLoaderServlet
. Unlike loadScreen()
, cacheScreens()
does not cause any UI
components to be created or drawn, it just loads the definitions of the screens. This allows a subsequent, synchronous
call to createScreen()
to create the actual screen, rather than
contacting the ScreenLoader
servlet and showing a loading message.
See loadScreen()
for the meaning of the locale
parameter.
Calling cacheScreens
twice with the same screenName will re-load the definition of that screen from the
server such that subsequent calls to createScreen()
will use the new definition.
screenName
- name of the screens to cachecallback
- callback for notification of screens being successfully cachedpublic static void cacheScreens(java.lang.String[] screenName, Function callback, java.lang.String locale)
public static void cacheScreens(java.lang.String[] screenName, Function callback, java.lang.String locale, RPCRequest requestProperties)
Component XML
format,
using the ScreenLoaderServlet
. Unlike loadScreen()
, cacheScreens()
does not cause any UI
components to be created or drawn, it just loads the definitions of the screens. This allows a subsequent, synchronous
call to createScreen()
to create the actual screen, rather than
contacting the ScreenLoader
servlet and showing a loading message.
See loadScreen()
for the meaning of the locale
parameter.
Calling cacheScreens
twice with the same screenName will re-load the definition of that screen from the
server such that subsequent calls to createScreen()
will use the new definition.
screenName
- name of the screens to cachecallback
- callback for notification of screens being successfully cachedlocale
- The name of a locale to use for resolving i18n tags in the component XML of the screenrequestProperties
- optional properties for the requestpublic static void cancelQueue()
If a transactionId is passed, that transaction will be
cancelled, otherwise, the current (not yet sent) transaction is cancelled. You can retrieve the id of the current
transaction, if there is one, by calling getQueueTransactionId()
before the transaction has been sent.
Note that cancelQueue() calls clearTransaction()
and attempts to abort the request. However,
note also that whilst cancelling a transaction that has already been sent will not necessarily stop the HTTP request
that has been issued - this is only possible on some browsers and with some transports - it will reliably cause Smart
GWT to ignore any response returned by the server and not fire any callbacks that have been passed in.
Also, take
into account that this method removes all queued requests from the current queue, but queueing is still active, so if
you also want to disable queuing you should call startQueue(false)
.
public static void cancelQueue(int transactionNum)
If a transactionId is passed, that transaction will be
cancelled, otherwise, the current (not yet sent) transaction is cancelled. You can retrieve the id of the current
transaction, if there is one, by calling getQueueTransactionId()
before the transaction has been sent.
Note that cancelQueue() calls clearTransaction()
and attempts to abort the request. However,
note also that whilst cancelling a transaction that has already been sent will not necessarily stop the HTTP request
that has been issued - this is only possible on some browsers and with some transports - it will reliably cause Smart
GWT to ignore any response returned by the server and not fire any callbacks that have been passed in.
Also, take
into account that this method removes all queued requests from the current queue, but queueing is still active, so if
you also want to disable queuing you should call startQueue(false)
.
transactionNum
- transactionId of the queue.public static void clearTransaction(int transactionNum)
A transaction
means a batch of one or more RPCRequests that have already been sent to the server via sendQueue()
.
You can retrieve the id of the current transaction, if
there is one, by getQueueTransactionId()
before the
transaction is sent.
transactionNum
- id of the transaction to be clearedpublic static void exportContent(Canvas canvas)
As with other exports, the resulting file can be
saved to the server filesystem
instead of, or in
addition to being downloaded to the user. See server-side docs for
com.isomorphic.contentexport.PdfExport for more details on server-side processing and
code samples for redirecting PDF output to a file or in-memory buffer, as well as
instructions for adding additional stylesheets.
You can either pass any Canvas
to exportContent
, or you can
pass HTML that you have retrieved by calling Canvas.getPrintHTML()
. When
calling getPrintHTML()
to retrieve HTML for use with
exportContent()
, you must pass the PrintProperties.printForExport
or DrawPane
and FacetChart
instances will not export properly.
You can use a custom skin when exporting your HTML content. To use a custom skin,
add a line to server.properties
:
skin.{skinName}.location: custom/skinWhere {skinName} is the name of your custom skin, and the value is the path to your skin resources from the application webroot.
Requires the Smart GWT server framework, but does not require use of server-based databinding - no .ds.xml files need to exist.
You can also inject a small amount of CSS from the browser via
DSRequest.exportCSS
- this is intended primarily for switching
the page size on
the fly, for exceptionally wide or tall exports.
canvas
- Canvas or canvas list that has exportable widgets, or an HTML fragment derived from getPrintHTML()
public static void exportContent(Canvas[] canvas)
As with other exports, the resulting file can be
saved to the server filesystem
instead of, or in
addition to being downloaded to the user. See server-side docs for
com.isomorphic.contentexport.PdfExport for more details on server-side processing and
code samples for redirecting PDF output to a file or in-memory buffer, as well as
instructions for adding additional stylesheets.
You can either pass any Canvas
to exportContent
, or you can
pass HTML that you have retrieved by calling Canvas.getPrintHTML()
. When
calling getPrintHTML()
to retrieve HTML for use with
exportContent()
, you must pass the PrintProperties.printForExport
or DrawPane
and FacetChart
instances will not export properly.
You can use a custom skin when exporting your HTML content. To use a custom skin,
add a line to server.properties
:
skin.{skinName}.location: custom/skinWhere {skinName} is the name of your custom skin, and the value is the path to your skin resources from the application webroot.
Requires the Smart GWT server framework, but does not require use of server-based databinding - no .ds.xml files need to exist.
You can also inject a small amount of CSS from the browser via
DSRequest.exportCSS
- this is intended primarily for switching
the page size on
the fly, for exceptionally wide or tall exports.
canvas
- Canvas or canvas list that has exportable widgets, or an HTML fragment derived from getPrintHTML()
public static void exportContent(java.lang.String canvas)
As with other exports, the resulting file can be
saved to the server filesystem
instead of, or in
addition to being downloaded to the user. See server-side docs for
com.isomorphic.contentexport.PdfExport for more details on server-side processing and
code samples for redirecting PDF output to a file or in-memory buffer, as well as
instructions for adding additional stylesheets.
You can either pass any Canvas
to exportContent
, or you can
pass HTML that you have retrieved by calling Canvas.getPrintHTML()
. When
calling getPrintHTML()
to retrieve HTML for use with
exportContent()
, you must pass the PrintProperties.printForExport
or DrawPane
and FacetChart
instances will not export properly.
You can use a custom skin when exporting your HTML content. To use a custom skin,
add a line to server.properties
:
skin.{skinName}.location: custom/skinWhere {skinName} is the name of your custom skin, and the value is the path to your skin resources from the application webroot.
Requires the Smart GWT server framework, but does not require use of server-based databinding - no .ds.xml files need to exist.
You can also inject a small amount of CSS from the browser via
DSRequest.exportCSS
- this is intended primarily for switching
the page size on
the fly, for exceptionally wide or tall exports.
canvas
- Canvas or canvas list that has exportable widgets, or an HTML fragment derived from getPrintHTML()
HTMLString
public static void exportContent(Canvas canvas, DSRequest requestProperties)
As with other exports, the resulting file can be
saved to the server filesystem
instead of, or in
addition to being downloaded to the user. See server-side docs for
com.isomorphic.contentexport.PdfExport for more details on server-side processing and
code samples for redirecting PDF output to a file or in-memory buffer, as well as
instructions for adding additional stylesheets.
You can either pass any Canvas
to exportContent
, or you can
pass HTML that you have retrieved by calling Canvas.getPrintHTML()
. When
calling getPrintHTML()
to retrieve HTML for use with
exportContent()
, you must pass the PrintProperties.printForExport
or DrawPane
and FacetChart
instances will not export properly.
You can use a custom skin when exporting your HTML content. To use a custom skin,
add a line to server.properties
:
skin.{skinName}.location: custom/skinWhere {skinName} is the name of your custom skin, and the value is the path to your skin resources from the application webroot.
Requires the Smart GWT server framework, but does not require use of server-based databinding - no .ds.xml files need to exist.
You can also inject a small amount of CSS from the browser via
DSRequest.exportCSS
- this is intended primarily for switching
the page size on
the fly, for exceptionally wide or tall exports.
canvas
- Canvas or canvas list that has exportable widgets, or an HTML fragment derived from getPrintHTML()
requestProperties
- Request properties for the export to pdf objectpublic static java.lang.Integer getQueueTransactionId()
This method will return null if no requests are
currently queued, even if startQueue()
has been called.
public static void setHandleErrorCallback(HandleErrorCallback callback)
handleError()
will be called if RPCResponse.status
is
negative and RPCRequest.willHandleError
was not set. It
is called for both DSResponse
s and RPCResponse
s that
have a non-success status. You can check whether the response is a DSResponse by checking
response.isDSResponse
. By default handleError()
always logs a warning. In addition, if
response.data
was set to a String, a warning dialog will be shown to
the user with response.data as the message, which allows the server to send user error messages back without writing
custom client-side error handling.
To do custom error handling that is specific to a particular component or type of
request, set RPCRequest.willHandleError
and deal with
errors in the rpcRequest.callback. To change the default system-wide error handling, install a HandleErrorCallback
with this method. To invoke the default
error handling in your new handler, you can simply call the method runDefaultErrorHandling()
.
If you're using the
xmlHttpRequest RPCRequest.transport
, you can access the HTTP status code of the response (eg
404 Not Found or 500 Server Error) as RPCResponse.httpResponseCode
.
For very advanced usage, the response.xmlHttpRequest contains the native
XMLHttpRequest object used to make the request. This can be accessed via DSResponse.getAttributeAsJavaScriptObject()
.
Accessing this object is subject to possible cross-platform bugs and inconsistencies, and Isomorphic recommends that you
wrap any access to the XMLHttpRequest object in a try/catch block because some browsers may throw exceptions when
certain attributes of this object are accessed. For example, if you try to access XMLHttpRequest.status (for the HTTP
status code) when the network cable is unpluged in Windows, you'll get an Exception in Firefox.
See the overview of error handling
for additional guidance.
callback
- HandleErrorCallback the callback to set.ErrorEvent
,
HandleTransportErrorCallback.handleTransportError(int, int, int, java.lang.String)
,
runDefaultErrorHandling(com.smartgwt.client.data.DSResponse, com.smartgwt.client.data.DSRequest)
public static java.lang.Boolean hasCurrentTransactionQueued()
This method will return false if no requests are
currently queued, even if startQueue()
has been called.
public static void setLoginRequiredCallback(LoginRequiredCallback callback)
Relogin
. The transaction with the passed transactionId
is suspended,
and should either be cleared
or resent
after the user has been re-authenticated.
The
rpcRequest
parameter can be used to determine whether the suspended transaction can simply be dropped (eg,
it's periodic polling request).
The rpcResponse
parameter has rpcResponse.data set to the raw text of
the response that triggered loginRequired()
. Some very advanced relogin strategies may need to inspect the
raw response to get information needed for re-authentication.
callback
- LoginRequiredCallback the callback to set.public static void setQueueSentCallback(QueueSentCallback callback)
There is
no default implementation of this method; it is simply an override point. It is intended to be used by user code that
needs to be notified when Smart GWT sends requests to the server. Note that the list of RPCRequest
s passed to this method is strictly read-only.
callback
- QueueSentCallback the callback to set.public static java.lang.Boolean requestsArePending()
public static void resendTransaction()
suspendTransaction()
for context. Note that the transaction must have been previously suspended, and in
particular suspended validly according to the rules described in the docs for suspendTransaction()
, or undefined results will occur.
You
can resend all suspended transactions by calling resendTransaction()
with no arguments.
public static void resendTransaction(int transactionNum)
suspendTransaction()
for context. Note that the transaction must have been previously suspended, and in
particular suspended validly according to the rules described in the docs for suspendTransaction()
, or undefined results will occur.
You
can resend all suspended transactions by calling resendTransaction()
with no arguments.
transactionNum
- id of the transaction to be re-sent, or null to resend all suspended transactionspublic static void runDefaultErrorHandling(DSResponse response, DSRequest request)
HandleErrorCallback.handleError()
. May be called from a custom handler to achieve the default behavior if one has been
installed.response
- response the responserequest
- request the requestHandleErrorCallback.handleError(com.smartgwt.client.data.DSResponse, com.smartgwt.client.data.DSRequest)
public static void sendQueue()
This method will do nothing and the callback will not be
called if no requests have actually been queued. You can detect whether the queue is empty by calling getQueueTransactionId()
.
NOTE: if you aren't the caller who first enables queuing (startQueue() returns true), you should in general avoid calling sendQueue(), because whoever was first to enable queuing may have more requests to add to the same queue.
See startQueue()
for more information about queuing.
public static void sendQueue(RPCQueueCallback callback)
This method will do nothing and the callback will not be
called if no requests have actually been queued. You can detect whether the queue is empty by calling getQueueTransactionId()
.
NOTE: if you aren't the caller who first enables queuing (startQueue() returns true), you should in general avoid calling sendQueue(), because whoever was first to enable queuing may have more requests to add to the same queue.
See startQueue()
for more information about queuing.
callback
- Callback to fire when the queued operations complete. Callback will be fired with 1 parameter: responses
an
array of DSResponse
or RPCResponse
objects that were
part of the transaction fired by this method.send(java.lang.String, com.smartgwt.client.rpc.RPCCallback, com.smartgwt.client.rpc.RPCRequest)
,
sendRequest(com.smartgwt.client.rpc.RPCRequest)
,
startQueue()
public static boolean startQueue()
DSRequests
and RPCRequests
system-wide, for later sending when RPCManager.sendQueue() is called, at which time all queued requests
will be sent as a single, combined HTTP request. Combining requests via queuing:
Queuing is used automatically by many, many framework features, including multi-row grid editing
(Grid Mass Editing
), multi-row drag & drop,
data paging for large trees
, "serverCustom" validators
, Master-Detail saves,
OLAP / datacube functionalty
, and many others.
Queuing also has subtler architectural benefits in terms of building reusable services - see the QuickStart Guide sections on Queuing for details.
For all the reasons given above, it's extremely important to use DataSources that can support queuing.
Queuing is automatically supported when using server-based DataSources with the Smart GWT Server Framework, and is
supported by RestDataSource
.
Order of Execution
When the Smart GWT
Server framework receives a queued request, it will process all requests, in order, in a single thread, before any
response is sent to the client. All client-side actions related to queued requests, such as callbacks firing
on completion, likewise happen in queue order,
after all server-side processing has taken place.
Therefore when using queuing you can use the callback argument of
sendQueue()
to detect that all operations have completed, which is
much simpler than the logic needed to track multiple asynchronous operations and wait for all to complete.
Nested Queuing
In some cases you may wish to combine requests being sent by application logic with queued requests
automatically sent by components. For example, you may want to call ListGrid.saveAllEdits()
but also add an additional request to
the same queue.
To do this, just call startQueue()
before saveAllEdits()
(or whatever
other API would also normally perform a queued request), then call sendQueue()
. Framework features that
use queuing will automatically notice that you have already started a queue, and will not automatically call
sendQueue()
in this case. You can implement the same behavior in your own reusable components by checking
the return value of startQueue()
, which tells you whether queuing is already active.
Requests that can't be queued
When using queuing, all requests in a given queue must go to the same RPCRequest.actionURL
and use the same transport (XMLHttp or frames).
If a request specifies a different actionURL or transport than that of the requests currently on the queue, it will be
sent to the server separately, ahead of the queue, and a warning will be logged to the Developer Console.
Due to
browser security restrictions, at most one request with a file\n
upload
can be sent in a queue. If you attempt to add another, the existing queue will be sent immediately, logging a
warning, and queueing restarted for the new request.
Note that whenever requests are not sent in a single queue,
order is not guaranteed, and the callback provided to sendQueue()
at the end of your transaction may fire before requests not sent in the final queue have completed.
Implementing your own Queuing
If you are in the rare situation that:
dataProtocol:"clientCustom"
to avoid HTTP requests
being immediately sent when a DataSource executes. In outline: startQueue()
for managing a global setting reflecting whether your special queuing system is active.
Your DataSources should check for this global setting in DataSource.transformRequest()
, and, if queuing is active,
store the request you received in DataSource.transformRequest()
in memory, for example in an Array RPCManager.sendQueue()
which sends an HTTP request representing your combined requests, then once you
receive your combined response, call DataSource.processResponse()
for each request. RPCManager
's
queuing system doesn't really make sense - RPCManager
won't be aware of your separate, special queue of
requests, so will reject calls to sendQueue()
since RPCManager's queue is empty. Similarly, enabling
queuing on RPCManager
may cause inadvertent queuing of unrelated requests you did not intend to queue.
Maintaining your own separate notion of whether queuing is active is simpler and less error prone.sendQueue()
public static boolean startQueue(boolean shouldQueue)
DSRequests
and RPCRequests
system-wide, for later sending when RPCManager.sendQueue() is called, at which time all queued requests
will be sent as a single, combined HTTP request. Combining requests via queuing:
Queuing is used automatically by many, many framework features, including multi-row grid editing
(Grid Mass Editing
), multi-row drag & drop,
data paging for large trees
, "serverCustom" validators
, Master-Detail saves,
OLAP / datacube functionalty
, and many others.
Queuing also has subtler architectural benefits in terms of building reusable services - see the QuickStart Guide sections on Queuing for details.
For all the reasons given above, it's extremely important to use DataSources that can support queuing.
Queuing is automatically supported when using server-based DataSources with the Smart GWT Server Framework, and is
supported by RestDataSource
.
Order of Execution
When the Smart GWT
Server framework receives a queued request, it will process all requests, in order, in a single thread, before any
response is sent to the client. All client-side actions related to queued requests, such as callbacks firing
on completion, likewise happen in queue order,
after all server-side processing has taken place.
Therefore when using queuing you can use the callback argument of
sendQueue()
to detect that all operations have completed, which is
much simpler than the logic needed to track multiple asynchronous operations and wait for all to complete.
Nested Queuing
In some cases you may wish to combine requests being sent by application logic with queued requests
automatically sent by components. For example, you may want to call ListGrid.saveAllEdits()
but also add an additional request to
the same queue.
To do this, just call startQueue()
before saveAllEdits()
(or whatever
other API would also normally perform a queued request), then call sendQueue()
. Framework features that
use queuing will automatically notice that you have already started a queue, and will not automatically call
sendQueue()
in this case. You can implement the same behavior in your own reusable components by checking
the return value of startQueue()
, which tells you whether queuing is already active.
Requests that can't be queued
When using queuing, all requests in a given queue must go to the same RPCRequest.actionURL
and use the same transport (XMLHttp or frames).
If a request specifies a different actionURL or transport than that of the requests currently on the queue, it will be
sent to the server separately, ahead of the queue, and a warning will be logged to the Developer Console.
Due to
browser security restrictions, at most one request with a file\n
upload
can be sent in a queue. If you attempt to add another, the existing queue will be sent immediately, logging a
warning, and queueing restarted for the new request.
Note that whenever requests are not sent in a single queue,
order is not guaranteed, and the callback provided to sendQueue()
at the end of your transaction may fire before requests not sent in the final queue have completed.
Implementing your own Queuing
If you are in the rare situation that:
dataProtocol:"clientCustom"
to avoid HTTP requests
being immediately sent when a DataSource executes. In outline: startQueue()
for managing a global setting reflecting whether your special queuing system is active.
Your DataSources should check for this global setting in DataSource.transformRequest()
, and, if queuing is active,
store the request you received in DataSource.transformRequest()
in memory, for example in an Array RPCManager.sendQueue()
which sends an HTTP request representing your combined requests, then once you
receive your combined response, call DataSource.processResponse()
for each request. RPCManager
's
queuing system doesn't really make sense - RPCManager
won't be aware of your separate, special queue of
requests, so will reject calls to sendQueue()
since RPCManager's queue is empty. Similarly, enabling
queuing on RPCManager
may cause inadvertent queuing of unrelated requests you did not intend to queue.
Maintaining your own separate notion of whether queuing is active is simpler and less error prone.shouldQueue
- whether queuing should be enabled, default true. Passing false will disable queuing but not send
the queue yet, so that any queued requests will be sent along with the next
send()/sendRequest()sendQueue()
public static java.lang.Boolean xmlHttpRequestAvailable()
PlatformDependencies
for more information on when XMLHttpRequest parser may not available and
what features are impacted as a result.public static void getMaxLoginAttemptsExceededMarker()
com.smartgwt.client.rpc.RPCManager#setLoginRequiredMarker()
public static java.lang.String setMaxLoginAttemptsExceededMarker(java.lang.String maxLoginAttemptsExceededMarker)
loginSuccessMarker
- default value <SCRIPT>//'\"]]>>isc_maxLoginAttemptsExceededcom.smartgwt.client.rpc.RPCManager#setLoginRequiredMarker()
public static void setDefaultTimeout(double defaultTimeout)
In milliseconds, how long the RPCManager waits for an RPC request to complete before returning an error. If set to zero, the RPCManager will not enforce a timeout, but note that most browsers enforce their own timeouts on HTTP requests.
For the "xmlHttpRequest" transport, this timeout can only happen if the server actually fails to respond within the specified number of milliseconds. For the "hiddenFrames" transport, this timeout will occur for non-200 (HTTP_OK) responses.
defaultTimeout
- the default value is 240000 [4 minutes]public static void setDefaultPrompt(java.lang.String defaultPrompt)
defaultPrompt
- the default value is 'Contacting Server...'public static void setFetchDataPrompt(java.lang.String fetchDataPrompt)
fetchDataPrompt
- defaults to "Finding Records that match your criteria..."public static void setRemoveDataPrompt(java.lang.String removeDataPrompt)
removeDataPrompt
- default value "Deleting Record(s)..."public static void setSaveDataPrompt(java.lang.String saveDataPrompt)
saveDataPrompt
- default value "Saving form..."public static void setPromptCursor(java.lang.String promptCursor)
promptCursor
- default is browser dependentpublic static void setPromptStyle(PromptStyle promptStyle)
promptStyle
- default is PromptStyle.DIALOG
public static void setUseCursorTracking(boolean useCursorTracking)
useCursorTracking
- default value is platform-dependentpublic static void cancelQueue(java.lang.String transactionNum)
If a transactionId is passed, that transaction will be
cancelled, otherwise, the current (not yet sent) transaction is cancelled. You can retrieve the id of the current
transaction, if there is one, by calling getCurrentTransactionId()
before the transaction has been sent.
Note that cancelQueue() calls clearTransaction()
and attempts to abort the request. However,
note also that whilst cancelling a transaction that has already been sent will not necessarily stop the HTTP request
that has been issued - this is only possible on some browsers and with some transports - it will reliably cause Smart
GWT to ignore any response returned by the server and not fire any callbacks that have been passed in.
transactionNum
- transactionId of the queue.public static void clearTransaction(java.lang.String transactionNum)
A transaction
means a batch of one or more RPCRequests that have already been sent to the server via RPCManager.sendQueue
.
You can retrieve the id of the current
transaction, if there is one, by getCurrentTransactionId()
before the transaction is sent.
transactionNum
- id of the transaction to be clearedpublic static void resendTransaction(java.lang.String transactionNum)
RPCManager.suspendTransaction
for context. Note that the transaction must have been previously suspended, and in
particular suspended validly according to the rules described in the docs for RPCManager.suspendTransaction
, or undefined results will occur.
You can resend all suspended transactions by calling RPCManager.resendTransaction
with no arguments.
transactionNum
- id of the transaction to be re-sent, or null to resend all suspended transactionspublic static void suspendTransaction()
callback
in the
transaction won't fire, and the transaction can never timeout
. suspendTransaction()
is typically used
to handle total failures for an entire transaction, such as HTTP status 500, or session timeout resulting in com.smartgwt.client.rpc.RPCManager#loginRequired
being
called. In both cases the intent is to put the transaction on hold so that a transient problem can be resolved, and then the transaction can be re-sent successfully.
By using suspendTransaction(), components that submitted requests never realize there was a transient failure, and so error handling logic does not have to be implemented
in every component.
Generally you can only validly suspend a transaction from either com.smartgwt.client.rpc.RPCManager#loginRequired
or
com.smartgwt.client.rpc.RPCManager#handleError
, and in the case of handleError(), only when the first response in the transaction has an error.
Suspending and re-sending a partially processed transaction means that some responses will be processed twice, with undefined results for requests issued
automatically by UI components.
A suspended transaction must ultimately be either cleared via clearTransaction(int)
or re-sent via resendTransaction()
or memory will be leaked.
public static void suspendTransaction(java.lang.String transactionID)
callback
in
the transaction won't fire, and the transaction can never timeout
. suspendTransaction()
is
typically used to handle total failures for an entire transaction, such as HTTP status 500, or session timeout resulting in com.smartgwt.client.rpc.RPCManager#loginRequired
being called. In both cases the intent is to put the transaction on hold so that a transient problem can be resolved, and then the transaction can be re-sent successfully.
By using suspendTransaction(), components that submitted requests never realize there was a transient failure, and so error handling logic does not have to be implemented
in every component.
Generally you can only validly suspend a transaction from either com.smartgwt.client.rpc.RPCManager#loginRequired
or
com.smartgwt.client.rpc.RPCManager#handleError
, and in the case of handleError(), only when the first response in the transaction has an error. Suspending and re-sending a partially processed transaction means that some responses will be processed twice, with undefined results for requests issued automatically by UI components.
A suspended transaction must ultimately be either cleared via clearTransaction(int)
or re-sent via resendTransaction()
or memory will be leaked.
transactionID
- transaction to delay. Defaults to the current transaction if there is onepublic static void suspendTransaction(int transactionID)
callback
in
the transaction won't fire, and the transaction can never timeout
. suspendTransaction()
is
typically used to handle total failures for an entire transaction, such as HTTP status 500, or session timeout resulting in com.smartgwt.client.rpc.RPCManager#loginRequired
being called. In both cases the intent is to put the transaction on hold so that a transient problem can be resolved, and then the transaction can be re-sent successfully.
By using suspendTransaction(), components that submitted requests never realize there was a transient failure, and so error handling logic does not have to be implemented
in every component.
Generally you can only validly suspend a transaction from either com.smartgwt.client.rpc.RPCManager#loginRequired
or
com.smartgwt.client.rpc.RPCManager#handleError
, and in the case of handleError(), only when the first response in the transaction has an error. Suspending and re-sending a partially processed transaction means that some responses will be processed twice, with undefined results for requests issued automatically by UI components.
A suspended transaction must ultimately be either cleared via clearTransaction(int)
or re-sent via resendTransaction()
or memory will be leaked.
transactionID
- transaction to delay. Defaults to the current transaction if there is onepublic static java.lang.String getCurrentTransactionId()
This method must be called after startQueue() has been called and at least one request has been issued.
public static int getCurrentTransactionIdAsInt()
-1
instead of null
if there's no currently queued requests.public static void sendProxied(RPCRequest request, RPCCallback callback)
This API allows contacting services which are hosted on servers other than the origin server if the HttpProxy servlet is enabled on the Smart GWT Server.
The HttpProxy will be used if the actionURL
starts with "http" and uses a hostname other than "localhost"
or window.location.hostname
, or if the port number differs, or if request.useHttpProxy
is
explicitly set. Otherwise the request goes to the origin server (the server that returned the current page).
The
RPCRequest
properties that will be respected when relaying requests via the HttpProxy
are: actionURL
, httpMethod
, params
, contentType
, httpHeaders
, and data
. In this case "data", if set, will be used as the request body for an HTTP POST.
Higher-level APIs like
DataSource
or WebService
call through this API, and so
automatically use the HttpProxy if dataURL
or webService.location
is set to a foreign server.
This API is only
suitable for direct use when loading unstructured data that will not be shown in a DataBoundComponent
. For a WSDL-described web service, use XMLTools.loadWSDL
instead. For other web services, use a DataSource
with dataURL
, and use DataSource.transformRequest
and DataSource.transformResponse
as necessary to form requests for
the service and transform responses for display.
request
- rpcRequest to be routed through the HttpProxycallback
- callback to invoke on RPC completionpublic static void sendRequest(RPCRequest rpcRequestProperties)
rpcRequestProperties
- RPCRequest to send to the serverpublic static void sendRequest(RPCRequest rpcRequestProperties, RPCCallback callback)
rpcRequestProperties
- RPCRequest to send to the servercallback
- callback to invoke on RPC completionpublic static void send(java.lang.String data, RPCCallback callback, RPCRequest requestParams)
data
- data to be passed to the servercallback
- callback to invoke on RPC completionrequestParams
- any additional properties you want to set - these will be applied to the RPCRequest object that will be auto-created for you.public static void send(java.lang.String data, RPCCallback callback, java.util.Map requestParams)
data
- data to be passed to the servercallback
- callback to invoke on RPC completionrequestParams
- any additional properties you want to set - these will be applied to the RPCRequest object that will be auto-created for you.public static void send(com.google.gwt.core.client.JavaScriptObject data, RPCCallback callback, RPCRequest requestParams)
data
- data to be passed to the servercallback
- callback to invoke on RPC completionrequestParams
- any additional properties you want to set - these will be applied to the RPCRequest object that will be auto-created for you.public static void send(com.google.gwt.core.client.JavaScriptObject data, RPCCallback callback, java.util.Map requestParams)
data
- data to be passed to the servercallback
- callback to invoke on RPC completionrequestParams
- any additional properties you want to set - these will be applied to the RPCRequest object that will be auto-created for you.public static void loadScreen(java.lang.String screenName, LoadScreenCallback callback)
Component XML
format.
See loadScreen(String, LoadScreenCallback, String[], String, RPCRequest)
screenName
- name of the screen to loadcallback
- callback for notification of screen being loadedpublic static void loadScreen(java.lang.String screenName, LoadScreenCallback callback, java.lang.String[] globals)
Component XML
format.
See loadScreen(String, LoadScreenCallback, String[], String, RPCRequest)
screenName
- name of the screen to loadcallback
- callback for notification of screen being loadedglobals
- widgets to allow to take their global IDspublic static void loadScreen(java.lang.String screenName, LoadScreenCallback callback, java.lang.String[] globals, RPCRequest requestProperties)
Component XML
format.
See loadScreen(String, LoadScreenCallback, String[], String, RPCRequest)
screenName
- name of the screen to loadcallback
- callback for notification of screen being loadedglobals
- widgets to allow to take their global IDsrequestProperties
- optional properties for the requestpublic static void loadScreen(java.lang.String screenName, LoadScreenCallback callback, java.lang.String[] globals, java.lang.String locale, RPCRequest requestProperties)
Component XML
format, using the
ScreenLoaderServlet
.
The ScreenLoaderServlet will look for a file named screenName.ui.xml in the directory given by the "project.ui" setting, which defaults webroot/shared/ui and can be configured in server.properties.
The screen
provided by the callback will be the outermost component if your
loaded screen consists of a hierarchy of widgets all contained under one parent (which
is true of any screens created in Visual Builder).
If you have multiple widget hierarchies in your screen, the screen
returned
will be the last top-level component created.
By default, components in the loaded screens that have
global IDs
will not
actually be allowed to take those global IDs - instead, only widgets that have one of the
global IDs passed as the globals
parameter will actually receive their global
IDs. To override this behavior, pass an array containing the special value
ALL_GLOBALS
for the globals
parameter.
When globals are being suppressed, the screen
available in the callback
will provide access to widgets that did not receive their global IDs via
Canvas.getByLocalId(String)
,
and the suppressedGlobals
available in the
callback will be a mapping from suppressed global ID to the widget or other component
that would have used that global ID if globals were not suppressed.
To load multiple screens at once, use
cacheScreens(String[], Function, String, RPCRequest)
and
createScreen(String, String[])
instead.
Components in the screen will default to having
com.smartgwt.client.widgets.Canvas#setAutoDraw(Boolean)
set to false.
This may be overridden by setting the
RPCRequest.setSuppressAutoDraw(Boolean)
attribute
explicitly to false
on the request properties object.
You can optionally provide a locale name to use when resolving any i18n tags in the screen's component XML. If you do not supply this, the locale will be derived from the servlet API, and so will generally be a locale appropriate to the client's operating system settings. Only provide a locale manually if you have a special requirement that requires the user's operating system locale to be overridden in your application. If you provide a locale name, it should be of the form "xx" or "xx_YY", where "xx" is a valid language code and "YY" is a valid country code. For example, "fr" or "en_GB".
This API assumes the ScreenLoaderServlet is installed at the default location - to use a
different location, use the requestProperties
parameter to specify a different
URL via +link{rpcRequest.actionURL}. The requestProperties
parameter can also
be used to pass additional params to a custom ScreenLoaderServlet - see the "Dynamic
Component XML" section of the
Component XML overview
.
screenName
- name of the screen to loadcallback
- callback for notification of screen being loadedglobals
- widgets to allow to take their global IDslocale
- the name of a locale to use for resolving i18n tags in the component XML of the screenrequestProperties
- optional properties for the requestpublic static void setAllowIE9Leak(boolean allowLeak)
eval()
function, objects created
within that evaluation are not released from browser memory until the page is
reloaded.
SmartGWT uses the eval()
function to evaluate JSON formatted
responses to RPCRequests by default, making long running applications potentially
susceptible to memory leaks over time.
Setting this property to false
enables a workaround suggested on the
Microsoft Knowledge Base to
avoid such memory leaks by evaluating script in a hidden iframe and periodically
refresh that frame. However developers should be aware of the following
limitation with this setting: attempting to access certain object types including
Date
or function
objects generated from such an
evaluation can subsequently lead to a JavaScript error with the message
"Can't execute code from a freed script"
.
This workaround therefore may not be suitable for all transactions or dataSources within a given application.
This property may also be specified for specific +link{RPCRequest.allowIE9Leak,RPCRequests}.
Note: This issue is discussed further in the online SmartGWT FAQ.
public static Canvas createScreen(java.lang.String screenName)
cacheScreens(String[], Function, String, RPCRequest)
.
As with loadScreen(String, LoadScreenCallback, String[])
, the default
behavior is to prevent any global widget IDs from
being established, the returned Canvas will be the outermost component of the screen,
and that Canvas will provide access to other widgets in the screen via Canvas.getByLocalId(String)
Alternatively, as with loadScreen(String, LoadScreenCallback, String[])
,
a list of IDs that should be allowed to become
globals can be passed, allowing those widgets to be retrieved via a call to
Canvas.getById(String)
after the screen has been created.
If you do not pass globals
and avoid depending on global IDs within the screen
definition itself (for example, by embedding JavaScript event handlers in the screen definition
that use global IDs), you can create the same screen multiple times.
screenName
- name of the screen to createpublic static Canvas createScreen(java.lang.String screenName, java.lang.String[] globals)
cacheScreens(String[], Function, String, RPCRequest)
.
As with loadScreen(String, LoadScreenCallback, String[])
,
the default behavior is to prevent any global widget IDs from
being established, the returned Canvas will be the outermost component of the screen,
and that Canvas will provide access to other widgets in the screen via Canvas.getByLocalId(String)
Alternatively, as with loadScreen(String, LoadScreenCallback, String[])
,
a list of IDs that should be allowed to become
globals can be passed, allowing those widgets to be retrieved via a call to
Canvas.getById(String)
after the screen has been created.
If you do not pass globals
and avoid depending on global IDs within the screen
definition itself (for example, by embedding JavaScript event handlers in the screen definition
that use global IDs), you can create the same screen multiple times.
screenName
- name of the screen to createglobals
- widgets to allow to take their global IDspublic static void exportContent(Canvas[] components, DSRequest requestProperties)
printable HTML
generated from live UI components
into a .pdf and downloads it ("Save As.." dialog).
For DrawPane
and subclasses (e.g. FacetChart
) to export properly, the canvas
parameter must be the widget itself, not the HTML obtained with getPrintHTML()
unless the PrintProperties
passed to getPrintHTML() had
printForExport
:true.
You can use a custom skin when exporting your HTML content. To use a custom skin, add a line to server.properties:
skin.{skinName}.location: custom/skinWhere {skinName} is the name of your custom skin, and the value is the path to your skin resources from the application webroot.
Requires the Smart GWT server framework, but does not require use of server-based databinding - no .ds.xml files need to exist.
See server-side docs for com.isomorphic.contentexport.PdfExport for more details on server-side processing and code samples for redirecting PDF output to a file or in-memory buffer, as well as instructions for adding additional stylesheets.
components
- Array of canvases that have exportable widgets.requestProperties
- Request properties for the export to pdf objectpublic static void exportContent(java.lang.String htmlFragment, DSRequest requestProperties)
printable HTML
generated from live UI components
into a .pdf and downloads it ("Save As.." dialog).
For DrawPane
and subclasses (e.g. FacetChart
) to export properly, the canvas
parameter must be the widget itself, not the HTML obtained with getPrintHTML()
unless the PrintProperties
passed to getPrintHTML() had
printForExport
:true.
You can use a custom skin when exporting your HTML content. To use a custom skin, add a line to server.properties:
skin.{skinName}.location: custom/skinWhere {skinName} is the name of your custom skin, and the value is the path to your skin resources from the application webroot.
Requires the Smart GWT server framework, but does not require use of server-based databinding - no .ds.xml files need to exist.
See server-side docs for com.isomorphic.contentexport.PdfExport for more details on server-side processing and code samples for redirecting PDF output to a file or in-memory buffer, as well as instructions for adding additional stylesheets.
htmlFragment
- HTML fragment derived from getPrintHTML()
.
See HTMLString
.requestProperties
- Request properties for the export to pdf objectpublic static void exportImage(java.lang.String svgString)
public static void exportImage(java.lang.String svgString, DSRequest requestProperties)
public static void exportImage(java.lang.String svgString, DSRequest requestProperties, ExportImageCallback callback)
DSRequest.exportImageFormat
.
Default is to download the image (triggering the browser's save dialog).
DSRequest.exportFilename
can be used to control the default filename provided in the save dialog.
To instead return the data as a normal DSResponse
, set
exportDisplay
of requestProperties
to ExportDisplay.RETURN
. In this case the data is always
base64 encoded.
Requires the SmartClient server framework, with the same set of required .jars as are required for PDF export of charts in legacy IE.
See also DrawPane.getSvgString()
and
DrawPane.getDataURL()
.
svgString
- XML string containing SVG datarequestProperties
- request properties controlling options for exportcallback
- optional callback when using exportDisplay:"return". Does not fire for other exportDisplay modes.public static void setHandleTransportErrorCallback(HandleTransportErrorCallback callback)
RPCRequest.willHandleError
was specified on the submitted request[s].
This provides the developer with an opportunity to handle a server error by (for example) suspending and resubmitting the transaction before any other handling occurs.
The default implementation takes no action - by default transport errors are handled via
handleError()
, or by the standard
request callback methods, depending on request.willHandleError. To perform custom
handing for transport errors, use this method to install a
HandleTransportErrorCallback
.
See cancelDefaultErrorHandling()
for details on how to stop the default error handling or current
error handler
if it
interferes with what you're trying to do in the HandleTransportErrorCallback
passed to this method.
Note: This method only applies to operations submitted via
XMLHttpRequest
- it is not possible to
provide similar error handling for other transports.
See this separate article
on error
handling for an overview.
callback
- HandleTransportErrorCallback the callback to set.HandleErrorCallback.handleError(com.smartgwt.client.data.DSResponse, com.smartgwt.client.data.DSRequest)
public static void cancelDefaultErrorHandling()
DSResponse
s in
the current transaction, ensuring that the default error handling or current
error handler
is not called for any
of them. This method is intended to be called inside a
HandleTransportErrorCallback
,
to prevent any potential interference from the default handling.