com.getsnappy.snappyj
Class JavaScriptBean

java.lang.Object
  extended by com.getsnappy.snappyj.JavaScriptBean
Direct Known Subclasses:
DynamicContextBean, MultiJavaScriptBean

public abstract class JavaScriptBean
extends java.lang.Object

These beans act as the communication channel between javascript and java. In javascript beans are manipulated and saved cookies. Each bean has its own cookie. These cookies must always be maintained to represent the current state, and are used in case of a reload. All variables in all beans can also be passed in through the request which overrides the cookie.

Author:
brian

Constructor Summary
JavaScriptBean()
           
 
Method Summary
protected  java.lang.Object get(java.lang.String attribute)
          Used internally to access the variables in this bean.
protected abstract  java.util.Vector<java.lang.String> getApplicationVariables()
          overide this function to define all variables for this bean
protected abstract  java.util.Vector<java.lang.Class> getApplicationVariableTypes()
          overide this function to define the variables types.
 java.lang.String getAttributeId(java.lang.String attribute)
          Works in conjunction with jsPersistForm.
abstract  java.lang.String getCookieName()
          overide this function to define a cookieName to load cookie state from
abstract  java.lang.String getJavaScriptBeanName()
          // overide this function to define a bean name.
protected static JavaScriptBean isPersistedInRequest(java.lang.String cookieName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void jsDeclareObject(java.io.Writer out)
          Generate the necassary object definitions to process a bean.
 java.lang.String jsGet(java.lang.String attribute)
          Outputs inline(single-line) JavaScript that will set and persist the specified attribute immediately, when the javascript is executed
 java.lang.String jsPersist()
           
 java.lang.String jsPersistForm()
          Load the html form elements by id for each attribute (see jsAttributeId) and persist changes.
 java.lang.String jsSet(java.lang.String attribute, java.lang.Boolean value)
          Outputs inline(single-line) JavaScript that will set and persist the specified attribute immediately, when the javascript is executed
 java.lang.String jsSet(java.lang.String attribute, java.lang.Integer value)
          Outputs inline(single-line) JavaScript that will set and persist the specified attribute immediately, when the javascript is executed
 java.lang.String jsSet(java.lang.String attribute, java.lang.Long value)
          Outputs inline(single-line) JavaScript that will set and persist the specified attribute immediately, when the javascript is executed
 java.lang.String jsSet(java.lang.String attribute, java.lang.String value)
          FIXME: Need to add type safety checks to jsSet
protected  void load(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This method loads the bean variables.
protected  void persistToRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Persist this Bean for the duration of the request.
protected  void set(java.lang.String attribute, java.lang.Object value)
          Used internally to access the variables in this bean, while also providing access to our useful generic methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaScriptBean

public JavaScriptBean()
Method Detail

getJavaScriptBeanName

public abstract java.lang.String getJavaScriptBeanName()
// overide this function to define a bean name. This function should be a return a static string and you should // implement a static version as well // // e.g. // public static String beanName = ""; // public static String getJavaScriptBeanName() { return beanName; } // public String getJavaScriptBeanName() { return beanName; }


getApplicationVariables

protected abstract java.util.Vector<java.lang.String> getApplicationVariables()
overide this function to define all variables for this bean

Returns:

getApplicationVariableTypes

protected abstract java.util.Vector<java.lang.Class> getApplicationVariableTypes()
overide this function to define the variables types. This corresponds with the collection of variables above.

Returns:

getCookieName

public abstract java.lang.String getCookieName()
overide this function to define a cookieName to load cookie state from


get

protected java.lang.Object get(java.lang.String attribute)
Used internally to access the variables in this bean. Each Bean should implement getters and setters that return this function like return get("");

Parameters:
attribute -
Returns:

set

protected void set(java.lang.String attribute,
                   java.lang.Object value)
Used internally to access the variables in this bean, while also providing access to our useful generic methods. Each Bean should implement getters and setters that call this function like set("","");

Parameters:
attribute -

persistToRequest

protected void persistToRequest(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response)
Persist this Bean for the duration of the request. This is a helper for creating per request caching from a static loader

Parameters:
request -
response -

isPersistedInRequest

protected static JavaScriptBean isPersistedInRequest(java.lang.String cookieName,
                                                     javax.servlet.http.HttpServletRequest request,
                                                     javax.servlet.http.HttpServletResponse response)

load

protected void load(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
This method loads the bean variables. We check to see if any changes have been persisted, and return those if they exist. Otherwise we load the this bean from the cookie. This allow us to implement reload, Each bean should implement one constructor, and it should call this function // public (HttpServletRequest request, HttpServletResponse response) { // load(request,response); // // // ... add any default settings here // }

Parameters:
request -
response -

jsDeclareObject

public void jsDeclareObject(java.io.Writer out)
                     throws java.io.IOException
Generate the necassary object definitions to process a bean. In order for a bean to function correctly the bean must load the js object definition first. Next the beanName must be passed in the beans argument to the Web20Environment js object. Finally the initialize method of the Web20Environment js object is invoked and an instance of the object definition is loaded into the Web20Evnirnment js object as beanName. NOTE: like an other js function, this one outputs straight JavaScript and should be nested inside a SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD