Project Wonder 5.0

er.ajax
Class AjaxOptions

java.lang.Object
  extended by com.webobjects.appserver.WOElement
      extended by com.webobjects.appserver.WODynamicElement
          extended by er.ajax.AjaxOptions

public class AjaxOptions
extends WODynamicElement

AjaxOptions provides a mechanism to produce a JSON formatted dictionary from binding names and / or a dictionary. This is intended to support the options parameter in Prototype, e.g. the second parameter here:

 new Ajax.Request('/some_url', {
     method: 'get',
     parameters: {company: 'example', limit: 12}
   });
 
However, the functionality is not specific to Prototype and can be used anywhere a JSON formatted dictionary is needed.

AjaxOptions can be used either in a HTML/WOD setting, e.g.

 AjaxOptions : AjaxOptions {
  method = "get";
        options = createAjaxOptions;
 }
 
with options bound to a dictionary produced by AjaxOption, or it can be used directly in Java, e.g.
  AjaxOptions.appendToResponse(createAjaxOptions(), context.response(), context);
 

Example (and fictitious) usage code:

        public NSDictionary createAjaxOptions(WOComponent component) {
                NSMutableArray ajaxOptionsArray = new NSMutableArray();
                ajaxOptionsArray.addObject(new AjaxOption("frequency", AjaxOption.NUMBER));
                ajaxOptionsArray.addObject(new AjaxOption("onLoading", AjaxOption.SCRIPT));
                ajaxOptionsArray.addObject(new AjaxOption("evalScripts", Boolean.TRUE, AjaxOption.BOOLEAN));
                ajaxOptionsArray.addObject(new AjaxOption("method", "get", AjaxOption.STRING));
      ...
                NSMutableDictionary options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, component, associations());
                return options;
        }

 response.appendContentString("AUC.registerPeriodic('" + id + "'," + canStop + "," + stopped + ",");
 AjaxOptions.appendToResponse(options, response, context);
 response.appendContentString(");");
 

See Also:
AjaxOption, AjaxValue

Field Summary
 
Fields inherited from class com.webobjects.appserver.WODynamicElement
_ConstructorParameters
 
Constructor Summary
AjaxOptions(String name, NSDictionary bindings, WOElement children)
           
 
Method Summary
static void _appendToBuffer(NSDictionary options, StringBuffer stringBuffer, WOContext context)
          Adds JSON formatted key-value pairs from options to end of response content.
static void _appendToResponse(NSDictionary options, WOResponse response, WOContext context)
          Adds JSON formatted key-value pairs from options to end of response content.
static void appendToBuffer(NSDictionary options, StringBuffer stringBuffer, WOContext context)
          Adds JSON formatted key-value pairs from options to end of response content.
static void appendToResponse(NSDictionary options, WOResponse response, WOContext context)
          Adds JSON formatted key-value pairs from options to end of response content.
 void appendToResponse(WOResponse response, WOContext context)
           
 
Methods inherited from class com.webobjects.appserver.WODynamicElement
toString
 
Methods inherited from class com.webobjects.appserver.WOElement
invokeAction, takeValuesFromRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AjaxOptions

public AjaxOptions(String name,
                   NSDictionary bindings,
                   WOElement children)
Method Detail

appendToResponse

public void appendToResponse(WOResponse response,
                             WOContext context)
Overrides:
appendToResponse in class WOElement

_appendToResponse

public static void _appendToResponse(NSDictionary options,
                                     WOResponse response,
                                     WOContext context)
Adds JSON formatted key-value pairs from options to end of response content. Does not adds the surrounding "{" and "}" signifying a dictionary / object.

Parameters:
options - dictionary of key-value pairs, intended to have come from AjaxOption
response - WOResponse to add JSON formatted key-value pairs to
context - WOContext to provide WOComponent to resolve binding values in

_appendToBuffer

public static void _appendToBuffer(NSDictionary options,
                                   StringBuffer stringBuffer,
                                   WOContext context)
Adds JSON formatted key-value pairs from options to end of response content. Does not adds the surrounding "{" and "}" signifying a dictionary / object.

Parameters:
options - dictionary of key-value pairs, intended to have come from AjaxOption
stringBuffer - StringBuffer to add JSON formatted key-value pairs to
context - WOContext to provide WOComponent to resolve binding values in

appendToBuffer

public static void appendToBuffer(NSDictionary options,
                                  StringBuffer stringBuffer,
                                  WOContext context)
Adds JSON formatted key-value pairs from options to end of response content. Adds the surrounding "{" and "}" signifying a dictionary / object.

Parameters:
options - dictionary of key-value pairs, intended to have come from AjaxOption
stringBuffer - StringBuffer to add JSON formatted key-value pairs to
context - WOContext to provide WOComponent to resolve binding values in

appendToResponse

public static void appendToResponse(NSDictionary options,
                                    WOResponse response,
                                    WOContext context)
Adds JSON formatted key-value pairs from options to end of response content. Adds the surrounding "{" and "}" signifying a dictionary / object.

Parameters:
options - dictionary of key-value pairs, intended to have come from AjaxOption
response - WOResponse to add JSON formatted key-value pairs to
context - WOContext to provide WOComponent to resolve binding values in

Last updated: Wed, Feb 22, 2012 • 07:00 AM EST

Copyright © 2002 – 2011 Project Wonder.