You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/08/29 05:19:56 UTC
svn commit: r1378434 - in /myfaces/core/branches/2.0.x:
api/src/main/java/javax/faces/component/
api/src/main/java/javax/faces/convert/
api/src/main/java/javax/faces/validator/
shared-public/src/main/java/org/apache/myfaces/shared/util/
Author: lu4242
Date: Wed Aug 29 03:19:55 2012
New Revision: 1378434
URL: http://svn.apache.org/viewvc?rev=1378434&view=rev
Log:
MYFACES-3591 Labels with EL expressions are not shown in messages if partial state saving is disabled
Modified:
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_MessageUtils.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/convert/_MessageUtils.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/_MessageUtils.java
myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/MessageUtils.java
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_MessageUtils.java?rev=1378434&r1=1378433&r2=1378434&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_MessageUtils.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_MessageUtils.java Wed Aug 29 03:19:55 2012
@@ -22,7 +22,6 @@ import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
-import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@@ -111,7 +110,8 @@ class _MessageUtils
else
{
//Neither detail nor summary found
- facesContext.getExternalContext().log("No message with id " + messageId + " found in any bundle");
+ facesContext.getExternalContext().log("No message with id " + messageId
+ + " found in any bundle");
return new FacesMessage(severity, messageId, null);
}
}
@@ -191,14 +191,40 @@ class _MessageUtils
}
}
- static Object getLabel(FacesContext facesContext, UIComponent component) {
+ static Object getLabel(FacesContext facesContext, UIComponent component)
+ {
Object label = component.getAttributes().get("label");
+ ValueExpression expression = null;
+ if (label != null &&
+ label instanceof String && ((String)label).length() == 0 )
+ {
+ // Note component.getAttributes().get("label") internally try to
+ // evaluate the EL expression for the label, but in some cases,
+ // when PSS is disabled and f:loadBundle is used, when the view is
+ // restored the bundle is not set to the EL expression returns an
+ // empty String. It is not possible to check if there is a
+ // hardcoded label, but we can check if there is
+ // an EL expression set, so the best in this case is use that, and if
+ // there is an EL expression set, use it, otherwise use the hardcoded
+ // value. See MYFACES-3591 for details.
+ expression = component.getValueExpression("label");
+ if (expression != null)
+ {
+ // Set the label to null and use the EL expression instead.
+ label = null;
+ }
+ }
+
if(label != null)
+ {
return label;
+ }
- ValueExpression expression = component.getValueExpression("label");
+ expression = (expression == null) ? component.getValueExpression("label") : expression;
if(expression != null)
+ {
return expression;
+ }
//If no label is not specified, use clientId
return component.getClientId( facesContext );
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/convert/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/convert/_MessageUtils.java?rev=1378434&r1=1378433&r2=1378434&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/convert/_MessageUtils.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/convert/_MessageUtils.java Wed Aug 29 03:19:55 2012
@@ -27,7 +27,6 @@ import javax.faces.context.FacesContext;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@@ -94,7 +93,8 @@ class _MessageUtils
else
{
//Neither detail nor summary found
- facesContext.getExternalContext().log("No message with id " + messageId + " found in any bundle");
+ facesContext.getExternalContext().log("No message with id " + messageId
+ + " found in any bundle");
return new FacesMessage(severity, messageId, null);
}
}
@@ -161,20 +161,30 @@ class _MessageUtils
try
{
//Last resort is the context class loader
- if (System.getSecurityManager() != null) {
- Object cl = AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws PrivilegedActionException {
+ if (System.getSecurityManager() != null)
+ {
+ Object cl = AccessController.doPrivileged(new PrivilegedExceptionAction()
+ {
+ public Object run() throws PrivilegedActionException
+ {
return Thread.currentThread().getContextClassLoader();
}
});
return ResourceBundle.getBundle(bundleName,locale,(ClassLoader)cl);
- }else{
- return ResourceBundle.getBundle(bundleName,locale, Thread.currentThread().getContextClassLoader());
+ }
+ else
+ {
+ return ResourceBundle.getBundle(bundleName,locale,
+ Thread.currentThread().getContextClassLoader());
}
- }catch(PrivilegedActionException pae){
+ }
+ catch(PrivilegedActionException pae)
+ {
throw new FacesException(pae);
- }catch (MissingResourceException damned){
+ }
+ catch (MissingResourceException damned)
+ {
facesContext.getExternalContext().log("resource bundle " + bundleName + " could not be found");
return null;
}
@@ -182,14 +192,40 @@ class _MessageUtils
}
}
- static Object getLabel(FacesContext facesContext, UIComponent component) {
+ static Object getLabel(FacesContext facesContext, UIComponent component)
+ {
Object label = component.getAttributes().get("label");
+ ValueExpression expression = null;
+ if (label != null &&
+ label instanceof String && ((String)label).length() == 0 )
+ {
+ // Note component.getAttributes().get("label") internally try to
+ // evaluate the EL expression for the label, but in some cases,
+ // when PSS is disabled and f:loadBundle is used, when the view is
+ // restored the bundle is not set to the EL expression returns an
+ // empty String. It is not possible to check if there is a
+ // hardcoded label, but we can check if there is
+ // an EL expression set, so the best in this case is use that, and if
+ // there is an EL expression set, use it, otherwise use the hardcoded
+ // value. See MYFACES-3591 for details.
+ expression = component.getValueExpression("label");
+ if (expression != null)
+ {
+ // Set the label to null and use the EL expression instead.
+ label = null;
+ }
+ }
+
if(label != null)
+ {
return label;
+ }
- ValueExpression expression = component.getValueExpression("label");
+ expression = (expression == null) ? component.getValueExpression("label") : expression;
if(expression != null)
+ {
return expression;
+ }
//If no label is not specified, use clientId
return component.getClientId( facesContext );
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/_MessageUtils.java?rev=1378434&r1=1378433&r2=1378434&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/_MessageUtils.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/_MessageUtils.java Wed Aug 29 03:19:55 2012
@@ -21,7 +21,6 @@ package javax.faces.validator;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@@ -99,7 +98,8 @@ class _MessageUtils
else
{
//Neither detail nor summary found
- facesContext.getExternalContext().log("No message with id " + messageId + " found in any bundle");
+ facesContext.getExternalContext().log("No message with id " + messageId
+ + " found in any bundle");
return new FacesMessage(severity, messageId, null);
}
}
@@ -166,20 +166,30 @@ class _MessageUtils
try
{
//Last resort is the context class loader
- if (System.getSecurityManager() != null) {
- Object cl = AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws PrivilegedActionException {
+ if (System.getSecurityManager() != null)
+ {
+ Object cl = AccessController.doPrivileged(new PrivilegedExceptionAction()
+ {
+ public Object run() throws PrivilegedActionException
+ {
return Thread.currentThread().getContextClassLoader();
}
});
return ResourceBundle.getBundle(bundleName,locale,(ClassLoader)cl);
- }else{
- return ResourceBundle.getBundle(bundleName,locale, Thread.currentThread().getContextClassLoader());
+ }
+ else
+ {
+ return ResourceBundle.getBundle(bundleName,locale,
+ Thread.currentThread().getContextClassLoader());
}
- }catch(PrivilegedActionException pae){
+ }
+ catch(PrivilegedActionException pae)
+ {
throw new FacesException(pae);
- }catch (MissingResourceException damned){
+ }
+ catch (MissingResourceException damned)
+ {
facesContext.getExternalContext().log("resource bundle " + bundleName + " could not be found");
return null;
}
@@ -187,14 +197,40 @@ class _MessageUtils
}
}
- static Object getLabel(FacesContext facesContext, UIComponent component) {
+ static Object getLabel(FacesContext facesContext, UIComponent component)
+ {
Object label = component.getAttributes().get("label");
+ ValueExpression expression = null;
+ if (label != null &&
+ label instanceof String && ((String)label).length() == 0 )
+ {
+ // Note component.getAttributes().get("label") internally try to
+ // evaluate the EL expression for the label, but in some cases,
+ // when PSS is disabled and f:loadBundle is used, when the view is
+ // restored the bundle is not set to the EL expression returns an
+ // empty String. It is not possible to check if there is a
+ // hardcoded label, but we can check if there is
+ // an EL expression set, so the best in this case is use that, and if
+ // there is an EL expression set, use it, otherwise use the hardcoded
+ // value. See MYFACES-3591 for details.
+ expression = component.getValueExpression("label");
+ if (expression != null)
+ {
+ // Set the label to null and use the EL expression instead.
+ label = null;
+ }
+ }
+
if(label != null)
+ {
return label;
+ }
- ValueExpression expression = component.getValueExpression("label");
+ expression = (expression == null) ? component.getValueExpression("label") : expression;
if(expression != null)
+ {
return expression;
+ }
//If no label is not specified, use clientId
return component.getClientId( facesContext );
Modified: myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/MessageUtils.java?rev=1378434&r1=1378433&r2=1378434&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/MessageUtils.java (original)
+++ myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/MessageUtils.java Wed Aug 29 03:19:55 2012
@@ -645,12 +645,33 @@ public final class MessageUtils
public static Object getLabel(FacesContext facesContext, UIComponent component)
{
Object label = component.getAttributes().get("label");
+ ValueExpression expression = null;
+ if (label != null &&
+ label instanceof String && ((String)label).length() == 0 )
+ {
+ // Note component.getAttributes().get("label") internally try to
+ // evaluate the EL expression for the label, but in some cases,
+ // when PSS is disabled and f:loadBundle is used, when the view is
+ // restored the bundle is not set to the EL expression returns an
+ // empty String. It is not possible to check if there is a
+ // hardcoded label, but we can check if there is
+ // an EL expression set, so the best in this case is use that, and if
+ // there is an EL expression set, use it, otherwise use the hardcoded
+ // value. See MYFACES-3591 for details.
+ expression = component.getValueExpression("label");
+ if (expression != null)
+ {
+ // Set the label to null and use the EL expression instead.
+ label = null;
+ }
+ }
+
if(label != null)
{
return label;
}
- ValueExpression expression = component.getValueExpression("label");
+ expression = (expression == null) ? component.getValueExpression("label") : expression;
if(expression != null)
{
return expression;