com.mizar.faces.javax.utils
Class FacesUtils

java.lang.Object
  extended by com.mizar.faces.javax.utils.FacesUtils

public class FacesUtils
extends java.lang.Object


Nested Class Summary
static class FacesUtils.ScopeType
           
 
Constructor Summary
FacesUtils()
           
 
Method Summary
static void addErrorMessage(java.lang.String message)
           
static void addFatalMessage(java.lang.String message)
           
static void addInfoMessage(java.lang.String message)
           
static void addMessage(javax.faces.application.FacesMessage.Severity severity, java.lang.String message)
           
static void addMessage(javax.faces.application.FacesMessage.Severity severity, java.lang.String message, javax.faces.context.FacesContext fc)
           
static void addTableToWorkBook(org.apache.poi.hssf.usermodel.HSSFWorkbook workBook, java.lang.String pageName, java.util.List<RowInterface> beans)
           
static javax.faces.model.SelectItem[] addToSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Object value, java.lang.String label, int index)
          Insert an element into an array
static void addWarningMessage(java.lang.String message)
           
static javax.el.MethodExpression createMethodExpression(java.lang.String methodExpression, java.lang.Class<?> returnType, java.lang.Class[] params)
          Create MethodExpression object based on the given action expression string and return type.
static javax.el.ValueExpression createValueExpression(java.lang.String valueExpression, java.lang.Class<?> valueType)
          Create ValueExpression object based on the given value expression string and value type.
static void dispatch(java.lang.String path)
          UNTESTED -- I'm not entirely sure what this will do but I suspect that we might want to do it some day.
static javax.faces.component.UIComponent findChild(javax.faces.component.UIComponent component, java.lang.Class childClass)
          The method starts with component and examines all child components until it finds one matching the childClass component is checked first and will return itself if the criteria is met.
static javax.faces.component.UIComponent findComponent(java.lang.String id)
          The method wraps FacesContext.getCurrentInstance().getViewRoot().findComponent(id) with the appropriate bail outs if anything returns null.
static javax.faces.component.UIComponent findParent(javax.faces.component.UIComponent component, java.lang.Class parentClass)
          The method starts with component and examines all parent components until it finds one matching the parentClass component is checked first and will return itself if the criteria is met.
static javax.faces.component.UIComponent findParent(javax.faces.component.UIComponent component, java.lang.String name)
          The method starts with component and examines all parent components until it finds one with an <f:attribute> tag with the corresponding name and value arguments.
static javax.faces.component.UIComponent findParent(javax.faces.component.UIComponent component, java.lang.String name, java.lang.String value)
          The method starts with component and examines all parent components until it finds one with an <f:attribute> tag with the corresponding name and value arguments.
static java.lang.Object getCurrentInstance(java.lang.String managedBeanName)
          Handles of the overhead of getting the current Faces instance, etc.
static java.lang.String getDescriptionFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Long id)
          getDescriptionFromSelectItems gets the corresponding selectItem description from the selectItem based on the id.
static java.lang.String getDescriptionFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.String name)
          getDescriptionFromSelectItems gets the corresponding selectItem label from the selectItem based on the value.
static org.apache.poi.hssf.usermodel.HSSFWorkbook getExcelFromList(java.util.List<RowInterface> beans)
          This method will convert a list of JPA beans with an @Form annotation into an Excel spreadsheet
static java.lang.String getFacesParamValue(java.lang.String paramName)
          Returns the String value of an <f:param /> of the given name
static java.lang.String getFacesParamValue(javax.faces.component.UIComponent component)
           
static java.lang.reflect.Method getHandlerMethod(java.lang.String el)
          This method makes the assumption that the bean class has one and only one method with the name provided.
static java.lang.Object getHandlerObject(java.lang.String el)
           
static java.lang.String getInfoBox(FormInfo form)
           
static java.lang.String getInfoBox(java.lang.Object bean)
           
static org.jdom.Document getJdomDocument(javax.servlet.ServletContext context, java.lang.String fileName)
          This method is useful if you already have the ServletContext.
static org.jdom.Document getJdomDocument(java.lang.String fileName)
           
static java.lang.String getLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Long value)
          gets the corresponding selectItem label from the selectItem based on the value.
static java.lang.String getLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.String value)
          gets the corresponding selectItem label from the selectItem based on the value.
static java.lang.Object getManagedBeanInstance(java.lang.String managedBeanName)
           
static javax.faces.component.UIComponent getParent(javax.faces.component.UIComponent child, java.lang.Class parentClass)
           
static java.util.List<java.lang.String> getRegisteredBeans(FacesUtils.ScopeType scopeType)
           
static java.util.ResourceBundle getResourceBundle(java.lang.String resourceName)
          Get the locale resousources associated with current locale.
static javax.faces.component.UIViewRoot getViewRoot(java.lang.String viewId)
           
static boolean isAllDetailsEnabled(javax.faces.component.UIComponent uic)
          Checks uic to see if an allDetailsEnabled argument exists and if it is true.
static boolean isAutoSubmit(javax.faces.component.UIComponent uic)
          Checks uic to see if an autoSubmit argument exists and if it is true.
static boolean isDisabled(javax.faces.component.UIComponent uic)
          Checks uic to see if an disabled argument exists and if it is true.
static void launchApprovalDialog(java.lang.String title, java.lang.String remark, javax.faces.component.UIComponent source, java.util.HashMap userProps)
           
static void launchDialog(java.lang.String title, java.lang.String remark, java.lang.String name, javax.faces.component.UIComponent source, java.util.HashMap winProps, java.util.HashMap userProps)
           
static void redirect(java.lang.String location)
          UNTESTED -- I'm not entirely sure what this will do but I suspect that we might want to do it some day.
static javax.faces.model.SelectItem[] removeFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Object value)
          STATUS COMPLETELY UNTESTED
static void setActionListener(org.apache.myfaces.trinidad.component.UIXCommand uic, java.lang.String el)
           
static boolean setAllDetailsEnabled(javax.faces.component.UIComponent uic, boolean state)
          The method sets the state of the allDetailsEnabled attribute for a CoreTable.
static boolean setAutoSubmit(javax.faces.component.UIComponent uic, boolean state)
          The method sets the state of an autoSubmit attribute for a component.
static void setCurrentInstance(java.lang.String managedBeanName, java.lang.Object newObject)
          Handles of the overhead of getting the current Faces instance, etc.
static void setDescriptionFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Object value, java.lang.String description)
          Changes the description of a given selectItem in a SelectItems[] array.
static boolean setDisabled(javax.faces.component.UIComponent uic, boolean state)
          THIS METHOD DOES NOT WORK ...
static void setLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Long value, java.lang.String newLabel)
          Changes the label of selectItem(s) matching given value in a SelectItems[] array.
static void setLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.Long value, java.lang.String newLabel, java.lang.String newDescription)
          Sets the label and description for selectItem(s) maching given value in a SelectItems[] array.
static void setLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems, java.lang.String value, java.lang.String newLabel)
          Changes the label of a given selectItem in a SelectItems[] array.
static void setLaunchListener(org.apache.myfaces.trinidad.component.UIXCommand uic, java.lang.String el)
           
static void setReturnListener(org.apache.myfaces.trinidad.component.UIXCommand uic, java.lang.String el)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FacesUtils

public FacesUtils()
Method Detail

addMessage

public static void addMessage(javax.faces.application.FacesMessage.Severity severity,
                              java.lang.String message,
                              javax.faces.context.FacesContext fc)

addMessage

public static void addMessage(javax.faces.application.FacesMessage.Severity severity,
                              java.lang.String message)

addInfoMessage

public static void addInfoMessage(java.lang.String message)

addWarningMessage

public static void addWarningMessage(java.lang.String message)

addErrorMessage

public static void addErrorMessage(java.lang.String message)

addFatalMessage

public static void addFatalMessage(java.lang.String message)

getParent

public static javax.faces.component.UIComponent getParent(javax.faces.component.UIComponent child,
                                                          java.lang.Class parentClass)

createValueExpression

public static javax.el.ValueExpression createValueExpression(java.lang.String valueExpression,
                                                             java.lang.Class<?> valueType)
Create ValueExpression object based on the given value expression string and value type. This is to be used in UIComponent#setValueExpression(). Example: dataTable.setValueExpression("value", createValueExpression("#{myBean.dataList}", List.class));

Parameters:
valueExpression - The value expression string, e.g. "#{myBean.someValue}".
valueType - The actual value object type, e.g. String.class.
Returns:
The ValueExpression object to be used in UIComponent#setValueExpression().

createMethodExpression

public static javax.el.MethodExpression createMethodExpression(java.lang.String methodExpression,
                                                               java.lang.Class<?> returnType,
                                                               java.lang.Class[] params)
Create MethodExpression object based on the given action expression string and return type. This is to be used in UICommand#setActionExpression(). Example: saveButton.setActionExpression(createMethodExpression("#{myBean.saveDataList}", String.class, null));

Parameters:
methodExpression - The action expression string, e.g. "#{myBean.action}".
returnType - The actual return type of the action, e.g. String.class or null (void).
params - The expected parameter types for the method to be found. May be null if no parameters are required.
Returns:
The MethodExpression object to be used in UICommand#setActionExpression().

dispatch

public static void dispatch(java.lang.String path)
                     throws java.io.IOException
UNTESTED -- I'm not entirely sure what this will do but I suspect that we might want to do it some day.

Parameters:
path - Context relative path to the specified resource, which must start with a slash ("/") character
Throws:
java.io.IOException

redirect

public static void redirect(java.lang.String location)
                     throws java.io.IOException
UNTESTED -- I'm not entirely sure what this will do but I suspect that we might want to do it some day.

Parameters:
location - The redirect location URL, e.g. http://www.google.com
Throws:
java.io.IOException

getCurrentInstance

public static java.lang.Object getCurrentInstance(java.lang.String managedBeanName)
Handles of the overhead of getting the current Faces instance, etc. to return the current instance of a managed bean object.

Parameters:
managedBeanName - managedBean to retreive
Returns:
the current instance as resolved by VariableResolver

setCurrentInstance

public static void setCurrentInstance(java.lang.String managedBeanName,
                                      java.lang.Object newObject)
Handles of the overhead of getting the current Faces instance, etc. to set the current instance of the object

Parameters:
managedBeanName - managedBean to set
newObject - the value to set

getHandlerMethod

public static java.lang.reflect.Method getHandlerMethod(java.lang.String el)
This method makes the assumption that the bean class has one and only one method with the name provided. It does not check the number of arguments or the types of arguments. The method does search super classes.

Parameters:
el - a valid EL method expression; e.g. #{ManagedBean.getList}
Returns:
the first method found in the bean with a matching name.

getHandlerObject

public static java.lang.Object getHandlerObject(java.lang.String el)

getManagedBeanInstance

public static java.lang.Object getManagedBeanInstance(java.lang.String managedBeanName)
Parameters:
managedBeanName -
Returns:
the current instance of the managed bean
See Also:
FacesContext.getELContext(), ELContext.getELResolver(), ELResolver

getViewRoot

public static javax.faces.component.UIViewRoot getViewRoot(java.lang.String viewId)
Parameters:
viewId - the location of the page, e.g. "/SiteAddDialog.jspx"
Returns:
a new UIViewRoot instance

setDisabled

public static boolean setDisabled(javax.faces.component.UIComponent uic,
                                  boolean state)
THIS METHOD DOES NOT WORK ... PUT IT ON THE LIST TO FIX The method sets the state of an disabled attribute for a component. It does not check whether or not the disabled attribute is valid for the component.

Parameters:
uic - the component to set the disabled attribute for
state - the state to set the disabled attribute
Returns:
the previous state of the disabled attribute; false if not defined

isDisabled

public static boolean isDisabled(javax.faces.component.UIComponent uic)
Checks uic to see if an disabled argument exists and if it is true.

Parameters:
uic - a UIComponent to test presense of disabled="true"
Returns:
true if an disabled argument exists and it is true otherwise false

setAutoSubmit

public static boolean setAutoSubmit(javax.faces.component.UIComponent uic,
                                    boolean state)
The method sets the state of an autoSubmit attribute for a component. It does not check whether or not the autoSubmit attribute is valid for the component.

Parameters:
uic - the component to set the autoSubmit attribute for
state - the state to set the autoSubmit attribute
Returns:
the previous state of the autoSubmit attribute; false if not defined

isAutoSubmit

public static boolean isAutoSubmit(javax.faces.component.UIComponent uic)
Checks uic to see if an autoSubmit argument exists and if it is true.

Parameters:
uic - a UIComponent to test presense of autoSubmit="true"
Returns:
true if an autoSubmit argument exists and it is true otherwise false

setAllDetailsEnabled

public static boolean setAllDetailsEnabled(javax.faces.component.UIComponent uic,
                                           boolean state)
The method sets the state of the allDetailsEnabled attribute for a CoreTable. Checks that the class name of uic starts with "CoreTable"

Parameters:
uic - the component to set the allDetailsEnabled attribute for
state - the state to set the allDetailsEnabled attribute
Returns:
the previous state of the allDetailsEnabled attribute; false if not defined

isAllDetailsEnabled

public static boolean isAllDetailsEnabled(javax.faces.component.UIComponent uic)
Checks uic to see if an allDetailsEnabled argument exists and if it is true.

Parameters:
uic - a UIComponent to test presense of allDetailsEnabled="true"
Returns:
true if an allDetailsEnabled argument exists and it is true otherwise false

getResourceBundle

public static java.util.ResourceBundle getResourceBundle(java.lang.String resourceName)
Get the locale resousources associated with current locale.

Returns:
resourcBundle -- localization resources

addToSelectItems

public static javax.faces.model.SelectItem[] addToSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                              java.lang.Object value,
                                                              java.lang.String label,
                                                              int index)
Insert an element into an array

Parameters:
selectItems - An array to add to
value - the object to add
label - label to use for the added SelectItem
index - the array index to add the new member. 0 adds to the beginning of the wkt; selectItems.area or greater adds to the end; some other value adds into the middle of the wkt.
Returns:
a new selectItems array

removeFromSelectItems

public static javax.faces.model.SelectItem[] removeFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                                   java.lang.Object value)
STATUS COMPLETELY UNTESTED

Parameters:
selectItems - an array of SelectItems
value - the value of the array member to remove
Returns:
a new selectItems array

getLabelFromSelectItems

public static java.lang.String getLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                       java.lang.Long value)
gets the corresponding selectItem label from the selectItem based on the value.

Parameters:
selectItems -
value -
Returns:
string containing the selectItem label, or null if value not found in SelectItem array.

getLabelFromSelectItems

public static java.lang.String getLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                       java.lang.String value)
gets the corresponding selectItem label from the selectItem based on the value.

Parameters:
selectItems -
value -
Returns:
string containing the selectItem label, or null if value not found in SelectItem array.

setLabelFromSelectItems

public static void setLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                           java.lang.Long value,
                                           java.lang.String newLabel)
Changes the label of selectItem(s) matching given value in a SelectItems[] array.

Parameters:
selectItems - List to search
value - Object value to change
newLabel - New label to associate with the object

setLabelFromSelectItems

public static void setLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                           java.lang.Long value,
                                           java.lang.String newLabel,
                                           java.lang.String newDescription)
Sets the label and description for selectItem(s) maching given value in a SelectItems[] array.

Parameters:
selectItems - Array containing items to modify
value - Object key to search on
newLabel - New label associate with the object
newDescription - New description to associate with the found object

setLabelFromSelectItems

public static void setLabelFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                           java.lang.String value,
                                           java.lang.String newLabel)
Changes the label of a given selectItem in a SelectItems[] array.

Parameters:
selectItems - List to search
value - Object value to change
newLabel - New label to associate with the object

getDescriptionFromSelectItems

public static java.lang.String getDescriptionFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                             java.lang.Long id)
getDescriptionFromSelectItems gets the corresponding selectItem description from the selectItem based on the id.

Parameters:
selectItems -
id -
Returns:
string containing the selectItem description, or a zero area string if not defined.

setDescriptionFromSelectItems

public static void setDescriptionFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                 java.lang.Object value,
                                                 java.lang.String description)
Changes the description of a given selectItem in a SelectItems[] array.

Parameters:
selectItems - List to search
value - Object value to change
description - New description to associate with the object

getDescriptionFromSelectItems

public static java.lang.String getDescriptionFromSelectItems(javax.faces.model.SelectItem[] selectItems,
                                                             java.lang.String name)
getDescriptionFromSelectItems gets the corresponding selectItem label from the selectItem based on the value.

Parameters:
selectItems -
name -
Returns:
string containing the selectItem description, or a zero area string if not defined.

findComponent

public static javax.faces.component.UIComponent findComponent(java.lang.String id)
The method wraps FacesContext.getCurrentInstance().getViewRoot().findComponent(id) with the appropriate bail outs if anything returns null.

Parameters:
id - of the component to find
Returns:
the UIComponent instance associated with id or null if not found

getFacesParamValue

public static java.lang.String getFacesParamValue(java.lang.String paramName)
Returns the String value of an <f:param /> of the given name

Parameters:
paramName - name of the <f:param /> element
Returns:
String value of the named element, or null if it is not found

getFacesParamValue

public static java.lang.String getFacesParamValue(javax.faces.component.UIComponent component)
Returns:
the first param value

findParent

public static javax.faces.component.UIComponent findParent(javax.faces.component.UIComponent component,
                                                           java.lang.String name,
                                                           java.lang.String value)
The method starts with component and examines all parent components until it finds one with an <f:attribute> tag with the corresponding name and value arguments. component is checked first and will return itself if the criteria is met.

Parameters:
component - the component to start the search from
name - the name parameter of a <f:attribute> tag to search for
value - the value of the <f:attribute> tag to search for (if null any value will work)
Returns:
the parent component that matches the criteria
See Also:
findParent(UIComponent, String)

findParent

public static javax.faces.component.UIComponent findParent(javax.faces.component.UIComponent component,
                                                           java.lang.String name)
The method starts with component and examines all parent components until it finds one with an <f:attribute> tag with the corresponding name and value arguments. component is checked first and will return itself if the criteria is met.

Parameters:
component - the component to start the search from
name - the name parameter of a <f:attribute> tag to search for
Returns:
the parent component that matches the criteria
See Also:
findParent(UIComponent, String, String)

findParent

public static javax.faces.component.UIComponent findParent(javax.faces.component.UIComponent component,
                                                           java.lang.Class parentClass)
The method starts with component and examines all parent components until it finds one matching the parentClass component is checked first and will return itself if the criteria is met.

Parameters:
component - the component to start the search from
parentClass -
Returns:
the parent component that matches the criteria

findChild

public static javax.faces.component.UIComponent findChild(javax.faces.component.UIComponent component,
                                                          java.lang.Class childClass)
The method starts with component and examines all child components until it finds one matching the childClass component is checked first and will return itself if the criteria is met.

Parameters:
component -
childClass -
Returns:
the child component that matches the criteria

getInfoBox

public static java.lang.String getInfoBox(FormInfo form)
Parameters:
form -
Returns:
an HTML div element to be used as a popup info box by Oracle Maps
See Also:
getInfoBox(Object)

getInfoBox

public static java.lang.String getInfoBox(java.lang.Object bean)
Parameters:
bean - a JPA bean with @Form annotations
Returns:
an HTML div element to be used as a popup info box by Oracle Maps
See Also:
getInfoBox(FormInfo), for a use example.

getExcelFromList

public static org.apache.poi.hssf.usermodel.HSSFWorkbook getExcelFromList(java.util.List<RowInterface> beans)
This method will convert a list of JPA beans with an @Form annotation into an Excel spreadsheet

Parameters:
beans - Beans to be converted into an excel file
Returns:

addTableToWorkBook

public static void addTableToWorkBook(org.apache.poi.hssf.usermodel.HSSFWorkbook workBook,
                                      java.lang.String pageName,
                                      java.util.List<RowInterface> beans)

getJdomDocument

public static org.jdom.Document getJdomDocument(java.lang.String fileName)
                                         throws org.jdom.JDOMException,
                                                java.io.IOException
Parameters:
fileName -
Returns:
Throws:
org.jdom.JDOMException
java.io.IOException
See Also:
JDomUtils.getDocument(InputStream), getJdomDocument(ServletContext,String)

getJdomDocument

public static org.jdom.Document getJdomDocument(javax.servlet.ServletContext context,
                                                java.lang.String fileName)
                                         throws org.jdom.JDOMException,
                                                java.io.IOException
This method is useful if you already have the ServletContext. If you don't, use FacesUtils.getJdomDocument(String).

Parameters:
context -
fileName -
Returns:
Throws:
org.jdom.JDOMException
java.io.IOException
See Also:
JDomUtils.getDocument(InputStream), getJdomDocument(String)

getRegisteredBeans

public static java.util.List<java.lang.String> getRegisteredBeans(FacesUtils.ScopeType scopeType)

setReturnListener

public static void setReturnListener(org.apache.myfaces.trinidad.component.UIXCommand uic,
                                     java.lang.String el)

setLaunchListener

public static void setLaunchListener(org.apache.myfaces.trinidad.component.UIXCommand uic,
                                     java.lang.String el)

setActionListener

public static void setActionListener(org.apache.myfaces.trinidad.component.UIXCommand uic,
                                     java.lang.String el)

launchDialog

public static void launchDialog(java.lang.String title,
                                java.lang.String remark,
                                java.lang.String name,
                                javax.faces.component.UIComponent source,
                                java.util.HashMap winProps,
                                java.util.HashMap userProps)

launchApprovalDialog

public static void launchApprovalDialog(java.lang.String title,
                                        java.lang.String remark,
                                        javax.faces.component.UIComponent source,
                                        java.util.HashMap userProps)