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 2019/01/17 14:18:08 UTC
[myfaces-tobago] branch tobago-4.x updated: TOBAGO-1975:
may be more robust against null pointers
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch tobago-4.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/tobago-4.x by this push:
new d38d0fb TOBAGO-1975: <tc:selectItems> may be more robust against null pointers
d38d0fb is described below
commit d38d0fb0c0107a09d900850e84e44c3ef3065bd6
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Thu Jan 17 13:58:42 2019 +0100
TOBAGO-1975: <tc:selectItems> may be more robust against null pointers
---
.../myfaces/tobago/internal/util/SelectItemUtils.java | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/SelectItemUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/SelectItemUtils.java
index 74a1b5e..89a4180 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/SelectItemUtils.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/SelectItemUtils.java
@@ -23,6 +23,8 @@ import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.component.Visual;
import org.apache.myfaces.tobago.context.Markup;
import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
@@ -30,6 +32,7 @@ import javax.faces.component.UISelectItem;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
+import java.lang.invoke.MethodHandles;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,6 +47,8 @@ import java.util.NoSuchElementException;
*/
public class SelectItemUtils {
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
/**
* Creates a list of SelectItems to use for rendering.
*/
@@ -232,17 +237,21 @@ public class SelectItemUtils {
// Spec: When iterating over the select items, toString()
// must be called on the string rendered attribute values
- Object itemLabel = ComponentUtils.getAttribute(currentUISelectItems, Attributes.itemLabel);
- if (itemLabel == null) {
+ final Object itemLabelObject = ComponentUtils.getAttribute(currentUISelectItems, Attributes.itemLabel);
+ final String itemLabel;
+ if (itemLabelObject != null) {
+ itemLabel = itemLabelObject.toString();
+ } else if (itemValue != null) {
itemLabel = itemValue.toString();
} else {
- itemLabel = itemLabel.toString();
+ LOG.warn("Label string can't be created!");
+ itemLabel = "???";
}
Object itemDescription = ComponentUtils.getAttribute(currentUISelectItems, Attributes.itemDescription);
if (itemDescription != null) {
itemDescription = itemDescription.toString();
}
- final Boolean itemDisabled
+ final boolean itemDisabled
= ComponentUtils.getBooleanAttribute(currentUISelectItems, Attributes.itemDisabled, false);
final String itemImage = ComponentUtils.getStringAttribute(currentUISelectItems, Attributes.itemImage);
final Markup markup;
@@ -256,7 +265,7 @@ public class SelectItemUtils {
// TBD ?
// Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_PROP);
item = new org.apache.myfaces.tobago.model.SelectItem(
- itemValue, (String) itemLabel, (String) itemDescription, itemDisabled, itemImage, markup);
+ itemValue, itemLabel, (String) itemDescription, itemDisabled, itemImage, markup);
// remove the value with the key from var from the request map, if previously written
if (wroteRequestMapVarValue) {