org.sakaiproject.tool.section.jsf
Class JsfUtil

java.lang.Object
  extended byorg.sakaiproject.tool.section.jsf.JsfUtil

public class JsfUtil
extends Object

A utility to help deal with common tasks in JSF.

Author:
Josh Holtzman

Field Summary
static String TIME_PATTERN_DISPLAY
          As part of the crutch for JSF's inability to do validation on relative values in different components.
static String TIME_PATTERN_LONG
          As part of the crutch for JSF's inability to do validation on relative values in different components.
static String TIME_PATTERN_SHORT
          As part of the crutch for JSF's inability to do validation on relative values in different components.
 
Constructor Summary
JsfUtil()
           
 
Method Summary
static void addErrorMessage(String message)
          Adds an error message for display on a page when the page is guaranteed not to be displayed via a redirect.
static void addErrorMessage(String message, String componentId)
          Adds an error message for display on a component when the page is guaranteed not to be displayed via a redirect.
static void addInfoMessage(String message)
          Adds an info message for display on a page when the page is guaranteed not to be displayed via a redirect.
static void addRedirectSafeInfoMessage(String message)
          Adds an info message for display on a page even if faces sends the user to the page via a redirect.
static void addRedirectSafeWarnMessage(String message)
          Adds a warning message for display on a page even if faces sends the user to the page via a redirect.
static Time convertStringToTime(String str, boolean am)
          Converts a string and a boolean (am) into a java.sql.Time object.
static Locale getLocale()
          Gets the current locale for a request, as provided by the faces context.
static String getLocalizedMessage(String key)
          Gets a localized message from the message bundle.
static String getLocalizedMessage(String key, String[] params)
          Gets a localized message from the message bundle and formats it using the parameter array.
static Comparator getSelectItemComparator()
           
static String getStringFromParam(String string)
          Gets a value from the request parameter map, as provided by the faces context.
static boolean isEndTimeBeforeStartTime(String startTime, boolean startTimeAm, String endTime, boolean endTimeAm)
          As part of the crutch for JSF's inability to do validation on relative values in different components, this method checks whether two times, as expressed by string start and end times and booleans indicating am/pm, express times where the end time proceeds a start time.
static boolean isEndTimeWithoutStartTime(String startTime, String endTime)
          As part of the crutch for JSF's inability to do validation on relative values in different components, this method checks whether an end time has been entered without a start time.
static boolean isInvalidTime(String str)
          As part of the crutch for JSF's inability to do validation on relative values in different components, this method checks whether a string can represent a valid time.
static Object resolveVariable(String name)
          To cut down on configuration noise, allow access to request-scoped beans from session-scoped beans, and so on, this method lets the caller try to find anything anywhere that Faces can look for it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME_PATTERN_DISPLAY

public static final String TIME_PATTERN_DISPLAY
As part of the crutch for JSF's inability to do validation on relative values in different components. This pattern defines how times should be displayed in the Section Info UI.

See Also:
Constant Field Values

TIME_PATTERN_LONG

public static final String TIME_PATTERN_LONG
As part of the crutch for JSF's inability to do validation on relative values in different components. This pattern defines how to parse and format complete times (with hours, minutes, and am/pm marker).

See Also:
Constant Field Values

TIME_PATTERN_SHORT

public static final String TIME_PATTERN_SHORT
As part of the crutch for JSF's inability to do validation on relative values in different components. This pattern defines how to parse and format abberviated times (with only hours and am/pm marker).

See Also:
Constant Field Values
Constructor Detail

JsfUtil

public JsfUtil()
Method Detail

getLocale

public static Locale getLocale()
Gets the current locale for a request, as provided by the faces context. If not locale can be found, defaults to Locale.US.

Returns:

resolveVariable

public static final Object resolveVariable(String name)
To cut down on configuration noise, allow access to request-scoped beans from session-scoped beans, and so on, this method lets the caller try to find anything anywhere that Faces can look for it. WARNING: If what you're looking for is a managed bean and it isn't found, it will be created as a result of this call.


addErrorMessage

public static void addErrorMessage(String message)
Adds an error message for display on a page when the page is guaranteed not to be displayed via a redirect.

Parameters:
message -

addErrorMessage

public static void addErrorMessage(String message,
                                   String componentId)
Adds an error message for display on a component when the page is guaranteed not to be displayed via a redirect.

Parameters:
message -
componentId -

addInfoMessage

public static void addInfoMessage(String message)
Adds an info message for display on a page when the page is guaranteed not to be displayed via a redirect.

Parameters:
message -

addRedirectSafeInfoMessage

public static void addRedirectSafeInfoMessage(String message)
Adds an info message for display on a page even if faces sends the user to the page via a redirect.

Parameters:
message -

addRedirectSafeWarnMessage

public static void addRedirectSafeWarnMessage(String message)
Adds a warning message for display on a page even if faces sends the user to the page via a redirect.

Parameters:
message -

getLocalizedMessage

public static String getLocalizedMessage(String key)
Gets a localized message from the message bundle.


getLocalizedMessage

public static String getLocalizedMessage(String key,
                                         String[] params)
Gets a localized message from the message bundle and formats it using the parameter array.

Parameters:
key -
params -
Returns:

getStringFromParam

public static String getStringFromParam(String string)
Gets a value from the request parameter map, as provided by the faces context.

Parameters:
string -
Returns:

convertStringToTime

public static Time convertStringToTime(String str,
                                       boolean am)
Converts a string and a boolean (am) into a java.sql.Time object.

Parameters:
str -
am -
Returns:

isInvalidTime

public static boolean isInvalidTime(String str)
As part of the crutch for JSF's inability to do validation on relative values in different components, this method checks whether a string can represent a valid time. Returns true if the string fails to represent a time. Java's date formatters allow for impossible field values (eg hours > 12) so we do manual checks here. Ugh.

Parameters:
str - The string that might represent a time.
Returns:

isEndTimeWithoutStartTime

public static boolean isEndTimeWithoutStartTime(String startTime,
                                                String endTime)
As part of the crutch for JSF's inability to do validation on relative values in different components, this method checks whether an end time has been entered without a start time.

Parameters:
startTime -
endTime -
Returns:

isEndTimeBeforeStartTime

public static boolean isEndTimeBeforeStartTime(String startTime,
                                               boolean startTimeAm,
                                               String endTime,
                                               boolean endTimeAm)
As part of the crutch for JSF's inability to do validation on relative values in different components, this method checks whether two times, as expressed by string start and end times and booleans indicating am/pm, express times where the end time proceeds a start time.

Parameters:
startTime -
startTimeAm -
endTime -
endTimeAm -
Returns:

getSelectItemComparator

public static final Comparator getSelectItemComparator()