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 2010/05/02 03:31:07 UTC
svn commit: r940134 - in /myfaces/core/branches/1.2.x/api/src:
main/java/javax/faces/component/ main/java/javax/faces/convert/
main/java/javax/faces/validator/ test/java/javax/faces/convert/
Author: lu4242
Date: Sun May 2 01:31:07 2010
New Revision: 940134
URL: http://svn.apache.org/viewvc?rev=940134&view=rev
Log:
MYFACES-2691 Enhance MessageUtils adding methods when custom library bundle should be scanned
Added:
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java
Modified:
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_MessageUtils.java
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_MessageUtils.java
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_MessageUtils.java
myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/MessageUtilsTest.java
Modified: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_MessageUtils.java?rev=940134&r1=940133&r2=940134&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_MessageUtils.java (original)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_MessageUtils.java Sun May 2 01:31:07 2010
@@ -120,25 +120,14 @@ class _MessageUtils
if (args != null && args.length > 0)
{
- MessageFormat format;
-
- if (summary != null)
- {
- format = new MessageFormat(summary, locale);
- summary = format.format(args);
- }
-
- if (detail != null)
- {
- format = new MessageFormat(detail, locale);
- detail = format.format(args);
- }
+ return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
+ }
+ else
+ {
+ return new FacesMessage(severity, summary, detail);
}
-
- return new _LabeledFacesMessage(severity, summary, detail);
}
-
private static String getBundleString(ResourceBundle bundle, String key)
{
try
@@ -202,15 +191,14 @@ class _MessageUtils
}
}
- static String getLabel(FacesContext facesContext, UIComponent component) {
+ static Object getLabel(FacesContext facesContext, UIComponent component) {
Object label = component.getAttributes().get("label");
if(label != null)
- return label.toString();
+ return label;
ValueExpression expression = component.getValueExpression("label");
if(expression != null)
- return expression.getExpressionString();
- //return (String)expression.getValue(facesContext.getELContext());
+ return expression;
//If no label is not specified, use clientId
return component.getClientId( facesContext );
Added: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java?rev=940134&view=auto
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java (added)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java Sun May 2 01:31:07 2010
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package javax.faces.component;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.el.ValueExpression;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+class _ParametrizableFacesMessage extends FacesMessage
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7792947730961657948L;
+
+ private final Object _args[];
+ private String _evaluatedDetail;
+ private String _evaluatedSummary;
+ private transient Object _evaluatedArgs[];
+ private Locale _locale;
+
+ public _ParametrizableFacesMessage(
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity,
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(severity, summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ @Override
+ public String getDetail()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedDetail == null)
+ {
+ MessageFormat format = new MessageFormat(super.getDetail(), _locale);
+ _evaluatedDetail = format.format(_evaluatedArgs);
+ }
+ return _evaluatedDetail;
+ }
+
+ @Override
+ public String getSummary()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedSummary == null)
+ {
+ MessageFormat format = new MessageFormat(super.getSummary(), _locale);
+ _evaluatedSummary = format.format(_evaluatedArgs);
+ }
+ return _evaluatedSummary;
+ }
+
+ private void evaluateArgs()
+ {
+ _evaluatedArgs = new Object[_args.length];
+ FacesContext facesContext = null;
+ for (int i = 0; i < _args.length; i++)
+ {
+ if (_args[i] == null)
+ {
+ continue;
+ }
+ else if (_args[i] instanceof ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ else if (_args[i] instanceof ValueExpression)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
+ }
+ else
+ {
+ _evaluatedArgs[i] = _args[i];
+ }
+ }
+ }
+}
Modified: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_MessageUtils.java?rev=940134&r1=940133&r2=940134&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_MessageUtils.java (original)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_MessageUtils.java Sun May 2 01:31:07 2010
@@ -90,7 +90,8 @@ class _MessageUtils
else
{
//Neither detail nor summary found
- return null;
+ facesContext.getExternalContext().log("No message with id " + messageId + " found in any bundle");
+ return new FacesMessage(severity, messageId, null);
}
}
}
@@ -98,25 +99,14 @@ class _MessageUtils
if (args != null && args.length > 0)
{
- MessageFormat format;
-
- if (summary != null)
- {
- format = new MessageFormat(summary, locale);
- summary = format.format(args);
- }
-
- if (detail != null)
- {
- format = new MessageFormat(detail, locale);
- detail = format.format(args);
- }
+ return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
+ }
+ else
+ {
+ return new FacesMessage(severity, summary, detail);
}
-
- return new _LabeledFacesMessage(severity, summary, detail);
}
-
private static String getBundleString(ResourceBundle bundle, String key)
{
try
@@ -133,7 +123,6 @@ class _MessageUtils
private static ResourceBundle getApplicationBundle(FacesContext facesContext, Locale locale)
{
String bundleName = facesContext.getApplication().getMessageBundle();
-
return bundleName != null ? getBundle(facesContext, locale, bundleName) : null;
}
@@ -181,18 +170,16 @@ class _MessageUtils
}
}
- static String getLabel(FacesContext facesContext, UIComponent component) {
+ static Object getLabel(FacesContext facesContext, UIComponent component) {
Object label = component.getAttributes().get("label");
if(label != null)
- return label.toString();
+ return label;
ValueExpression expression = component.getValueExpression("label");
if(expression != null)
- return expression.getExpressionString();
- //return (String)expression.getValue(facesContext.getELContext());
+ return expression;
//If no label is not specified, use clientId
return component.getClientId( facesContext );
}
-
}
Added: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java?rev=940134&view=auto
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java (added)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java Sun May 2 01:31:07 2010
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package javax.faces.convert;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.el.ValueExpression;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+class _ParametrizableFacesMessage extends FacesMessage
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7792947730961657948L;
+
+ private final Object _args[];
+ private String _evaluatedDetail;
+ private String _evaluatedSummary;
+ private transient Object _evaluatedArgs[];
+ private Locale _locale;
+
+ public _ParametrizableFacesMessage(
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity,
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(severity, summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ @Override
+ public String getDetail()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedDetail == null)
+ {
+ MessageFormat format = new MessageFormat(super.getDetail(), _locale);
+ _evaluatedDetail = format.format(_evaluatedArgs);
+ }
+ return _evaluatedDetail;
+ }
+
+ @Override
+ public String getSummary()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedSummary == null)
+ {
+ MessageFormat format = new MessageFormat(super.getSummary(), _locale);
+ _evaluatedSummary = format.format(_evaluatedArgs);
+ }
+ return _evaluatedSummary;
+ }
+
+ private void evaluateArgs()
+ {
+ _evaluatedArgs = new Object[_args.length];
+ FacesContext facesContext = null;
+ for (int i = 0; i < _args.length; i++)
+ {
+ if (_args[i] == null)
+ {
+ continue;
+ }
+ else if (_args[i] instanceof ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ else if (_args[i] instanceof ValueExpression)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
+ }
+ else
+ {
+ _evaluatedArgs[i] = _args[i];
+ }
+ }
+ }
+}
Modified: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_MessageUtils.java?rev=940134&r1=940133&r2=940134&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_MessageUtils.java (original)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_MessageUtils.java Sun May 2 01:31:07 2010
@@ -104,25 +104,14 @@ class _MessageUtils
if (args != null && args.length > 0)
{
- MessageFormat format;
-
- if (summary != null)
- {
- format = new MessageFormat(summary, locale);
- summary = format.format(args);
- }
-
- if (detail != null)
- {
- format = new MessageFormat(detail, locale);
- detail = format.format(args);
- }
+ return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
+ }
+ else
+ {
+ return new FacesMessage(severity, summary, detail);
}
-
- return new _LabeledFacesMessage(severity, summary, detail);
}
-
private static String getBundleString(ResourceBundle bundle, String key)
{
try
@@ -139,7 +128,6 @@ class _MessageUtils
private static ResourceBundle getApplicationBundle(FacesContext facesContext, Locale locale)
{
String bundleName = facesContext.getApplication().getMessageBundle();
-
return bundleName != null ? getBundle(facesContext, locale, bundleName) : null;
}
@@ -187,18 +175,16 @@ class _MessageUtils
}
}
- static String getLabel(FacesContext facesContext, UIComponent component) {
+ static Object getLabel(FacesContext facesContext, UIComponent component) {
Object label = component.getAttributes().get("label");
if(label != null)
- return label.toString();
+ return label;
ValueExpression expression = component.getValueExpression("label");
if(expression != null)
- return expression.getExpressionString();
- //return (String)expression.getValue(facesContext.getELContext());
+ return expression;
//If no label is not specified, use clientId
return component.getClientId( facesContext );
}
-
}
Added: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java?rev=940134&view=auto
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java (added)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java Sun May 2 01:31:07 2010
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package javax.faces.validator;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.el.ValueExpression;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+class _ParametrizableFacesMessage extends FacesMessage
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7792947730961657948L;
+
+ private final Object _args[];
+ private String _evaluatedDetail;
+ private String _evaluatedSummary;
+ private transient Object _evaluatedArgs[];
+ private Locale _locale;
+
+ public _ParametrizableFacesMessage(
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity,
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(severity, summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ @Override
+ public String getDetail()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedDetail == null)
+ {
+ MessageFormat format = new MessageFormat(super.getDetail(), _locale);
+ _evaluatedDetail = format.format(_evaluatedArgs);
+ }
+ return _evaluatedDetail;
+ }
+
+ @Override
+ public String getSummary()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedSummary == null)
+ {
+ MessageFormat format = new MessageFormat(super.getSummary(), _locale);
+ _evaluatedSummary = format.format(_evaluatedArgs);
+ }
+ return _evaluatedSummary;
+ }
+
+ private void evaluateArgs()
+ {
+ _evaluatedArgs = new Object[_args.length];
+ FacesContext facesContext = null;
+ for (int i = 0; i < _args.length; i++)
+ {
+ if (_args[i] == null)
+ {
+ continue;
+ }
+ else if (_args[i] instanceof ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ else if (_args[i] instanceof ValueExpression)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
+ }
+ else
+ {
+ _evaluatedArgs[i] = _args[i];
+ }
+ }
+ }
+}
Modified: myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/MessageUtilsTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/MessageUtilsTest.java?rev=940134&r1=940133&r2=940134&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/MessageUtilsTest.java (original)
+++ myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/MessageUtilsTest.java Sun May 2 01:31:07 2010
@@ -43,7 +43,7 @@ public class MessageUtilsTest extends Ab
public void testGetLabelFromAttributesMap() {
HtmlInputText inputText = new HtmlInputText();
inputText.getAttributes().put("label", "testLabel");
- String label = _MessageUtils.getLabel(facesContext, inputText);
+ Object label = _MessageUtils.getLabel(facesContext, inputText);
assertEquals("testLabel", label);
}
@@ -53,14 +53,14 @@ public class MessageUtilsTest extends Ab
ValueExpression expression = new MockValueExpression("#{requestScope.lbl}",String.class);
inputText.setValueExpression("label", expression);
- String label = _MessageUtils.getLabel(facesContext, inputText);
+ Object label = _MessageUtils.getLabel(facesContext, inputText);
assertEquals("testLabel", label);
}
public void testGetLabelReturnsClientIdWhenLabelIsNotSpecified() {
HtmlInputText inputText = new HtmlInputText();
inputText.setId("testId");
- String label = _MessageUtils.getLabel(facesContext, inputText);
+ Object label = _MessageUtils.getLabel(facesContext, inputText);
assertEquals("testId", label);
}
}
\ No newline at end of file