nl.openedge.baritus
Class FormBeanCtrlBase

java.lang.Object
  extended bynl.openedge.baritus.FormBeanCtrlBase
All Implemented Interfaces:
org.infohazard.maverick.flow.Controller
Direct Known Subclasses:
FormBeanCtrl

public abstract class FormBeanCtrlBase
extends java.lang.Object
implements org.infohazard.maverick.flow.Controller

FormBeanBase is the class that does the real work within Baritus. Usually, you should extend the singleton implementation FormBeanCtrl. However, if you want to have behaviour like Maverick's ThrowawayFormBeanUser (a new instance of the controller is created on each request), you can extend from this class directly. Note that as method init(Node) is specific for the ControllerSingleton that is implemented in FormBeanCtrl, you do not have this method at your disposal here, hence you should do initialisation in your constructor instead.

Author:
Eelco Hillenius

Field Summary
static java.lang.String ERROR
          Common name for the typical "error" view.
static java.lang.String LOGON
          Common name for the typical "logon" view.
static java.lang.String REDIRECT
          Common name for the "redirect" view.
static java.lang.String REQUEST_ATTRIBUTE_EXECUTION_PARAMS
          Key for request attribute that is used to store the execution parameters for the current request.
static java.lang.String REQUEST_ATTRIBUTE_FORMBEANCONTEXT
          Key for request attribute that is used to store the formbean context.
static java.lang.String SESSION_KEY_CURRENT_LOCALE
          session key for the current locale.
static java.lang.String SUCCESS
          Common name for the typical "success" view.
 
Constructor Summary
FormBeanCtrlBase()
           
 
Method Summary
protected  void addInterceptor(Interceptor interceptor)
          Add an interceptor to the current list of interceptors.
protected  void addInterceptor(int index, Interceptor interceptor)
          Add an interceptor to the current list of interceptors at the specified position.
protected  void addPopulator(java.util.regex.Pattern pattern, FieldPopulator populator)
          Register a custom populator that overrides the default population process for all request parameters that match the regular expression stored in the provided pattern.
protected  void addPopulator(java.lang.String fieldName, FieldPopulator populator)
          Register a field populator for the given fieldName.
protected  void addValidationActivationRule(ValidationActivationRule rule)
          Register the rule for the whole form.
protected  void addValidator(FormValidator validator)
          Register a form validator.
protected  void addValidator(java.lang.String fieldName, FieldValidator validator)
          Register a field validator for the given fieldName.
protected  void addValidatorDelegate(nl.openedge.baritus.ValidatorDelegate validatorDelegate)
          Add a validator delegate.
protected  void doSetNoCache(org.infohazard.maverick.flow.ControllerContext cctx)
          Set http response headers that indicate that this page should not be cached.
 void fixExecutionParams(ExecutionParams params)
          Save the execution params that are used to influence the execution of the formBeanCtrl (like population, validation, etc).
protected  java.lang.String getConversionErrorLabelKey(java.lang.Class type, java.lang.String name, java.lang.Object triedValue)
          Get the message bundle key for a conversion error for the given type and field with the given name.
protected  FieldPopulator getDefaultPopulator()
          get the default field populator
protected  java.lang.String getErrorView(org.infohazard.maverick.flow.ControllerContext cctx, FormBeanContext formBeanContext)
          Get error view.
 ExecutionParams getExecutionParams(org.infohazard.maverick.flow.ControllerContext cctx)
          Get a deep copy of the execution params that are used to influence the execution of the formBeanCtrl (like population, validation, etc).
protected  java.util.Locale getLocaleForRequest(org.infohazard.maverick.flow.ControllerContext cctx, FormBeanContext formBeanContext)
          Get the prefered locale for the current request.
static java.lang.String getLocalizedMessage(java.lang.String key)
          Get localized message for given key.
protected static java.lang.String getLocalizedMessage(java.lang.String key, java.util.Locale locale)
          Get localized message for given key and locale.
protected static java.lang.String getLocalizedMessage(java.lang.String key, java.util.Locale locale, java.lang.Object[] parameters)
          Get localized message for given key and locale and format it with the given parameters.
protected static java.lang.String getLocalizedMessage(java.lang.String key, java.lang.Object[] parameters)
          Get localized message for given key and locale and format it with the given parameters.
 java.lang.String getPropertyNameKey(java.lang.String name)
          Get the message bundle key for the given property name.
protected  java.util.List getValidatorDelegates()
          Get the list of registered validator delegates.
protected  MultiHashMap getValidators(java.lang.String fieldName)
          Get the fieldValidators that were registered with the given fieldName.
 java.lang.String go(org.infohazard.maverick.flow.ControllerContext cctx)
          Executes this controller.
protected  boolean isNullOrEmpty(java.lang.Object value)
          Check if the value is null or empty.
protected abstract  java.lang.Object makeFormBean(FormBeanContext formBeanContext, org.infohazard.maverick.flow.ControllerContext cctx)
          This method will be called to produce a bean whose properties will be populated with the http currentRequest parameters, the resulting object will be placed in the formBeanContext after this call.
protected abstract  java.lang.String perform(FormBeanContext formBeanContext, org.infohazard.maverick.flow.ControllerContext cctx)
          This method must be overriden to perform application logic.
protected  void removeInterceptor(Interceptor interceptor)
          Remove an interceptor from the current list of interceptors.
protected  void removePopulator(java.util.regex.Pattern pattern)
          Register a custom populator that overrides the default population process for all request parameters that match the regular expression stored in the provided pattern.
protected  void removePopulator(java.lang.String fieldName)
          De-register the field populator that was registered with the given fieldName.
protected  void removeValidationActivationRule(ValidationActivationRule rule)
          De-register the given rule for the whole form.
protected  void removeValidator(FormValidator validator)
          De-register the given form level validator.
protected  void removeValidator(java.lang.String fieldName, FieldValidator validator)
          De-register the given validator that was registered with the given fieldName.
protected  void removeValidatorDelegate(nl.openedge.baritus.ValidatorDelegate validatorDelegate)
          Remove a validator delegate.
protected  void removeValidators(java.lang.String fieldName)
          De-register the fieldValidators that were registered with the given fieldName.
 void setConversionErrorForField(org.infohazard.maverick.flow.ControllerContext cctx, FormBeanContext formBeanContext, java.lang.Class targetType, java.lang.String name, java.lang.Object triedValue, java.lang.Throwable t)
          Set error for field with name 'name' in case of a conversion error.
protected  void setDefaultPopulator(FieldPopulator populator)
          set the default field populator
 void setOverrideField(org.infohazard.maverick.flow.ControllerContext cctx, FormBeanContext formBeanContext, java.lang.String name, java.lang.Object triedValue, java.lang.Throwable t, FieldValidator validator)
          Set the override value for the provdied field name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUCCESS

public static final java.lang.String SUCCESS
Common name for the typical "success" view.

See Also:
Constant Field Values

LOGON

public static final java.lang.String LOGON
Common name for the typical "logon" view.

See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
Common name for the typical "error" view.

See Also:
Constant Field Values

REDIRECT

public static final java.lang.String REDIRECT
Common name for the "redirect" view.

See Also:
Constant Field Values

SESSION_KEY_CURRENT_LOCALE

public static final java.lang.String SESSION_KEY_CURRENT_LOCALE
session key for the current locale.

See Also:
Constant Field Values

REQUEST_ATTRIBUTE_FORMBEANCONTEXT

public static final java.lang.String REQUEST_ATTRIBUTE_FORMBEANCONTEXT
Key for request attribute that is used to store the formbean context. This key is used to be able to reuse the formbean context with multiple commands within the same request without having to figure out what the last Maverick beanName was (it is possible to override the name of the bean - 'model' by default - that is stored in the request by Maverick for each view). Not intended for use outside this class.

See Also:
Constant Field Values

REQUEST_ATTRIBUTE_EXECUTION_PARAMS

public static final java.lang.String REQUEST_ATTRIBUTE_EXECUTION_PARAMS
Key for request attribute that is used to store the execution parameters for the current request. Not intended for use outside this class.

See Also:
Constant Field Values
Constructor Detail

FormBeanCtrlBase

public FormBeanCtrlBase()
Method Detail

go

public final java.lang.String go(org.infohazard.maverick.flow.ControllerContext cctx)
                          throws javax.servlet.ServletException
Executes this controller. You should verride the perform method to provide application logic. This method handles all callbacks and interceptors. See the manual for the path(s) of execution.

Specified by:
go in interface org.infohazard.maverick.flow.Controller
Parameters:
cctx - maverick controller context
Returns:
String name of the view
Throws:
javax.servlet.ServletException
See Also:
Controller.go(org.infohazard.maverick.flow.ControllerContext)

setConversionErrorForField

public void setConversionErrorForField(org.infohazard.maverick.flow.ControllerContext cctx,
                                       FormBeanContext formBeanContext,
                                       java.lang.Class targetType,
                                       java.lang.String name,
                                       java.lang.Object triedValue,
                                       java.lang.Throwable t)
Set error for field with name 'name' in case of a conversion error. uses getConversionErrorLabelKey to get the specific label. NOTE: this will be used in case of conversion errors ONLY. If a validator causes an error (after normal conversion) the error message of the validator will be used, not this method. The message is formatted with objects triedValue, name (by calling getPropertyNameKey) and t, so you can use {0}, {1} and {2} resp. with your custom message. If there is an entry in the default resource bundle that has form: formname.[name] (eg. formname.firstname and formname.lastname) the name parameter {1} will be replaced with this value.

Parameters:
cctx - controller context
formBeanContext - context with form bean
targetType - type of target property
name - name of field
triedValue - value that was tried for population
t - exception

getPropertyNameKey

public java.lang.String getPropertyNameKey(java.lang.String name)
Get the message bundle key for the given property name.

Parameters:
name - property name
Returns:
String the message bundle key of the property, defaults to "formname." + name

getConversionErrorLabelKey

protected java.lang.String getConversionErrorLabelKey(java.lang.Class type,
                                                      java.lang.String name,
                                                      java.lang.Object triedValue)
Get the message bundle key for a conversion error for the given type and field with the given name.

Parameters:
type - type of the target property that threw the conversion error
name - name of the target property
triedValue - the value that could not be converted to the type of the target property
Returns:
String message bundle key

setOverrideField

public void setOverrideField(org.infohazard.maverick.flow.ControllerContext cctx,
                             FormBeanContext formBeanContext,
                             java.lang.String name,
                             java.lang.Object triedValue,
                             java.lang.Throwable t,
                             FieldValidator validator)
Set the override value for the provdied field name. This method will be called if a property could not be set on the form or did not pass validation. by registering the 'original' value (possibly modified by overrides of either this method or the 'getOverrideValue' of the validator that was the cause of the validation failure) end users can have their 'wrong' input value shown.

Parameters:
cctx - controller context
formBeanContext - context with form bean
name - name of the field
triedValue - the user input value/ currentRequest parameter
t - exception if known (may be null)
validator - the validator that was the cause of the validation failure, if one (is null if this was a conversion error)

perform

protected abstract java.lang.String perform(FormBeanContext formBeanContext,
                                            org.infohazard.maverick.flow.ControllerContext cctx)
                                     throws java.lang.Exception
This method must be overriden to perform application logic. By default, that method will only then be called when population & validation succeeded, and no FlowExceptions were thrown by interceptors.

Parameters:
formBeanContext - context with the populated bean returned by makeFormBean().
cctx - maverick controller context.
Returns:
String view to display
Throws:
java.lang.Exception - As a last fallthrough, exceptions are handled by the framework. It is advisable however, to keep control of the error reporting, and let this method do the exception handling

makeFormBean

protected abstract java.lang.Object makeFormBean(FormBeanContext formBeanContext,
                                                 org.infohazard.maverick.flow.ControllerContext cctx)
This method will be called to produce a bean whose properties will be populated with the http currentRequest parameters, the resulting object will be placed in the formBeanContext after this call.

Parameters:
formBeanContext - the form bean context. If this is the first control within a request, the formBeanContext will be empty. If this is a not the first control that is called within a request (i.e. more controls are linked together), and execution parameters property reuseFormBeanContext is true (which is the default), the formBeanContext may allready contain error registrations, and contains the formBean that was used in the control before this one.
cctx - controller context with references to request, response etc.
Returns:
Object instance of bean that should be populated. Right after the call to makeFormBean, the instance will be set in the formBeanContext as property 'bean'

addValidatorDelegate

protected void addValidatorDelegate(nl.openedge.baritus.ValidatorDelegate validatorDelegate)
Add a validator delegate. ValidatorDelegates can do validation on input and populated form beans. Besides the allways used DefaultValidatorDelegate, users of Baritus can register additional delegates, for instance to be able to plug in validator mechanisms like FormProc or Commons Validator.

Parameters:
validatorDelegate -

removeValidatorDelegate

protected void removeValidatorDelegate(nl.openedge.baritus.ValidatorDelegate validatorDelegate)
Remove a validator delegate.

Parameters:
validatorDelegate -

getValidatorDelegates

protected java.util.List getValidatorDelegates()
Get the list of registered validator delegates.

Returns:
the list of registered validator delegates, possibly null.

addValidator

protected void addValidator(java.lang.String fieldName,
                            FieldValidator validator)
Register a field validator for the given fieldName. multiple fieldValidators for one key are allowed.

Parameters:
fieldName - name of field
validator - validator instance

addValidator

protected void addValidator(FormValidator validator)
Register a form validator. form validators will be called after the field level validators executed successfully, and thus can be used to check consistency etc.

Parameters:
validator - the form level validator

removeValidators

protected void removeValidators(java.lang.String fieldName)
De-register the fieldValidators that were registered with the given fieldName.

Parameters:
fieldName - name of field

removeValidator

protected void removeValidator(java.lang.String fieldName,
                               FieldValidator validator)
De-register the given validator that was registered with the given fieldName.

Parameters:
fieldName - name of field
validator - the validator to remove for the given field

removeValidator

protected void removeValidator(FormValidator validator)
De-register the given form level validator.

Parameters:
validator - form validator

addValidationActivationRule

protected void addValidationActivationRule(ValidationActivationRule rule)
Register the rule for the whole form.

Parameters:
rule - activation rule

removeValidationActivationRule

protected void removeValidationActivationRule(ValidationActivationRule rule)
De-register the given rule for the whole form.

Parameters:
rule - global rule to remove

getValidators

protected MultiHashMap getValidators(java.lang.String fieldName)
Get the fieldValidators that were registered with the given fieldName.

Parameters:
fieldName - name of the field
Returns:
MultiMap the fieldValidators that were registered with the given fieldName

addPopulator

protected void addPopulator(java.lang.String fieldName,
                            FieldPopulator populator)
Register a field populator for the given fieldName. Field populators override the default population of a property on the current form.

Parameters:
fieldName - name of field
populator - populator instance

removePopulator

protected void removePopulator(java.lang.String fieldName)
De-register the field populator that was registered with the given fieldName.

Parameters:
fieldName - name of field

addPopulator

protected void addPopulator(java.util.regex.Pattern pattern,
                            FieldPopulator populator)
Register a custom populator that overrides the default population process for all request parameters that match the regular expression stored in the provided pattern. The registered populators are tried for a match in order of registration. For each match that was found, the populator that was registered for it will be used, and the request parameter(s) will be removed from the map that is used for population. As a consequence, regexFieldPopulators overrule 'normal' field populators, and if more than one regex populator would match the parameters, only the first match is used. Custom populators are stored by name of the property.

Parameters:
pattern - regex pattern
populator - populator instance

removePopulator

protected void removePopulator(java.util.regex.Pattern pattern)
Register a custom populator that overrides the default population process for all request parameters that match the regular expression stored in the provided pattern. The registered populators are tried for a match in order of registration. For each match that was found, the populator that was registered for it will be used, and the request parameter(s) will be removed from the map that is used for population. As a consequence, regexFieldPopulators overrule 'normal' field populators, and if more than one regex populator would match the parameters, only the first match is used. Custom populators are stored by name of the property.

Parameters:
pattern - regex pattern

setDefaultPopulator

protected void setDefaultPopulator(FieldPopulator populator)
set the default field populator

Parameters:
populator - the default field populator

getDefaultPopulator

protected FieldPopulator getDefaultPopulator()
get the default field populator

Returns:
FieldPopulator the default field populator

addInterceptor

protected void addInterceptor(Interceptor interceptor)
Add an interceptor to the current list of interceptors.

Parameters:
interceptor - the interceptor to add to the current list of interceptors

addInterceptor

protected void addInterceptor(int index,
                              Interceptor interceptor)
Add an interceptor to the current list of interceptors at the specified position.

Parameters:
index - index position where to insert the interceptor
interceptor - the interceptor to add to the current list of interceptors

removeInterceptor

protected void removeInterceptor(Interceptor interceptor)
Remove an interceptor from the current list of interceptors.

Parameters:
interceptor - the interceptor to remove from the current list of interceptors

isNullOrEmpty

protected boolean isNullOrEmpty(java.lang.Object value)
Check if the value is null or empty.

Parameters:
value - object to check on
Returns:
true if value is not null AND not empty (e.g. in case of a String or Collection)

getLocalizedMessage

public static java.lang.String getLocalizedMessage(java.lang.String key)
Get localized message for given key.

Parameters:
key - key of message
Returns:
String localized message

getLocalizedMessage

protected static java.lang.String getLocalizedMessage(java.lang.String key,
                                                      java.util.Locale locale)
Get localized message for given key and locale. If locale is null, the default locale will be used.

Parameters:
key - key of message
locale - locale for message
Returns:
String localized message

getLocalizedMessage

protected static java.lang.String getLocalizedMessage(java.lang.String key,
                                                      java.lang.Object[] parameters)
Get localized message for given key and locale and format it with the given parameters. If locale is null, the default locale will be used.

Parameters:
key - key of message
parameters - parameters for the message
Returns:
String localized message

getLocalizedMessage

protected static java.lang.String getLocalizedMessage(java.lang.String key,
                                                      java.util.Locale locale,
                                                      java.lang.Object[] parameters)
Get localized message for given key and locale and format it with the given parameters. If locale is null, the default locale will be used.

Parameters:
key - key of message
locale - locale for message
parameters - parameters for the message
Returns:
String localized message

getLocaleForRequest

protected java.util.Locale getLocaleForRequest(org.infohazard.maverick.flow.ControllerContext cctx,
                                               FormBeanContext formBeanContext)
Get the prefered locale for the current request. IF a user is set in the form, the preferedLocale will be checked for this user. IF a locale is found as an attribute in the session with key SESSION_KEY_CURRENT_LOCALE, the previous found locale(s) will be replaced with this value.

Parameters:
cctx - controller context
formBeanContext - context
Returns:
Locale the prefered locale

getErrorView

protected java.lang.String getErrorView(org.infohazard.maverick.flow.ControllerContext cctx,
                                        FormBeanContext formBeanContext)
Get error view. This is 'error' by default.

Parameters:
cctx - controller context
formBeanContext - context
Returns:
String logical name of view

doSetNoCache

protected void doSetNoCache(org.infohazard.maverick.flow.ControllerContext cctx)
Set http response headers that indicate that this page should not be cached.

Parameters:
cctx - controller context

getExecutionParams

public ExecutionParams getExecutionParams(org.infohazard.maverick.flow.ControllerContext cctx)
Get a deep copy of the execution params that are used to influence the execution of the formBeanCtrl (like population, validation, etc). If an instance was found in the current request, this will be used. NOTE: changes to these parameters will be local for the current request. If you want the changes to be kept for all subsequent uses of the control, call fixExecutionParams.

Parameters:
cctx - Maverick context with the current request, null if it should be ignored.
Returns:
ExecutionParams the execution params that are used to influence the execution of the formBeanCtrl (like population, validation, etc).

fixExecutionParams

public void fixExecutionParams(ExecutionParams params)
Save the execution params that are used to influence the execution of the formBeanCtrl (like population, validation, etc).

Parameters:
params - the execution params that are used to influence the execution of the formBeanCtrl (like population, validation, etc).


Copyright © 2003-2004 Open Edge. All Rights Reserved.