net.jot.web.forms
Class JOTForm

java.lang.Object
  extended by net.jot.web.view.JOTViewBlock
      extended by net.jot.web.view.JOTViewTag
          extended by net.jot.web.forms.JOTForm
Direct Known Subclasses:
JOTGeneratedForm

public abstract class JOTForm
extends JOTViewTag

Generic class for handling HTML forms (validate, save the values when validation fail etc...) You probably will want to use one of the subclass rather than this directly: ie: JOTGeneratedForm, JOTDBForm etc... Or you can Subclass this directly for more control Form objects provide easy parsing/validation of web forms

Author:
thibautc

Field Summary
static java.lang.String REQUEST_ID
           
 
Fields inherited from class net.jot.web.view.JOTViewBlock
content, visible
 
Constructor Summary
JOTForm()
           
 
Method Summary
 void defineField(java.lang.String name, int type)
          Define a field of the form (name/field type) You should define all the types you want to use / see in the html form Typically you make calls to this method from within init()
 JOTFormElement get(java.lang.String name)
          Return an element (by name)
 java.util.Hashtable getAll()
          Return all the form fields Hastable of {name:JOTFormElement}
 java.util.Hashtable getErrors()
           
 java.lang.String getResult()
          Result of the form processing: ie: success, validationFailure etc...
 boolean hasValidated()
           
abstract  void init(JOTFlowRequest request)
          You can use this method to set initial form values (Called the first time the form is created) Ex: defineField("name", JOTFormConst.TEXTAREA); get("fname").setValue("toto");
 void preValidate()
          Override this function if you want to do things before validation runs
 void reparseForm(JOTFlowRequest request)
          if new values are found in the request, this is going to be called to parse the new values
abstract  void save(JOTFlowRequest request)
          This will be called after a succesful validation This is where you save your form data ..
 void setErrors(java.util.Hashtable errors)
           
 void setHasValidated(boolean hasValidated)
           
 void setResult(java.lang.String result)
           
abstract  java.util.Hashtable validate(JOTFlowRequest request)
          You need to define this method to you want to validate your form.
abstract  boolean validatePermissions(JOTFlowRequest request)
          Implement this and return true if user is authorized to use this form
 
Methods inherited from class net.jot.web.view.JOTViewTag
getFlags, getTagProperties, removeFlag, setFlag, setTagProperty, unsetTagProperty
 
Methods inherited from class net.jot.web.view.JOTViewBlock
getContent, isVisible, setContent, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUEST_ID

public static final java.lang.String REQUEST_ID
See Also:
Constant Field Values
Constructor Detail

JOTForm

public JOTForm()
Method Detail

validatePermissions

public abstract boolean validatePermissions(JOTFlowRequest request)
Implement this and return true if user is authorized to use this form

Parameters:
request -
Returns:

init

public abstract void init(JOTFlowRequest request)
                   throws java.lang.Exception
You can use this method to set initial form values (Called the first time the form is created) Ex: defineField("name", JOTFormConst.TEXTAREA); get("fname").setValue("toto");

Throws:
java.lang.Exception

validate

public abstract java.util.Hashtable validate(JOTFlowRequest request)
                                      throws java.lang.Exception
You need to define this method to you want to validate your form. The returned a hashtable or error messages (String error_id, String error_text) The hashtable should be empty/null if no errors occured. Ex: Hashtable h=new Hashtable(); h.put("error1","Password invalid");

Throws:
java.lang.Exception

save

public abstract void save(JOTFlowRequest request)
                   throws java.lang.Exception
This will be called after a succesful validation This is where you save your form data .. wherever you want to save it like a database etc ... Implementation note: if the field is saveAutomatically=false, then we won't save that field

Throws:
java.lang.Exception

preValidate

public void preValidate()
Override this function if you want to do things before validation runs


defineField

public void defineField(java.lang.String name,
                        int type)
Define a field of the form (name/field type) You should define all the types you want to use / see in the html form Typically you make calls to this method from within init()

Parameters:
name -
type -

getAll

public java.util.Hashtable getAll()
Return all the form fields Hastable of {name:JOTFormElement}


get

public JOTFormElement get(java.lang.String name)
Return an element (by name)

Parameters:
name -
Returns:

reparseForm

public void reparseForm(JOTFlowRequest request)
if new values are found in the request, this is going to be called to parse the new values

Parameters:
request -

getErrors

public java.util.Hashtable getErrors()

setErrors

public void setErrors(java.util.Hashtable errors)

hasValidated

public boolean hasValidated()

setHasValidated

public void setHasValidated(boolean hasValidated)

getResult

public java.lang.String getResult()
Result of the form processing: ie: success, validationFailure etc...

Returns:

setResult

public void setResult(java.lang.String result)