jaxcent
Class JaxcentPage

java.lang.Object
  extended byjaxcent.JaxcentPage

public class JaxcentPage
extends java.lang.Object

JaxcentPage is the base class from which all Jaxcent URL handlers need to be derived. In cases where no particular handler is needed (when using auto-session-management and when no data verification is needed), this class can be specified directly as the handler. This class provides over-ridable methods to process operations like load and unload. It also provides various common utility methods, such as showing JavaScript alert (dialog box) messages.


Constructor Summary
JaxcentPage()
          Default constructor.
 
Method Summary
 boolean checkElementExists(SearchType searchType, java.lang.String searchString, int searchIndex)
          Check if an element exists, without attempting to assign it to an object.
 void deleteCookie(java.lang.String cookieName)
          Delete cookie.
 void deleteElementById(java.lang.String id)
          Delete an element referenced by an ID.
 java.lang.String evalJavaScriptCode(java.lang.String code)
          Execute JavaScript code, wait for results.
 java.lang.String evalJavaScriptCode(java.lang.String code, boolean argsAsArray, java.lang.Object[] args)
          Same as execJavaScriptCode, but waits for the result of the evaluation and returns it.
 void execJavaScriptCode(java.lang.String code)
          Execute JavaScript code, do not wait for results.
 void execJavaScriptCode(java.lang.String code, boolean argsAsArray, java.lang.Object[] args)
          Call JavaScript, do not wait for results.
 java.util.Map getAllFormData()
          Retrieve all form data on page.
 java.util.Map getAllSessionData(boolean getFromCurrentPage)
          Get all data from session so far.
 java.lang.Object getAppContext()
          This method will return the application server's or Jaxcent connector's application context.
 java.util.Enumeration getAppContextKeys()
          Get list of key names from application context.
 java.lang.String getClientJaxcentURL()
          Returns the URL used in the client for Jaxcent.
 java.lang.String getClientVersion()
          Returns a string describing the connected page's version number, e.g. "2.1.1".
 java.lang.String getCookie(java.lang.String cookieName)
          Get cookie value.
 java.util.Map getCookies()
          Get cookies from page as name->value pairs.
 java.lang.String getCurrentPath()
          Get the path of the URL that is being processed.
 boolean getFormSaveEnabled()
          For AutoSessionData pages, returns whether saving form data in session upon page unloads, is enabled.
 java.lang.Object getFromAppContext(java.lang.String key)
          Get data from application context.
 java.lang.Object getHttpSession()
          If "UseSession" or "AutoSessionData" have been configured as true in the configuration file for this page, this method will return the HTTP session object from the application server or Jaxcent connector.
static java.lang.String getJaxcentVersion()
          Return Jaxcent version.
 java.util.Locale getLocale()
          Get the remote locale if specified in HTTP Accept-Language header.
 java.util.Locale[] getLocales()
          Get a list of remote locales if specified in HTTP Accept-Language header.
 java.lang.String getRemoteAddr()
          Get the client IP address.
 java.awt.Dimension getScreenSize()
          Get screen dimensions
 java.lang.String getStatusText()
          Get status text.
 java.awt.Dimension getWindowSize()
          Get window dimensions
 void goBack()
          Navigate back.
 void goForward()
          Navigate forward.
 void invalidateHttpSession()
          If "UseSession" or "AutoSessionData" have been configured as true in the configuration file for this page, this method can be used to invalidate the session.
 java.lang.String makeContentURL(java.lang.String contentType, byte[] content, java.lang.String filename)
          Returns a URL that will return a given content-type and bytes.
 void navigate(java.lang.String url)
          Navigate to a given URL.
protected  void onFinalFormData(java.util.Map formData)
          Override to receive form data during page unloading.
protected  void onJavaScriptRequest(java.lang.String cmd, java.lang.String[] args)
          Override to process data from JavaScript methods sent by calling the "JaxcentServerRequest( args... );" function defined by the Jaxcent JavaScript file.
protected  void onLoad()
          Override to handle page loading.
protected  void onUnload()
          Override to handle page unloading.
 void removeAppContextKey(java.lang.String key)
          Remove key from application context.
 void resetFromSession()
          Reset form data from session.
 void saveInAppContext(java.lang.String key, java.lang.Object value)
          Save data in the application context, using a given key (like a Map.)
 void setBatchUpdates(boolean batchUpdates)
          Used to hold updates without sending them out to the client.
 void setCookie(java.lang.String cookieString)
          Add cookie to page.
 void setCookie(java.lang.String name, java.lang.String value, java.util.Date expires, java.lang.String domain, java.lang.String path, boolean isSecure)
          Add cookie to page.
 void setFormSaveEnabled(boolean enable)
          Enable or disable saving of form data from current page into session, for AutoSessionData management.
 void setStatusText(java.lang.String text)
          Set status text.
 boolean showConfirmDialog(java.lang.String message)
          Show JavaScript confirm dialog box to the user.
 java.lang.String showInputDialog(java.lang.String prompt, java.lang.String defaultResult)
          Show JavaScript prompt dialog box to the user.
 void showMessageDialog(java.lang.String message)
          Show JavaScript alert dialog box to the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JaxcentPage

public JaxcentPage()
Default constructor. Called by the Jaxcent framework, do not call directly. Usually this class is overridden.

Method Detail

getHttpSession

public java.lang.Object getHttpSession()
                                throws Jaxception
If "UseSession" or "AutoSessionData" have been configured as true in the configuration file for this page, this method will return the HTTP session object from the application server or Jaxcent connector.

If running with a standard Java servlet-container/application-server, the object returned is of type javax.servlet.http.HttpSession, and can be cast to that type.

If running with a direct Jaxcent connector for IIS/Apache, the object returned is of type jaxcentConnector.JaxcentSession.

Throws:
Jaxception

invalidateHttpSession

public void invalidateHttpSession()
                           throws Jaxception
If "UseSession" or "AutoSessionData" have been configured as true in the configuration file for this page, this method can be used to invalidate the session.

Throws:
Jaxception

getAppContext

public java.lang.Object getAppContext()
                               throws Jaxception
This method will return the application server's or Jaxcent connector's application context.

If running with a standard Java servlet-container/application-server, the object returned is of type javax.servlet.ServletContext, and can be cast to that type.

If running with a direct Jaxcent connector for IIS/Apache, the object returned is of type jaxcentConnector.JaxcentAppContext.

Throws:
Jaxception
See Also:
saveInAppContext(java.lang.String, java.lang.Object), getFromAppContext(java.lang.String), getAppContextKeys()

onLoad

protected void onLoad()
Override to handle page loading. Data can be retrieved from the page at this time.


onFinalFormData

protected void onFinalFormData(java.util.Map formData)
Override to receive form data during page unloading. The data has the same format as getAllFormData. But at this time, no further interactions with the page are possible. The data can be saved in the session, or otherwise processed. Field verifications cannot be done here. For field verifications, add handler on buttons or other fields, and retrieve the data either individually or by calling getAllFormData().


getAllFormData

public java.util.Map getAllFormData()
                             throws Jaxception
Retrieve all form data on page. The data must be identifiable with a name or an ID. In addition to INPUT tags, also retrieves data from SELECT and TEXTAREA tags.

The returned Map maps names or ids, to values.

Multile checkboxes can have the same name and multiple values. These are separated by commas. If the checkbox (or none of the checkboxes) is not selected, there will still be a value, and this value will be an empty string.

For lists (SELECT), the value contains of a selected index, followed by a colon character and the text selected. (Convenient utility functions JaxcentObject.getSelectedIndex and JaxcentObject.getSelectedValue are available to parse it.)

Throws:
Jaxception

onUnload

protected void onUnload()
Override to handle page unloading.


getAllSessionData

public java.util.Map getAllSessionData(boolean getFromCurrentPage)
                                throws Jaxception
Get all data from session so far. If the "getFromCurrentPage" parameter is true, first retrieve current page's data into session, otherwise just returns the data collected so far. This method is only available if auto-session-data is set to true. If getFromCurrentPage is true, this method cannot be called from the constructor (before page loading.)

Throws:
Jaxception

navigate

public void navigate(java.lang.String url)
              throws Jaxception
Navigate to a given URL.

Throws:
Jaxception

goBack

public void goBack()
            throws Jaxception
Navigate back.

Throws:
Jaxception

goForward

public void goForward()
               throws Jaxception
Navigate forward.

Throws:
Jaxception

execJavaScriptCode

public void execJavaScriptCode(java.lang.String code,
                               boolean argsAsArray,
                               java.lang.Object[] args)
                        throws Jaxception
Call JavaScript, do not wait for results.

The arguments array can contain Strings, Integers, Doubles, Strings, Boolean, Integers, Jaxcent HTML Elements, or it can be null. If the argument array is not null, the "code" is just a JavaScript function name, and must not contain the parentheses character. In this case, the characters "( )" containing any arguments are appended to the "code". The array specifies the list of parameters. If the argument array is null, the "code" is evaluated as is, as an expression. To call a function with no args, use the form execJavaScriptCode( "myFunction()", null, false );

If the "argsAsArray" argument is true, the JavaScript function will be called with a single argument, which will be an array. Otherwise, the "args" array will be used as a list of arguments.

Throws:
Jaxception

execJavaScriptCode

public void execJavaScriptCode(java.lang.String code)
                        throws Jaxception
Execute JavaScript code, do not wait for results.

Same as execJavaScriptCode( code, false, null );

Throws:
Jaxception

evalJavaScriptCode

public java.lang.String evalJavaScriptCode(java.lang.String code,
                                           boolean argsAsArray,
                                           java.lang.Object[] args)
                                    throws Jaxception
Same as execJavaScriptCode, but waits for the result of the evaluation and returns it.

Throws:
Jaxception

evalJavaScriptCode

public java.lang.String evalJavaScriptCode(java.lang.String code)
                                    throws Jaxception
Execute JavaScript code, wait for results.

Same as evalJavaScriptCode( code, false, null );

Throws:
Jaxception

onJavaScriptRequest

protected void onJavaScriptRequest(java.lang.String cmd,
                                   java.lang.String[] args)
Override to process data from JavaScript methods sent by calling the "JaxcentServerRequest( args... );" function defined by the Jaxcent JavaScript file.

The JavaScript call is asynchronous and does not wait for server response -- if it is required to process a server response in JavaScript, define a function in JavaScript and call that function via execJavaScriptCode or evalJavaScriptCode, from your override of this method.

If JaxcentServerRequest was called at the client with no arguments, this method is called with null args. If JaxcentServerRequest was called with 1 arg, this method is passed that arg as "cmd", the "args" is null. Otherwise, "cmd" is the first arg passed to JaxcentServerRequest, and "args" contains the rest of the args.


setStatusText

public void setStatusText(java.lang.String text)
                   throws Jaxception
Set status text.

Throws:
Jaxception

getStatusText

public java.lang.String getStatusText()
                               throws Jaxception
Get status text.

Throws:
Jaxception

getScreenSize

public java.awt.Dimension getScreenSize()
                                 throws Jaxception
Get screen dimensions

Throws:
Jaxception

getWindowSize

public java.awt.Dimension getWindowSize()
                                 throws Jaxception
Get window dimensions

Throws:
Jaxception

getCurrentPath

public java.lang.String getCurrentPath()
Get the path of the URL that is being processed.


getRemoteAddr

public java.lang.String getRemoteAddr()
Get the client IP address.


getLocale

public java.util.Locale getLocale()
Get the remote locale if specified in HTTP Accept-Language header. (If not specified, returns server's default locale.)


getLocales

public java.util.Locale[] getLocales()
Get a list of remote locales if specified in HTTP Accept-Language header. The most preferred locale is first, followed by other locales in order of preference. (If none specified, returns server's default locale.)


showMessageDialog

public void showMessageDialog(java.lang.String message)
Show JavaScript alert dialog box to the user.


showConfirmDialog

public boolean showConfirmDialog(java.lang.String message)
                          throws Jaxception
Show JavaScript confirm dialog box to the user. Returns true for confirmation, false for cancellation.

Throws:
Jaxception

showInputDialog

public java.lang.String showInputDialog(java.lang.String prompt,
                                        java.lang.String defaultResult)
                                 throws Jaxception
Show JavaScript prompt dialog box to the user. If the defaultResult is not null, the input dialog is initialized with this text. If the user cancels, the returned value is null, otherwise it is the input from user.

Throws:
Jaxception

getCookies

public java.util.Map getCookies()
                         throws Jaxception
Get cookies from page as name->value pairs.

Throws:
Jaxception

getCookie

public java.lang.String getCookie(java.lang.String cookieName)
                           throws Jaxception
Get cookie value.

Throws:
Jaxception

setCookie

public void setCookie(java.lang.String cookieString)
Add cookie to page. cookieString must be a correctly formatted cookie string.


setCookie

public void setCookie(java.lang.String name,
                      java.lang.String value,
                      java.util.Date expires,
                      java.lang.String domain,
                      java.lang.String path,
                      boolean isSecure)
               throws Jaxception
Add cookie to page. Expires, domain, path may be null.

Throws:
Jaxception

deleteCookie

public void deleteCookie(java.lang.String cookieName)
Delete cookie.


deleteElementById

public void deleteElementById(java.lang.String id)
Delete an element referenced by an ID.


checkElementExists

public boolean checkElementExists(SearchType searchType,
                                  java.lang.String searchString,
                                  int searchIndex)
                           throws Jaxception
Check if an element exists, without attempting to assign it to an object.

Throws:
Jaxception

resetFromSession

public void resetFromSession()
                      throws Jaxception
Reset form data from session. Session must be available. This can be used to implement a "Reset" button.

Throws:
Jaxception

setFormSaveEnabled

public void setFormSaveEnabled(boolean enable)
Enable or disable saving of form data from current page into session, for AutoSessionData management. By default, this is enabled. To program the Reset/Submit type of behavior of earlier FORMs based web applications, disable saving form to session in the constructor, then in the Submit (or other button) handler, enable saving again before navigating away from the page.


getFormSaveEnabled

public boolean getFormSaveEnabled()
For AutoSessionData pages, returns whether saving form data in session upon page unloads, is enabled. This behavior is enabled by default, but can be turned off programmatically.


setBatchUpdates

public void setBatchUpdates(boolean batchUpdates)
Used to hold updates without sending them out to the client. This can improve performance by sending out a number of updates all at once.

If batch-updates has been set to true, no further data will be sent to the client until batch-updates is reset to false! This should be done in a try-finally clause.

Important: Do not attempt to retrieve data from page while batch-updates is true!


saveInAppContext

public void saveInAppContext(java.lang.String key,
                             java.lang.Object value)
                      throws Jaxception
Save data in the application context, using a given key (like a Map.)

Throws:
Jaxception

getFromAppContext

public java.lang.Object getFromAppContext(java.lang.String key)
                                   throws Jaxception
Get data from application context.

Throws:
Jaxception
See Also:
saveInAppContext(java.lang.String, java.lang.Object)

removeAppContextKey

public void removeAppContextKey(java.lang.String key)
                         throws Jaxception
Remove key from application context.

Throws:
Jaxception
See Also:
saveInAppContext(java.lang.String, java.lang.Object), getFromAppContext(java.lang.String)

getAppContextKeys

public java.util.Enumeration getAppContextKeys()
                                        throws Jaxception
Get list of key names from application context.

Throws:
Jaxception
See Also:
saveInAppContext(java.lang.String, java.lang.Object), getFromAppContext(java.lang.String)

getClientVersion

public java.lang.String getClientVersion()
Returns a string describing the connected page's version number, e.g. "2.1.1". It should be the same as the Jaxcent version.


getClientJaxcentURL

public java.lang.String getClientJaxcentURL()
Returns the URL used in the client for Jaxcent. The default is /JaxcentServlet21


getJaxcentVersion

public static java.lang.String getJaxcentVersion()
Return Jaxcent version.


makeContentURL

public java.lang.String makeContentURL(java.lang.String contentType,
                                       byte[] content,
                                       java.lang.String filename)
                                throws Jaxception
Returns a URL that will return a given content-type and bytes. The information is placed in the session. The URL is based upon the Jaxcent URL, and can be used for applications such as generating a PDF file. "UseSession" or "AutoSessionData" must be configured for the page. The "filename" argument can be null. If it is non-null, it will be appended to the servlet part of the URL and before the query string.

Throws:
Jaxception