Project Wonder 5.0

er.ajax
Class AjaxUtils

java.lang.Object
  extended by er.ajax.AjaxUtils

public class AjaxUtils
extends java.lang.Object

Properties
er.ajax.compresseder.ajax.compressed
           
er.extensions.ERXResponseRewriter.javascriptTypeAttributeer.extensions.ERXResponseRewriter.javascriptTypeAttribute
           

Constructor Summary
AjaxUtils()
           
 
Method Summary
static void addResourceInHead(com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOResponse response, java.lang.String framework, java.lang.String fileName, java.lang.String startTag, java.lang.String endTag)
          Deprecated. this is not called by anything anymore and does not use the new support for loading-on-demand
static void addScriptCodeInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String script)
          Calls ERXWOContext.addScriptCodeInHead.
static void addScriptResourceInHead(com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOResponse response, java.lang.String fileName)
          Calls ERXWOContext.addScriptResourceInHead with "Ajax" framework
static void addScriptResourceInHead(com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOResponse response, java.lang.String framework, java.lang.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(com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOResponse response, java.lang.String fileName)
          Calls ERXWOContext.addStylesheetResourceInHead with "Ajax" framework
static void addStylesheetResourceInHead(com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOResponse response, java.lang.String framework, java.lang.String fileName)
          Calls ERXWOContext.addStylesheetResourceInHead
static java.lang.String ajaxComponentActionUrl(com.webobjects.appserver.WOContext context)
          Returns an Ajax component action url.
static void appendScript(com.webobjects.appserver.WOContext context, java.lang.String script)
          Shortcut for appendScript.
static void appendScript(com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOResponse response, java.lang.String script)
          Appends the given javascript to the response, surrounding it in a script header/footer if necessary.
static void appendScriptFooter(com.webobjects.appserver.WOResponse response)
           
static void appendScriptFooterIfNecessary(com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOResponse response)
           
static void appendScriptHeader(com.webobjects.appserver.WOResponse response)
           
static void appendScriptHeaderIfNecessary(com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOResponse response)
           
static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOComponent component, com.webobjects.foundation.NSDictionary associations, java.lang.String name)
           
static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOComponent component, com.webobjects.foundation.NSDictionary associations, java.lang.String name, java.lang.String appendValue)
           
static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOComponent component, java.lang.String name, com.webobjects.appserver.WOAssociation association)
           
static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, com.webobjects.appserver.WOComponent component, java.lang.String name, com.webobjects.appserver.WOAssociation association, java.lang.String appendValue)
           
static
<T> com.webobjects.foundation.NSArray<T>
arrayValueForAssociation(com.webobjects.appserver.WOComponent component, com.webobjects.appserver.WOAssociation association)
          Returns the array bound to the given association.
static
<T> com.webobjects.foundation.NSArray<T>
arrayValueForBinding(com.webobjects.appserver.WOComponent component, java.lang.String bindingName)
          Returns the array bound to the given binding name.
static
<T> com.webobjects.foundation.NSArray<T>
arrayValueForObject(java.lang.Object value)
          Returns the array for the given object.
static com.webobjects.appserver.WOAssociation bindingNamed(java.lang.String name, com.webobjects.foundation.NSDictionary associations)
           
static boolean booleanValueForBinding(java.lang.String name, boolean defaultValue, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOComponent component)
           
static AjaxResponse createResponse(com.webobjects.appserver.WORequest request, com.webobjects.appserver.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 hasBinding(java.lang.String name, com.webobjects.foundation.NSDictionary associations)
           
static boolean isAjaxRequest(com.webobjects.appserver.WORequest request)
          Return whether or not the given request is an Ajax request.
static com.webobjects.appserver.WOResponse javascriptResponse(java.lang.String javascript, com.webobjects.appserver.WOContext context)
          Returns an AjaxResponse with the given javascript as the body of the response.
static com.webobjects.foundation.NSMutableDictionary mutableUserInfo(com.webobjects.appserver.WOMessage message)
          Returns the userInfo dictionary if the supplied message and replaces it with a mutable version if it isn't already one.
static java.lang.String quote(java.lang.String value)
          If the value is null, this returns "null", otherwise it returns '[value]'.
static void redirectTo(com.webobjects.appserver.WOComponent component)
          Creates (or modifies if already created) an AjaxResponse to redirect to the passed component with a component action.
static void setPageReplacementCacheKey(com.webobjects.appserver.WOContext _context, java.lang.String _key)
           
static void setValueForBinding(java.lang.Object value, java.lang.String name, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOComponent component)
           
static boolean shouldHandleRequest(com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOContext context, java.lang.String containerID)
           
static java.lang.String stringValueForBinding(java.lang.String name, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOComponent component)
           
static java.lang.String toSafeElementID(java.lang.String elementID)
          Deprecated. replaced by ERXStringUtilities.safeIdentifierName
static void updateDomElement(com.webobjects.appserver.WOResponse response, java.lang.String id, java.lang.Object value, java.lang.String numberFormat, java.lang.String dateFormat, java.lang.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.
static void updateMutableUserInfoWithAjaxInfo(com.webobjects.appserver.WOContext context)
           
static void updateMutableUserInfoWithAjaxInfo(com.webobjects.appserver.WOMessage message)
           
static java.lang.Object valueForBinding(java.lang.String name, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOComponent component)
           
static java.lang.Object valueForBinding(java.lang.String name, java.lang.Object defaultValue, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOComponent component)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AjaxUtils

public AjaxUtils()
Method Detail

quote

public static java.lang.String quote(java.lang.String value)
If the value is null, this returns "null", otherwise it returns '[value]'.

Parameters:
value - the value to quote
Returns:
the quoted value or "null"

isAjaxRequest

public static boolean isAjaxRequest(com.webobjects.appserver.WORequest request)
Return whether or not the given request is an Ajax request.

Parameters:
request - the request the check

setPageReplacementCacheKey

public static void setPageReplacementCacheKey(com.webobjects.appserver.WOContext _context,
                                              java.lang.String _key)

createResponse

public static AjaxResponse createResponse(com.webobjects.appserver.WORequest request,
                                          com.webobjects.appserver.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. You can check this header in the session to decide if you want to save the request or not.

Parameters:
context -

mutableUserInfo

public static com.webobjects.foundation.NSMutableDictionary mutableUserInfo(com.webobjects.appserver.WOMessage message)
Returns the userInfo dictionary if the supplied message and replaces it with a mutable version if it isn't already one.

Parameters:
message -

addScriptResourceInHead

public static void addScriptResourceInHead(com.webobjects.appserver.WOContext context,
                                           com.webobjects.appserver.WOResponse response,
                                           java.lang.String framework,
                                           java.lang.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.

Parameters:
response -
fileName -

addScriptResourceInHead

public static void addScriptResourceInHead(com.webobjects.appserver.WOContext context,
                                           com.webobjects.appserver.WOResponse response,
                                           java.lang.String fileName)
Calls ERXWOContext.addScriptResourceInHead with "Ajax" framework


addStylesheetResourceInHead

public static void addStylesheetResourceInHead(com.webobjects.appserver.WOContext context,
                                               com.webobjects.appserver.WOResponse response,
                                               java.lang.String framework,
                                               java.lang.String fileName)
Calls ERXWOContext.addStylesheetResourceInHead


addStylesheetResourceInHead

public static void addStylesheetResourceInHead(com.webobjects.appserver.WOContext context,
                                               com.webobjects.appserver.WOResponse response,
                                               java.lang.String fileName)
Calls ERXWOContext.addStylesheetResourceInHead with "Ajax" framework


addResourceInHead

public static void addResourceInHead(com.webobjects.appserver.WOContext context,
                                     com.webobjects.appserver.WOResponse response,
                                     java.lang.String framework,
                                     java.lang.String fileName,
                                     java.lang.String startTag,
                                     java.lang.String endTag)
Deprecated. this is not called by anything anymore and does not use the new support for loading-on-demand

Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.

Parameters:
response -
fileName -
startTag -
endTag -

addScriptCodeInHead

public static void addScriptCodeInHead(com.webobjects.appserver.WOResponse response,
                                       com.webobjects.appserver.WOContext context,
                                       java.lang.String script)
Calls ERXWOContext.addScriptCodeInHead.


toSafeElementID

public static java.lang.String toSafeElementID(java.lang.String elementID)
Deprecated. replaced by ERXStringUtilities.safeIdentifierName


shouldHandleRequest

public static boolean shouldHandleRequest(com.webobjects.appserver.WORequest request,
                                          com.webobjects.appserver.WOContext context,
                                          java.lang.String containerID)

updateMutableUserInfoWithAjaxInfo

public static void updateMutableUserInfoWithAjaxInfo(com.webobjects.appserver.WOContext context)

updateMutableUserInfoWithAjaxInfo

public static void updateMutableUserInfoWithAjaxInfo(com.webobjects.appserver.WOMessage message)

javascriptResponse

public static com.webobjects.appserver.WOResponse javascriptResponse(java.lang.String javascript,
                                                                     com.webobjects.appserver.WOContext context)
Returns an AjaxResponse with the given javascript as the body of the response.

Parameters:
context - the WOContext
javascript - the javascript to send
Returns:
a new response

appendScript

public static void appendScript(com.webobjects.appserver.WOContext context,
                                java.lang.String script)
Shortcut for appendScript.

Parameters:
context - the context
script - the script to append

appendScript

public static void appendScript(com.webobjects.appserver.WORequest request,
                                com.webobjects.appserver.WOResponse response,
                                java.lang.String script)
Appends the given javascript to the response, surrounding it in a script header/footer if necessary.

Parameters:
request - the request
response - the response
script - the script to append

appendScriptHeaderIfNecessary

public static void appendScriptHeaderIfNecessary(com.webobjects.appserver.WORequest request,
                                                 com.webobjects.appserver.WOResponse response)

appendScriptHeader

public static void appendScriptHeader(com.webobjects.appserver.WOResponse response)

appendScriptFooterIfNecessary

public static void appendScriptFooterIfNecessary(com.webobjects.appserver.WORequest request,
                                                 com.webobjects.appserver.WOResponse response)

appendScriptFooter

public static void appendScriptFooter(com.webobjects.appserver.WOResponse response)

hasBinding

public static boolean hasBinding(java.lang.String name,
                                 com.webobjects.foundation.NSDictionary associations)

bindingNamed

public static com.webobjects.appserver.WOAssociation bindingNamed(java.lang.String name,
                                                                  com.webobjects.foundation.NSDictionary associations)

valueForBinding

public static java.lang.Object valueForBinding(java.lang.String name,
                                               java.lang.Object defaultValue,
                                               com.webobjects.foundation.NSDictionary associations,
                                               com.webobjects.appserver.WOComponent component)

stringValueForBinding

public static java.lang.String stringValueForBinding(java.lang.String name,
                                                     com.webobjects.foundation.NSDictionary associations,
                                                     com.webobjects.appserver.WOComponent component)

valueForBinding

public static java.lang.Object valueForBinding(java.lang.String name,
                                               com.webobjects.foundation.NSDictionary associations,
                                               com.webobjects.appserver.WOComponent component)

booleanValueForBinding

public static boolean booleanValueForBinding(java.lang.String name,
                                             boolean defaultValue,
                                             com.webobjects.foundation.NSDictionary associations,
                                             com.webobjects.appserver.WOComponent component)

setValueForBinding

public static void setValueForBinding(java.lang.Object value,
                                      java.lang.String name,
                                      com.webobjects.foundation.NSDictionary associations,
                                      com.webobjects.appserver.WOComponent component)

arrayValueForAssociation

public static <T> com.webobjects.foundation.NSArray<T> arrayValueForAssociation(com.webobjects.appserver.WOComponent component,
                                                                                com.webobjects.appserver.WOAssociation association)
Returns the array bound to the given association.

Type Parameters:
T - the array type
Parameters:
component - the component to resolve against
association - the association to retrieve a value for
Returns:
an array (or null)

arrayValueForBinding

public static <T> com.webobjects.foundation.NSArray<T> arrayValueForBinding(com.webobjects.appserver.WOComponent component,
                                                                            java.lang.String bindingName)
Returns the array bound to the given binding name.

Type Parameters:
T - the array type
Parameters:
component - the component to resolve against
bindingName - the name of the binding
Returns:
an array (or null)

arrayValueForObject

public static <T> com.webobjects.foundation.NSArray<T> arrayValueForObject(java.lang.Object value)
Returns the array for the given object. If the object is a string, it will be parsed as a JSON value.

Type Parameters:
T - the array type
Parameters:
value - the object value
Returns:
an array (or null)

ajaxComponentActionUrl

public static java.lang.String ajaxComponentActionUrl(com.webobjects.appserver.WOContext context)
Returns an Ajax component action url. Using an ajax component action urls guarantees that caching during your ajax request will be handled appropriately.

Parameters:
context - the context of the request
Returns:
an ajax request url.

appendTagAttributeAndValue

public static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response,
                                              com.webobjects.appserver.WOContext context,
                                              com.webobjects.appserver.WOComponent component,
                                              com.webobjects.foundation.NSDictionary associations,
                                              java.lang.String name)

appendTagAttributeAndValue

public static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response,
                                              com.webobjects.appserver.WOContext context,
                                              com.webobjects.appserver.WOComponent component,
                                              com.webobjects.foundation.NSDictionary associations,
                                              java.lang.String name,
                                              java.lang.String appendValue)

appendTagAttributeAndValue

public static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response,
                                              com.webobjects.appserver.WOContext context,
                                              com.webobjects.appserver.WOComponent component,
                                              java.lang.String name,
                                              com.webobjects.appserver.WOAssociation association)

appendTagAttributeAndValue

public static void appendTagAttributeAndValue(com.webobjects.appserver.WOResponse response,
                                              com.webobjects.appserver.WOContext context,
                                              com.webobjects.appserver.WOComponent component,
                                              java.lang.String name,
                                              com.webobjects.appserver.WOAssociation association,
                                              java.lang.String appendValue)

redirectTo

public static void redirectTo(com.webobjects.appserver.WOComponent component)
Creates (or modifies if already created) an AjaxResponse to redirect to the passed component with a component action. Anything previously written to the AjaxResponse is preserved.

Parameters:
component - full page WOComponent instance to redirect to

updateDomElement

public static void updateDomElement(com.webobjects.appserver.WOResponse response,
                                    java.lang.String id,
                                    java.lang.Object value,
                                    java.lang.String numberFormat,
                                    java.lang.String dateFormat,
                                    java.lang.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;
 }
 

Parameters:
response - The response to append the JavaScript to
id - ID of the DOM element to update
value - The new value
numberFormat - optional number format to format the value with
dateFormat - optional date format to format the value with
valueWhenEmpty - string to use when value is null
See Also:
AjaxResponse#updateDomElement(String, Object, String, String, String), AjaxResponse#updateDomElement(String, Object)

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.