public class AjaxUtils extends Object
Name | Description |
---|---|
er.ajax.compressed | er.ajax.compressed |
er.extensions.ERXResponseRewriter.javascriptTypeAttribute | er.extensions.ERXResponseRewriter.javascriptTypeAttribute |
Constructor and Description |
---|
AjaxUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addScriptCodeInHead(WOResponse response,
WOContext context,
String script)
|
static void |
addScriptResourceInHead(WOContext context,
WOResponse response,
String fileName)
Calls
addScriptResourceInHead(WOContext, WOResponse, String, String) with "Ajax" as framework. |
static void |
addScriptResourceInHead(WOContext context,
WOResponse response,
String framework,
String fileName)
Adds a script tag with a correct resource URL in the HTML head tag if it isn't already present in the response.
|
static void |
addStylesheetResourceInHead(WOContext context,
WOResponse response,
String fileName)
Calls
addStylesheetResourceInHead(WOContext, WOResponse, String, String) with "Ajax" as framework. |
static void |
addStylesheetResourceInHead(WOContext context,
WOResponse response,
String framework,
String fileName)
|
static String |
ajaxComponentActionUrl(WOContext context)
Returns an Ajax component action url.
|
static void |
appendScript(WOContext context,
String script)
Shortcut for appendScript.
|
static void |
appendScript(WORequest request,
WOResponse response,
String script)
Appends the given javascript to the response, surrounding it in a script header/footer if necessary.
|
static void |
appendScriptFooter(WOResponse response) |
static void |
appendScriptFooterIfNecessary(WORequest request,
WOResponse response) |
static void |
appendScriptHeader(WOResponse response) |
static void |
appendScriptHeaderIfNecessary(WORequest request,
WOResponse response) |
static void |
appendTagAttributeAndValue(WOResponse response,
WOContext context,
WOComponent component,
NSDictionary<String,WOAssociation> associations,
String name) |
static void |
appendTagAttributeAndValue(WOResponse response,
WOContext context,
WOComponent component,
NSDictionary<String,WOAssociation> associations,
String name,
String appendValue) |
static void |
appendTagAttributeAndValue(WOResponse response,
WOContext context,
WOComponent component,
String name,
WOAssociation association) |
static void |
appendTagAttributeAndValue(WOResponse response,
WOContext context,
WOComponent component,
String name,
WOAssociation association,
String appendValue) |
static <T> NSArray<T> |
arrayValueForAssociation(WOComponent component,
WOAssociation association)
Returns the array bound to the given association.
|
static <T> NSArray<T> |
arrayValueForBinding(WOComponent component,
String bindingName)
Returns the array bound to the given binding name.
|
static <T> NSArray<T> |
arrayValueForObject(Object value)
Returns the array for the given object.
|
static AjaxResponse |
createResponse(WORequest request,
WOContext context)
Creates a response for the given context (which can be null), sets the charset to UTF-8, the connection to
keep-alive and flags it as a Ajax request by adding an AJAX_REQUEST_KEY header.
|
static boolean |
isAjaxRequest(WORequest request)
Return whether or not the given request is an Ajax request.
|
static WOResponse |
javascriptResponse(String javascript,
WOContext context)
Returns an
AjaxResponse with the given javascript as the body of the response. |
static String |
quote(String value)
If the value is null, this returns "null", otherwise it returns '[value]'.
|
static void |
redirectTo(WOComponent component)
Creates (or modifies if already created) an AjaxResponse to redirect to the passed component with a component action.
|
static void |
setPageReplacementCacheKey(WOContext _context,
String _key) |
static boolean |
shouldHandleRequest(WORequest request,
WOContext context,
String containerID) |
static void |
updateDomElement(WOResponse response,
String id,
Object value,
String numberFormat,
String dateFormat,
String valueWhenEmpty)
updateDomElement appends JavaScript code to the given
AjaxResponse that updates the content of the DOM Element with the given
ID to the specified value. |
public static String quote(String value)
value
- the value to quotepublic static boolean isAjaxRequest(WORequest request)
request
- the request the checktrue
public static void setPageReplacementCacheKey(WOContext _context, String _key)
public static AjaxResponse createResponse(WORequest request, WOContext context)
request
- the current requestcontext
- the current contextpublic static void addScriptResourceInHead(WOContext context, WOResponse response, String framework, String fileName)
context
- the contextresponse
- the response to write intoframework
- the framework that contains the filefileName
- the name of the javascript file to addpublic static void addScriptResourceInHead(WOContext context, WOResponse response, String fileName)
addScriptResourceInHead(WOContext, WOResponse, String, String)
with "Ajax" as framework.context
- the contextresponse
- the response to write intofileName
- the name of the javascript file to addpublic static void addStylesheetResourceInHead(WOContext context, WOResponse response, String framework, String fileName)
context
- the contextresponse
- the response to write intoframework
- the framework that contains the filefileName
- the name of the CSS file to addpublic static void addStylesheetResourceInHead(WOContext context, WOResponse response, String fileName)
addStylesheetResourceInHead(WOContext, WOResponse, String, String)
with "Ajax" as framework.context
- the contextresponse
- the response to write intofileName
- the name of the CSS file to addpublic static void addScriptCodeInHead(WOResponse response, WOContext context, String script)
response
- the response to write intocontext
- the contextscript
- the javascript code to insertpublic static boolean shouldHandleRequest(WORequest request, WOContext context, String containerID)
public static WOResponse javascriptResponse(String javascript, WOContext context)
AjaxResponse
with the given javascript as the body of the response.context
- the contextjavascript
- the javascript to sendpublic static void appendScript(WOContext context, String script)
context
- the contextscript
- the script to appendpublic static void appendScript(WORequest request, WOResponse response, String script)
request
- the requestresponse
- the responsescript
- the script to appendpublic static void appendScriptHeaderIfNecessary(WORequest request, WOResponse response)
public static void appendScriptHeader(WOResponse response)
public static void appendScriptFooterIfNecessary(WORequest request, WOResponse response)
public static void appendScriptFooter(WOResponse response)
public static <T> NSArray<T> arrayValueForAssociation(WOComponent component, WOAssociation association)
T
- the array typecomponent
- the component to resolve againstassociation
- the association to retrieve a value forpublic static <T> NSArray<T> arrayValueForBinding(WOComponent component, String bindingName)
T
- the array typecomponent
- the component to resolve againstbindingName
- the name of the bindingpublic static <T> NSArray<T> arrayValueForObject(Object value)
T
- the array typevalue
- the object valuepublic static String ajaxComponentActionUrl(WOContext context)
context
- the context of the requestpublic static void appendTagAttributeAndValue(WOResponse response, WOContext context, WOComponent component, NSDictionary<String,WOAssociation> associations, String name)
public static void appendTagAttributeAndValue(WOResponse response, WOContext context, WOComponent component, NSDictionary<String,WOAssociation> associations, String name, String appendValue)
public static void appendTagAttributeAndValue(WOResponse response, WOContext context, WOComponent component, String name, WOAssociation association)
public static void appendTagAttributeAndValue(WOResponse response, WOContext context, WOComponent component, String name, WOAssociation association, String appendValue)
public static void redirectTo(WOComponent component)
component
- full page WOComponent instance to redirect topublic static void updateDomElement(WOResponse response, String id, Object value, String numberFormat, String dateFormat, String valueWhenEmpty)
updateDomElement
appends JavaScript code to the given
AjaxResponse that updates the content of the DOM Element with the given
ID to the specified value. Useful if you want to update multiple small
regions on a page with a single request, e.g. when an AjaxObserveField
triggers an action.
This method is also available on instances. The example
below uses the method on AjaxResponse.
public WOActionResults cartItemChanged() {
ShoppingCart cart; // assume this exists
ShoppingCartItem item; // assume this exists
AjaxResponse response = AjaxUtils.createResponse(context().request(), context());
response.appendScriptHeaderIfNecessary();
response.updateDomElement("orderAmount_" + item.primaryKey(), item.orderAmount(), "#,##0.", null, null);
response.updateDomElement("price_" + item.primaryKey(), item.priceForOrderAmount(), "#,##0.00", null, null);
response.updateDomElement("shoppingCartPrice", cart.totalPrice(), "#,##0.00", null, null);
response.appendScriptFooterIfNecessary();
return response;
}
response
- The response to append the JavaScript toid
- ID of the DOM element to updatevalue
- The new valuenumberFormat
- optional number format to format the value withdateFormat
- optional date format to format the value withvalueWhenEmpty
- string to use when value is nullAjaxResponse.updateDomElement(String, Object, String, String, String)
,
AjaxResponse.updateDomElement(String, Object)
Copyright © 2002 – 2024 Project Wonder.