JavaScript Functions

 

NOTE: The tooltips for the Framework are provided by Walter Zorn. Please visit his site at http://www.walterzorn.com. He is the one developer I can identity, there are many more functions that I begged, borrowed and stole(copy and pasted) from the internet – “Why think, when you can GOOGLE!”

 

Another point of interest, the Framework never performs a “Submit”, all interactions with the host are via AJAX. If you don’t yet know what AJAX is, it is simply a mechanism for transmitting data, and receiving data to the server. With AJAX, the framework can selectively interact with the server, and not simply to a “big bang” send of all form data.

 

AJAX is an acronym for ‘Asynchronous JavaScript and XML’. There is nothing new to install to use it, it is more a technique, rather than anything new. To see how we use AJAX within the F4J framework, look at the AjaxRequestPage() JavaScript function in the sbGeneral.js file. For more information on AJAX, try googling it – there is much to read.

 

http://java.sun.com/javaee/javaserverfaces/ajax/tutorial.jsp

 

Ok – Back to the topic(s) at hand….

Java Script Commands:

sbGeneral.js

 

The sbGeneral.js file contains the core Framework script functions for all server and form interactions.

 

System wide global variables:

 

var sysAccess                                       = "Page";

var sysLastForm                                    = "";

var sysCurrentForm                                = "";

var sysSessionStartDateTime                 = "";

var sysSessionEndDateTime                   = "";

var sysAction                                         = "";

var localTransitionForm                           ="";

var FormContextArea                              = "ajaxcontentarea";

var FormTopArea                                    = "ajaxtoparea";

var FormHeaderArea                               = "ajaxheaderarea";

var FormBottomArea                              = "ajaxbottomarea";

var FormFooterArea                                = "ajaxfooterarea";

 

Functions:

 

Function Name

Parameters

AjaxRequestData

servletName, Action

AjaxRequestPage

servletName, Action, Access, Target

AjaxRequestWSDL

servlet

AjaxSubmitPage

servletName, Action, Target

dirtyForm

bool,formObject

getAllFormValues

formID

getChildrenFor

dom, parentHandler, childHandler

getFormValue

fieldName

getFormValueOnForm

formID, fieldName

getGlobalValuesFromForm

fobj

getGlobalValuesFromMemory

formID

getListValue

fieldName

getNode

parent, tagName

getNodesWithKey

parent, tagName, key

getRequestObj

 

ProcessXMLResp

inXML, ParentTag, parentHandler, childHandler

rawXmlResponse

req

setFieldInError

fieldName

setFieldInErrorOnForm

formID, fieldName

setFormValue

fieldName, fieldValue

setFormValueOnForm

formID, fieldName, fieldValue

setGlobalFormValuesFromMemory

formID

validateField

formObject

validateForm

 

validateFormFromServer

formID

xmlGlobalChild

ChildNodeName, ChildNodeValue, ChildID

xmlGlobalParent

ParentNodeName, pID

xmlResponse

req, Target

xmlSimpleResponse

req, Target

 

AjaxLib.js

 

Provides JavaScript “class” like access to Ajax and the underlying AsyncFW/DO framework. To use it you will need to create an instance of the “Ajax” object;

 

var aj = new Ajax();

 

Once you have created an instance of the Ajax object, you can then interact with the server by using one of the four methods provided;

Asynchronous Request – do not wait for response

Ajax.requestText(servlet, handler, formvalues)

Ajax.requestXML(servlet, handler, formvalues)

Synchronous Request – wait for server response

Ajax.requestSyncText(servlet, handler, formvalues)

Ajax.requestSyncXML(servlet, handler, formvalues)

 

Text or XML response

The requests can return either a text string, or an XML DOM object.  Text return values are harder to interrogate,  but is very useful for returning simple strings. The XML DOM requests are far more useful for form, or multiple field value return types.

Request Parameters

Each of the for request methods require the same three parameters.

 

Servlet – This is the equivalent to the html Form “Action” attribute. It is the name of the servlet to be invoked.

 

Handler – This is the handler function which will be called when the server returns a respsone. The handler function must take the following form;

 

function AjaxReturnHandler(domObject){

     alert("returned XML DOM from Server");

}

 

OR

 

function AjaxReturnHandler (stringObject){

     alert("returned Text String from Server");

}

 

FormValues – The data to be sent to the server.

 

Sample Request w/Handler

 

function MyServlet_Sample(){

     setFormValue("sysAction", "Import");

     var aj = new Ajax();

     aj.requestSyncXML("/FWAdmin/MyServlet",

"SampleHandler",

getAllFormValues("MySevlet"));

}

function SampleHandler(dom){

     alert("returned from Import");

}

 

The above JavaScript will execute a synchronous request to the /FWAdmin/MyServlet servlet using all the form values using the sbGeneral.js function getAllFormValue(formname). When the servlet returns it’s response, the handler “SampleHandler” will be invoked.

 

 

FormValidation.js

 

Standing on the shoulders of giants, I have assembled most of these functions by combing the web. Thanks to all you un-named developers out their!

 

The FormValidation functions are geared toward data manipulation, and formatting.

Functions:

 

Function Name

Parameters

add100Percent

strValue

addCommas

strValue

addCurrency

num

addCurrency2

strValue

addInterest

strValue

addPercent

strValue

changeDateFrmt

val

customRegExp

strValue, regEx

endsWith

strValue, strStr

inYrRangeUSDate

strValue, frmYear, toYear

isEmpty

strValue

isValidEmail

strValue

isValidInteger

strValue

isValidNotEmpty

strValue

isValidNumeric

strValue

isValidSSN

strValue

isValidUSDate

strValue

isValidUSPhone

strValue

isValidUSZip

strValue

isValidValue

strValue, strMatchPattern

leftTrim

strValue

makeInteger

strValue

parseField

inField

removeCharacters

strValue, strMatchPattern

removeCommas

strValue

removeCurrency

strValue

removeDecimal

strValue

removeInterest

strValue

removePercent

strValue

rightTrim

strValue

startsWith

strValue, strStr

trimAll

strValue

Framework Page Interface

 

Ok, so JavaScript doesn’t really have the concept of an ‘Interface’. That said, the Framework requires that you implement a script for every page that user will interact with, and that that page implement certain functions, and a variable. The pseudo-interface requires that these functions begin with the name of the form (case matters).

 

Variable:

 

var yourFormNameDirty = false;

 

Functions:

 

Function Name

Parameters

yourFormName_getDataToSend

Action

yourFormName_preRequestAction

Action

yourFormName_Request_Return

currForm

yourFormName_Submit_PreSubmit

Action

yourFormName_Submit_Return

Action

yourFormName_SubmitButton

ButtonObj

yourFormName_Validate

fieldName, fieldValue

 

 

 

 

Copyright 2009. All rights reserved by

S. Chappell