You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/06/10 14:29:17 UTC
svn commit: r1747720 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/convert/
tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/
tobago-core/src/main/java/org/apache/myfaces/tobago/util/
tobago-theme/tobago-t...
Author: lofwyr
Date: Fri Jun 10 14:29:16 2016
New Revision: 1747720
URL: http://svn.apache.org/viewvc?rev=1747720&view=rev
Log:
TOBAGO-1567: Clean up: consolidate getFormattedValue() and other methods.
Added:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/MeasureConverter.java
- copied, changed from r1747659, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/CurrencyConverter.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractRendererBaseWrapper.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyCheckboxRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/MeasureConverter.java (from r1747659, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/CurrencyConverter.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/MeasureConverter.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/MeasureConverter.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/CurrencyConverter.java&r1=1747659&r2=1747720&rev=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/CurrencyConverter.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/convert/MeasureConverter.java Fri Jun 10 14:29:16 2016
@@ -20,18 +20,18 @@
package org.apache.myfaces.tobago.convert;
import org.apache.myfaces.tobago.internal.util.StringUtils;
+import org.apache.myfaces.tobago.layout.Measure;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
-import java.util.Currency;
/**
- * JSF converter for the java.util.Currency class.
+ * JSF converter for the org.apache.myfaces.tobago.layout.Measure class.
*/
-@org.apache.myfaces.tobago.apt.annotation.Converter(forClass = "java.util.Currency")
-public class CurrencyConverter implements Converter {
+@org.apache.myfaces.tobago.apt.annotation.Converter(forClass = "org.apache.myfaces.tobago.layout.Measure")
+public class MeasureConverter implements Converter {
@Override
public Object getAsObject(final FacesContext facesContext, final UIComponent component, final String string)
@@ -39,7 +39,7 @@ public class CurrencyConverter implement
if (StringUtils.isBlank(string)) {
return null;
} else {
- return Currency.getInstance(string);
+ return Measure.valueOf(string);
}
}
@@ -50,7 +50,7 @@ public class CurrencyConverter implement
return null;
}
try {
- return ((Currency) object).getCurrencyCode();
+ return ((Measure) object).serialize();
} catch (final ClassCastException e) {
throw new ConverterException("object='" + object + "'", e);
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractRendererBaseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractRendererBaseWrapper.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractRendererBaseWrapper.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractRendererBaseWrapper.java Fri Jun 10 14:29:16 2016
@@ -24,7 +24,6 @@ import org.apache.myfaces.tobago.interna
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import java.io.IOException;
@@ -62,11 +61,6 @@ public abstract class AbstractRendererBa
}
@Override
- public final Converter getConverter(final FacesContext facesContext, final UIComponent component) {
- return getRenderer(facesContext).getConverter(facesContext, component);
- }
-
- @Override
public final Object getConvertedValue(
final FacesContext facesContext, final UIComponent component, final Object submittedValue)
throws ConverterException {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java Fri Jun 10 14:29:16 2016
@@ -21,12 +21,10 @@ package org.apache.myfaces.tobago.render
import org.apache.myfaces.tobago.context.ResourceManager;
import org.apache.myfaces.tobago.internal.context.ResourceManagerFactory;
-import org.apache.myfaces.tobago.layout.Measure;
+import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
@@ -62,42 +60,11 @@ public class RendererBase extends Render
String currentValue = null;
final Object currentObj = getValue(component);
if (currentObj != null) {
- currentValue = getFormattedValue(facesContext, component, currentObj);
+ currentValue = ComponentUtils.getFormattedValue(facesContext, component, currentObj);
}
return currentValue;
}
- protected String getFormattedValue(final FacesContext context, final UIComponent component, final Object currentValue)
- throws ConverterException {
-
- if (currentValue == null) {
- return "";
- }
-
- if (!(component instanceof ValueHolder)) {
- return currentValue.toString();
- }
-
- Converter converter = ((ValueHolder) component).getConverter();
-
- if (converter == null) {
- if (currentValue instanceof String) {
- return (String) currentValue;
- }
- if (currentValue instanceof Measure) {
- return ((Measure) currentValue).serialize();
- }
- final Class converterType = currentValue.getClass();
- converter = context.getApplication().createConverter(converterType);
- }
-
- if (converter == null) {
- return currentValue.toString();
- } else {
- return converter.getAsString(context, component, currentValue);
- }
- }
-
protected Object getValue(final UIComponent component) {
if (component instanceof ValueHolder) {
return ((ValueHolder) component).getValue();
@@ -106,36 +73,13 @@ public class RendererBase extends Render
}
}
- public Converter getConverter(final FacesContext context, final UIComponent component) {
- Converter converter = null;
- if (component instanceof ValueHolder) {
- converter = ((ValueHolder) component).getConverter();
- }
- if (converter == null) {
- final ValueExpression valueExpression = component.getValueExpression("value");
- if (valueExpression != null) {
- final Class converterType = valueExpression.getType(context.getELContext());
- if (converterType == null || converterType == String.class
- || converterType == Object.class) {
- return null;
- }
- try {
- converter = context.getApplication().createConverter(converterType);
- } catch (final FacesException e) {
- LOG.error("No Converter found for type " + converterType);
- }
- }
- }
- return converter;
- }
-
@Override
public Object getConvertedValue(final FacesContext context, final UIComponent component, final Object submittedValue)
throws ConverterException {
if (!(submittedValue instanceof String)) {
return submittedValue;
}
- final Converter converter = getConverter(context, component);
+ final Converter converter = ComponentUtils.getConverter(context, component);
if (converter != null) {
return converter.getAsObject(context, component, (String) submittedValue);
} else {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Fri Jun 10 14:29:16 2016
@@ -36,6 +36,7 @@ import org.apache.myfaces.tobago.renderk
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.el.ValueExpression;
import javax.faces.FactoryFinder;
import javax.faces.application.FacesMessage;
import javax.faces.component.NamingContainer;
@@ -49,6 +50,7 @@ import javax.faces.component.UIViewRoot;
import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
@@ -69,7 +71,7 @@ public final class ComponentUtils {
private static final Logger LOG = LoggerFactory.getLogger(ComponentUtils.class);
public static final String SUB_SEPARATOR = "::";
-
+
private static final String RENDER_KEY_PREFIX
= "org.apache.myfaces.tobago.util.ComponentUtils.RendererKeyPrefix_";
@@ -83,6 +85,7 @@ public final class ComponentUtils {
/**
* Name of the map for data attributes in components. New in JSF 2.2.
+ *
* @since 2.0.0
*/
public static final String DATA_ATTRIBUTES_KEY = "javax.faces.component.DATA_ATTRIBUTES_KEY";
@@ -302,7 +305,7 @@ public final class ComponentUtils {
public static <T extends UIComponent> List<T> findDescendantList(final UIComponent component, final Class<T> type) {
final List<T> result = new ArrayList<T>();
-
+
for (final UIComponent child : component.getChildren()) {
if (type.isAssignableFrom(child.getClass())) {
result.add((T) child);
@@ -593,16 +596,16 @@ public final class ComponentUtils {
* The search depends on the number of prefixed colons in the relativeId:
* </p>
* <dl>
- * <dd>number of prefixed colons == 0</dd>
- * <dt>fully relative</dt>
- * <dd>number of prefixed colons == 1</dd>
- * <dt>absolute (still normal findComponent syntax)</dt>
- * <dd>number of prefixed colons == 2</dd>
- * <dt>search in the current naming container (same as 0 colons)</dt>
- * <dd>number of prefixed colons == 3</dd>
- * <dt>search in the parent naming container of the current naming container</dt>
- * <dd>number of prefixed colons > 3</dd>
- * <dt>go to the next parent naming container for each additional colon</dt>
+ * <dd>number of prefixed colons == 0</dd>
+ * <dt>fully relative</dt>
+ * <dd>number of prefixed colons == 1</dd>
+ * <dt>absolute (still normal findComponent syntax)</dt>
+ * <dd>number of prefixed colons == 2</dd>
+ * <dt>search in the current naming container (same as 0 colons)</dt>
+ * <dd>number of prefixed colons == 3</dd>
+ * <dt>search in the parent naming container of the current naming container</dt>
+ * <dd>number of prefixed colons > 3</dd>
+ * <dt>go to the next parent naming container for each additional colon</dt>
* </dl>
* <p>
* If a literal is specified: to use more than one identifier the identifiers must be space delimited.
@@ -783,7 +786,7 @@ public final class ComponentUtils {
}
/**
- * Adding a data attribute to the component.
+ * Adding a data attribute to the component.
* The name must start with "data-", e. g. "data-tobago-foo" or "data-bar"
*/
public static void putDataAttributeWithPrefix(
@@ -817,4 +820,41 @@ public final class ComponentUtils {
Map<Object, Object> map = getDataAttributes(component);
return map != null ? map.get(name) : null;
}
+
+ public static Converter getConverter(final FacesContext facesContext, final UIComponent component) {
+
+ Converter converter = null;
+ if (component instanceof ValueHolder) {
+ converter = ((ValueHolder) component).getConverter();
+ }
+
+ if (converter == null) {
+ final ValueExpression valueExpression = component.getValueExpression("value");
+ if (valueExpression != null) {
+ final Class converterType = valueExpression.getType(facesContext.getELContext());
+ if (converterType != null && converterType != String.class && converterType != Object.class) {
+ converter = facesContext.getApplication().createConverter(converterType);
+ }
+ }
+ }
+
+ return converter;
+ }
+
+ public static String getFormattedValue(
+ final FacesContext facesContext, final UIComponent component, final Object currentValue)
+ throws ConverterException {
+
+ if (currentValue == null) {
+ return "";
+ }
+
+ final Converter converter = ComponentUtils.getConverter(facesContext, component);
+ if (converter != null) {
+ return converter.getAsString(facesContext, component, currentValue);
+ } else {
+ return currentValue.toString();
+ }
+ }
+
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyCheckboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyCheckboxRenderer.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyCheckboxRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyCheckboxRenderer.java Fri Jun 10 14:29:16 2016
@@ -73,7 +73,7 @@ public class SelectManyCheckboxRenderer
writer.startElement(HtmlElements.LABEL);
writer.startElement(HtmlElements.INPUT);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX);
- final String formattedValue = RenderUtils.getFormattedValue(facesContext, select, item.getValue());
+ final String formattedValue = ComponentUtils.getFormattedValue(facesContext, select, item.getValue());
boolean checked;
if (submittedValues == null) {
checked = RenderUtils.contains(values, item.getValue());
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java Fri Jun 10 14:29:16 2016
@@ -76,7 +76,7 @@ public class SelectOneRadioRenderer exte
writer.startElement(HtmlElements.LABEL);
writer.startElement(HtmlElements.INPUT);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.RADIO);
- final String formattedValue = RenderUtils.getFormattedValue(facesContext, select, item.getValue());
+ final String formattedValue = ComponentUtils.getFormattedValue(facesContext, select, item.getValue());
boolean checked;
if (submittedValue == null) {
checked = ObjectUtils.equals(item.getValue(), value);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java Fri Jun 10 14:29:16 2016
@@ -148,7 +148,7 @@ public abstract class ToolBarRendererBas
ComponentUtils.setAttribute(command, Attributes.tip, item.getDescription());
}
- final String formattedValue = RenderUtils.getFormattedValue(facesContext, radio, item.getValue());
+ final String formattedValue = ComponentUtils.getFormattedValue(facesContext, radio, item.getValue());
final boolean checked;
if (ObjectUtils.equals(item.getValue(), value) || markFirst) {
checked = true;
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Fri Jun 10 14:29:16 2016
@@ -224,7 +224,7 @@ public final class HtmlRendererUtils {
if (itemValue instanceof String && values != null && values.length > 0 && !(values[0] instanceof String)) {
itemValue = ComponentUtils.getConvertedValue(facesContext, component, (String) itemValue);
}
- final String formattedValue = RenderUtils.getFormattedValue(facesContext, component, itemValue);
+ final String formattedValue = ComponentUtils.getFormattedValue(facesContext, component, itemValue);
boolean contains;
if (submittedValues == null) {
contains = RenderUtils.contains(values, itemValue);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java?rev=1747720&r1=1747719&r2=1747720&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java Fri Jun 10 14:29:16 2016
@@ -42,8 +42,6 @@ import javax.faces.component.behavior.Cl
import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
import javax.faces.render.ClientBehaviorRenderer;
import java.io.IOException;
import java.net.URLDecoder;
@@ -115,47 +113,6 @@ public final class RenderUtils {
return false;
}
- public static String getFormattedValue(final FacesContext facesContext, final UIComponent component) {
- Object value = null;
- if (component instanceof ValueHolder) {
- value = ((ValueHolder) component).getLocalValue();
- if (value == null) {
- value = ((ValueHolder) component).getValue();
- }
- }
- return getFormattedValue(facesContext, component, value);
- }
-
- // Copy from RendererBase
- public static String getFormattedValue(
- final FacesContext context, final UIComponent component, final Object currentValue)
- throws ConverterException {
-
- if (currentValue == null) {
- return "";
- }
-
- if (!(component instanceof ValueHolder)) {
- return currentValue.toString();
- }
-
- Converter converter = ((ValueHolder) component).getConverter();
-
- if (converter == null) {
- if (currentValue instanceof String) {
- return (String) currentValue;
- }
- final Class converterType = currentValue.getClass();
- converter = context.getApplication().createConverter(converterType);
- }
-
- if (converter == null) {
- return currentValue.toString();
- } else {
- return converter.getAsString(context, component, currentValue);
- }
- }
-
public static String currentValue(final UIComponent component) {
String currentValue = null;
if (component instanceof ValueHolder) {
@@ -169,18 +126,7 @@ public final class RenderUtils {
value = ((ValueHolder) component).getValue();
if (value != null) {
- Converter converter = ((ValueHolder) component).getConverter();
- if (converter == null) {
- final FacesContext context = FacesContext.getCurrentInstance();
- converter = context.getApplication().createConverter(value.getClass());
- }
- if (converter != null) {
- currentValue =
- converter.getAsString(FacesContext.getCurrentInstance(),
- component, value);
- } else {
- currentValue = value.toString();
- }
+ currentValue = ComponentUtils.getFormattedValue(FacesContext.getCurrentInstance(), component, value);
}
}
return currentValue;