com.webmethods.caf.faces.bean
Class BaseFacesBean

java.lang.Object
  extended by com.webmethods.caf.faces.bean.BaseFacesBean
Direct Known Subclasses:
BaseApplicationBean, BaseEventHandlerBean, BaseFacesSessionBean, BaseTaskRuleContext, EncodersBean

public class BaseFacesBean
extends Object

Base class for all faces managed beans. Can be used as a parent class for client managed beans.


Field Summary
protected static String DATA_BINDING_CLIENTS
          The String key for storing the map of data binding clients.
protected static String OUTCOME_ERROR
          Outcome for failed action
protected static String OUTCOME_OK
          Outcome for successful action
protected  Map resourcesProviders
          Map of resource providers with Locale as the keys.
 
Constructor Summary
BaseFacesBean()
          Default constructor
 
Method Summary
protected  MethodBinding createMethodBinding(String expression, Class[] args)
          Shortcut method for getFacesContext().getApplication().createMethodBinding(expression, args)
protected  ValueBinding createValueBinding(String expression)
          Shortcut method for getFacesContext().getApplication().createValueBinding(expression)
protected  void error(FacesMessage.Severity severity, String message, String details)
          Adds an error message to the faces context.
protected  void error(String message)
          Adds an error message to the faces context.
protected  void error(String message, String details)
          Adds an error message to the faces context.
protected  void error(String message, Throwable throwable)
          Adds an error message to the faces context.
protected  void error(Throwable throwable)
          Adds an error message to the faces context.
protected  Object getBean(String beanName)
          Returns reference to the managed bean with the given name
protected  FacesContext getFacesContext()
          Returns current faces context
protected  Locale getLocale()
          Returns locale for the current request/response.
protected static InputStream getResourceInputStream(String relPath)
          Returns an InputStream for a resource at the given path
protected  IContentProvider getResources(String baseName)
          Deprecated.  
protected  ResourceBundleContentProvider getResourcesProvider(String baseName)
          Returns ResourceBundleContentProvider for the current locale and baseName.
 Throwable getRootCause(Throwable ex)
          Returns root expception for the given exception
protected  String getStackTrace(Throwable t)
          Returns stack trace of the given exception
protected  Object getTreeAttribute(String key)
          Retrieves an Object from the tree's attribute map.
protected  boolean isUserInRole(String roleName)
          Checks if the current user is in specified local/logical role.
protected  void log(String message)
          Logs a message
protected  void log(String message, Throwable throwable)
          Logs an exception
protected  void log(Throwable throwable)
          Logs an exception
protected  void putTreeAttribute(String key, Object value)
          Places an Object on the tree's attribute map.
protected  void resetDataBindingClients()
          Resets data binding flags for the current request.
protected  boolean resolveDataBinding(String[][] bindingExpressions, Object bean, String varName)
          Shortcut method
protected  boolean resolveDataBinding(String[][] bindingExpressions, Object bean, String varName, boolean forceResolve, boolean cacheRightValues)
          Data Flow execution.
protected  Object resolveExpression(String expression)
          Return the result of the resolved value binding expression.
protected  boolean setValue(String expression, Object value)
          Sets value using given JSF value binding expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTCOME_OK

protected static final String OUTCOME_OK
Outcome for successful action

See Also:
Constant Field Values

OUTCOME_ERROR

protected static final String OUTCOME_ERROR
Outcome for failed action

See Also:
Constant Field Values

resourcesProviders

protected Map resourcesProviders
Map of resource providers with Locale as the keys.


DATA_BINDING_CLIENTS

protected static final String DATA_BINDING_CLIENTS
The String key for storing the map of data binding clients.

See Also:
Constant Field Values
Constructor Detail

BaseFacesBean

public BaseFacesBean()
Default constructor

Method Detail

createValueBinding

protected ValueBinding createValueBinding(String expression)
Shortcut method for getFacesContext().getApplication().createValueBinding(expression)

Parameters:
expression - value binding expression
Returns:
value binding for the given expression

createMethodBinding

protected MethodBinding createMethodBinding(String expression,
                                            Class[] args)
Shortcut method for getFacesContext().getApplication().createMethodBinding(expression, args)

Parameters:
expression - method binding expression
args - method argument types
Returns:
method binding for the given expression

resolveExpression

protected Object resolveExpression(String expression)
Return the result of the resolved value binding expression. BaseFacesBean.getFacesContext() must return a valid context for the current thread.

Parameters:
expression - JSF value binding expression
Returns:
result of the expression, can be null

setValue

protected boolean setValue(String expression,
                           Object value)
Sets value using given JSF value binding expression. Tries to convert the given value parameter to the target type of the value binding expression.

Parameters:
expression - JSF value binding expression
value - new value to assign
Returns:
true if the new value is different from the previous value

putTreeAttribute

protected void putTreeAttribute(String key,
                                Object value)
Places an Object on the tree's attribute map. The values persisted as long as the tree is persisted.

Parameters:
key - attribute key
value - attribute value

getTreeAttribute

protected Object getTreeAttribute(String key)
Retrieves an Object from the tree's attribute map.

Parameters:
key - the attribute key
Returns:
previously set attribute value or null if not found

resolveDataBinding

protected boolean resolveDataBinding(String[][] bindingExpressions,
                                     Object bean,
                                     String varName)
Shortcut method

See Also:
BaseFacesBean.resolveDataBinding(String[][], Object, String, boolean, boolean)

resolveDataBinding

protected boolean resolveDataBinding(String[][] bindingExpressions,
                                     Object bean,
                                     String varName,
                                     boolean forceResolve,
                                     boolean cacheRightValues)

Data Flow execution. The flow is a set of data assigments and action calls.

The varName parameter can be used to access java bean specified as bean parameter. For example, if varName=this, then binding expression can use "#{this.myproperty}" to access myproperty on the bean instance.

If the bean implements IRefreshableContentProvider and IRefreshable.isAutoRefresh() is true then it automatically calls IRefreshable.refresh() method if any of the right expressions differ from the values previously set on the bean.

By default bindings are evaluted once per request (action or render). Specifying forceResolve parameters as true will force the resolution.

If right expression returns null the previously cached value of that expression will be used, if cacheRightValues parameter is true. If null is a valid value, then use false for cacheRightValues

Parameters:
bindingExpressions - two dimentional array of left expression=right expression, or method expression.
bean - java bean instance, can be a managed bean instance, can be null.
varName - optional variable name that will point to the bean instance. Can be null.
forceResolve - set to true to force the resolution. If false it only happens once per request (action or render)
cacheRightValues - set to true if want cache non-null right expressions values and use them whenever right expression returns null. Set to false, if null is a valid value.
Returns:
true if data bindings have changed and the provider have not been auto-refreshed, i.e. it should be refreshed manually.

resetDataBindingClients

protected void resetDataBindingClients()
Resets data binding flags for the current request.


getBean

protected Object getBean(String beanName)
Returns reference to the managed bean with the given name

Parameters:
beanName - the name of the managed bean
Returns:
null if the bean cannot be found

getResourceInputStream

protected static InputStream getResourceInputStream(String relPath)
Returns an InputStream for a resource at the given path

Parameters:
relPath - relative to the web application root path to the resource
Returns:
input stream opened for this resource or null if resource is not found

log

protected void log(Throwable throwable)
Logs an exception

Parameters:
throwable - the exception

log

protected void log(String message,
                   Throwable throwable)
Logs an exception

Parameters:
message - the message
throwable - the exception

log

protected void log(String message)
Logs a message

Parameters:
message - the message

getStackTrace

protected String getStackTrace(Throwable t)
Returns stack trace of the given exception

Parameters:
t - the exception
Returns:
its stack trace

error

protected void error(FacesMessage.Severity severity,
                     String message,
                     String details)
Adds an error message to the faces context. This message can be display using Message control.

Parameters:
severity - severity of the message
message - the message
details - the details for the message

error

protected void error(String message,
                     String details)
Adds an error message to the faces context. This message can be display using Message control.

Parameters:
message - the message
details - the details for the message

error

protected void error(String message)
Adds an error message to the faces context. This message can be display using Message control.

Parameters:
message - the message

error

protected void error(Throwable throwable)
Adds an error message to the faces context. This message can be display using Message control.

Parameters:
throwable - the error exception

error

protected void error(String message,
                     Throwable throwable)
Adds an error message to the faces context. This message can be display using Message control.

Parameters:
message - the message
throwable - the error exception

getRootCause

public Throwable getRootCause(Throwable ex)
Returns root expception for the given exception

Parameters:
ex - the exception
Returns:
root exception or the exception itself

getFacesContext

protected FacesContext getFacesContext()
Returns current faces context

Returns:
null if faces context is not available for the current thread

isUserInRole

protected boolean isUserInRole(String roleName)
Checks if the current user is in specified local/logical role.

Parameters:
roleName - local/logical role name defined in this web or portlet application
Returns:
true if the current user belongs to this role.

getResources

protected IContentProvider getResources(String baseName)
Deprecated. 

Use BaseFacesBean.getResourcesProvider(String)


getResourcesProvider

protected ResourceBundleContentProvider getResourcesProvider(String baseName)
Returns ResourceBundleContentProvider for the current locale and baseName. The locale is specified by UIViewRoot. If message bundle is not specified or cannot be loaded the returned provider is empty.

Parameters:
baseName - resource bundle base name
Returns:
instance of ResourceBundleContentProvider for application resource bundle.

getLocale

protected Locale getLocale()
Returns locale for the current request/response.

Returns:
locale