Author: chris.laprun(a)jboss.com
Date: 2009-02-18 19:40:10 -0500 (Wed, 18 Feb 2009)
New Revision: 12833
Modified:
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
Log:
- Added Javadoc and made parameter names more precise.
- JSFBeanContext.createMessage now uses BeanContext.STATUS as target if none is
specified.
Modified:
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java 2009-02-19
00:37:54 UTC (rev 12832)
+++
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java 2009-02-19
00:40:10 UTC (rev 12833)
@@ -60,24 +60,33 @@
protected abstract Locale getLocale();
- public void createErrorMessage(String message, Object... params)
+ public void createErrorMessage(String localizedMessageId, Object... params)
{
- createLocalizedMessage(STATUS, message, getErrorSeverity(), params);
+ createLocalizedMessage(STATUS, localizedMessageId, getErrorSeverity(), params);
}
- public void createTargetedErrorMessage(String target, String message, Object...
params)
+ public void createTargetedErrorMessage(String target, String localizedMessageId,
Object... params)
{
- createLocalizedMessage(target, message, getErrorSeverity(), params);
+ createLocalizedMessage(target, localizedMessageId, getErrorSeverity(), params);
}
- protected void createLocalizedMessage(String target, String message, Object severity,
Object... params)
+ /**
+ * Adds a localized message using the appropriate severity to the identified target in
the context. This method
+ * accepts an arbitrary number of arguments to be passed as parameters of localized
strings.
+ *
+ * @param target the target in this context that will receive the new
message
+ * @param localizedMessageId a resource bundle identifier identifying which the
localized string to use as a message
+ * @param severity an object representing the severity of the message
(typically FacesMessage.Severity)
+ * @param params additional parameters to be passed to replace tokens in
localized strings
+ */
+ protected void createLocalizedMessage(String target, String localizedMessageId, Object
severity, Object... params)
{
- createMessage(target, getMessageFromBundle(message, params), severity);
+ createMessage(target, getMessageFromBundle(localizedMessageId, params), severity);
}
- public String getMessageFromBundle(String message, Object... params)
+ public String getMessageFromBundle(String localizedMessageId, Object... params)
{
- return getLocalizedMessage(message, getLocale(), params);
+ return getLocalizedMessage(localizedMessageId, getLocale(), params);
}
public static String getLocalizedMessage(String localizationKey, Locale locale,
Object... params)
@@ -91,6 +100,17 @@
createErrorMessageFrom(STATUS, e);
}
+ /**
+ * Creates a localized error message targeting the specified object in the context and
using the specified error
+ * information. This method looks for two specific resource bundle entries to localize
the message, {@link
+ * #UNEXPECTED_ERROR} and {@link #CAUSE}, using the following format for the message:
<code>result of {@link
+ * #getLocalizedMessageOrExceptionName(Throwable)} for the exception\n[localized value
associated with {@link
+ * #CAUSE}result of {@link #getLocalizedMessageOrExceptionName(Throwable)} for the
exception's cause if the cause
+ * exists]
+ *
+ * @param target the contextual object target by the message to be created
+ * @param e the exception that we want to display as an error message
+ */
public void createErrorMessageFrom(String target, Exception e)
{
Throwable cause = e.getCause();
@@ -99,6 +119,14 @@
createMessage(target, message, getErrorSeverity());
}
+ /**
+ * Retrieves a localized message associated with the specified Throwable.
+ *
+ * @param e the Throwable for which a localized message is to be retrieved
+ * @return the localized message associated with the specified Throwable if it exists
or the localized value
+ * associated with the {@link #UNEXPECTED_ERROR} resource bundle entry to
which is appended the Throwable
+ * class name.
+ */
private String getLocalizedMessageOrExceptionName(Throwable e)
{
String localizedMessage = e.getLocalizedMessage();
@@ -109,14 +137,14 @@
return localizedMessage;
}
- protected void createInfoMessage(String target, String message)
+ protected void createInfoMessage(String target, String localizedMessageId)
{
- createLocalizedMessage(target, message, getInfoSeverity());
+ createLocalizedMessage(target, localizedMessageId, getInfoSeverity());
}
- public void createInfoMessage(String message)
+ public void createInfoMessage(String localizedMessageId)
{
- createInfoMessage(STATUS, message);
+ createInfoMessage(STATUS, localizedMessageId);
}
/**
Modified:
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java 2009-02-19
00:37:54 UTC (rev 12832)
+++
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java 2009-02-19
00:40:10 UTC (rev 12833)
@@ -23,6 +23,8 @@
package org.jboss.portal.faces.gui;
+import org.jboss.portal.common.util.ParameterValidation;
+
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import java.util.Locale;
@@ -58,6 +60,11 @@
protected void createMessage(String target, String message, Object severity)
{
+ if (ParameterValidation.isNullOrEmpty(target))
+ {
+ target = STATUS;
+ }
+
FacesMessage.Severity jsfSeverity;
if (severity instanceof FacesMessage.Severity)
{