myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1585032 - in /myfaces/core/trunk: api/src/main/java/javax/faces/component/ shared-public/src/main/java/org/apache/myfaces/shared/util/ shared/src/main/java/org/apache/myfaces/shared/renderkit/html/ shared/src/main/java/org/apache/myfaces/s...
Date Sat, 05 Apr 2014 09:30:10 GMT
Author: lu4242
Date: Sat Apr  5 09:30:10 2014
New Revision: 1585032

URL: http://svn.apache.org/r1585032
Log:
MYFACES-3879 - Passthrough attributes for f:selectItem and f:selectItems should be rendered
by associated components

Added:
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemInfo.java
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemsUtils.java
Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
    myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSelectableRendererBase.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsIterator.java?rev=1585032&r1=1585031&r2=1585032&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsIterator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsIterator.java Sat
Apr  5 09:30:10 2014
@@ -55,6 +55,7 @@ class _SelectItemsIterator implements It
     private final Iterator<UIComponent> _children;
     private Iterator<?> _nestedItems;
     private SelectItem _nextItem;
+    private UIComponent _currentComponent;
     private UISelectItems _currentUISelectItems;
     private FacesContext _facesContext;
 
@@ -80,6 +81,7 @@ class _SelectItemsIterator implements It
                 return true;
             }
             _nestedItems = null;
+            _currentComponent = null;
         }
         if (_children.hasNext())
         {
@@ -132,12 +134,14 @@ class _SelectItemsIterator implements It
                             + getPathToComponent(child) + " does not reference an Object
of type SelectItem");
                 }
                 _nextItem = (SelectItem) item;
+                _currentComponent = child;
                 return true;
             }
             else if (child instanceof UISelectItems)
             {
                 _currentUISelectItems = ((UISelectItems) child);
                 Object value = _currentUISelectItems.getValue();
+                _currentComponent = child;
 
                 if (value instanceof SelectItem)
                 {
@@ -197,6 +201,10 @@ class _SelectItemsIterator implements It
                     }
                 }
             }
+            else
+            {
+                _currentComponent = null;
+            }
         }
         return false;
     }
@@ -296,6 +304,11 @@ class _SelectItemsIterator implements It
         throw new UnsupportedOperationException();
     }
     
+    public UIComponent getCurrentComponent()
+    {
+        return _currentComponent;
+    }
+
     private boolean getBooleanAttribute(UIComponent component, String attrName, boolean defaultValue)
     {
         Object value = component.getAttributes().get(attrName);

Modified: myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java?rev=1585032&r1=1585031&r2=1585032&view=diff
==============================================================================
--- myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
(original)
+++ myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
Sat Apr  5 09:30:10 2014
@@ -58,6 +58,7 @@ public class SelectItemsIterator impleme
     private final Iterator<UIComponent> _children;
     private Iterator<? extends Object> _nestedItems;
     private SelectItem _nextItem;
+    private UIComponent _currentComponent;
     private UISelectItems _currentUISelectItems;
     private FacesContext _facesContext;
 
@@ -83,6 +84,7 @@ public class SelectItemsIterator impleme
                 return true;
             }
             _nestedItems = null;
+            _currentComponent = null;
         }
         if (_children.hasNext())
         {
@@ -136,12 +138,14 @@ public class SelectItemsIterator impleme
                             + " does not reference an Object of type SelectItem");
                 }
                 _nextItem = (SelectItem) item;
+                _currentComponent = child;
                 return true;
             }
             else if (child instanceof UISelectItems)
             {
                 _currentUISelectItems = ((UISelectItems) child);
                 Object value = _currentUISelectItems.getValue();
+                _currentComponent = child;
 
                 if (value instanceof SelectItem)
                 {
@@ -201,6 +205,10 @@ public class SelectItemsIterator impleme
                     }
                 }
             }
+            else
+            {
+                _currentComponent = null;
+            }
         }
         return false;
     }
@@ -300,6 +308,11 @@ public class SelectItemsIterator impleme
         throw new UnsupportedOperationException();
     }
     
+    public UIComponent getCurrentComponent()
+    {
+        return _currentComponent;
+    }
+
     private boolean getBooleanAttribute(UIComponent component, String attrName, boolean defaultValue)
     {
         Object value = component.getAttributes().get(attrName);

Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java?rev=1585032&r1=1585031&r2=1585032&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
(original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
Sat Apr  5 09:30:10 2014
@@ -42,6 +42,8 @@ import javax.faces.model.SelectItemGroup
 
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
+import org.apache.myfaces.shared.renderkit.html.util.SelectItemInfo;
+import org.apache.myfaces.shared.renderkit.html.util.SelectItemsUtils;
 
 public class HtmlCheckboxRendererBase extends HtmlRenderer
 {
@@ -74,7 +76,7 @@ public class HtmlCheckboxRendererBase ex
         {
             Boolean value = org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanValue(
uiComponent );
             boolean isChecked = value != null ? value.booleanValue() : false;
-            renderCheckbox(facesContext, uiComponent, EXTERNAL_TRUE_VALUE, false,isChecked,
true, null); 
+            renderCheckbox(facesContext, uiComponent, EXTERNAL_TRUE_VALUE, uiComponent, false,isChecked,
true, null); 
                 //TODO: the selectBoolean is never disabled
         }
         else if (uiComponent instanceof UISelectMany)
@@ -151,14 +153,16 @@ public class HtmlCheckboxRendererBase ex
 
         int itemNum = 0;
 
-        for (Iterator it = org.apache.myfaces.shared.renderkit.RendererUtils.getSelectItemList(
+        for (Iterator it = SelectItemsUtils.getSelectItemInfoList(
                 selectMany, facesContext)
                 .iterator(); it.hasNext();)
         {
-            SelectItem selectItem = (SelectItem) it.next();
+            SelectItemInfo selectItemInfo = (SelectItemInfo) it.next();
+            SelectItem selectItem = (SelectItem) selectItemInfo.getItem();
             
             itemNum = renderGroupOrItemCheckbox(facesContext, selectMany, 
-                                                selectItem, useSubmittedValues, lookupSet,

+                                                selectItem, selectItemInfo.getComponent(),
+                                                useSubmittedValues, lookupSet, 
                                                 converter, pageDirectionLayout, itemNum);
         }
 
@@ -198,6 +202,17 @@ public class HtmlCheckboxRendererBase ex
                                              Converter converter, boolean pageDirectionLayout,

                                              Integer itemNum) throws IOException
     {
+        return renderGroupOrItemCheckbox(facesContext, uiComponent, selectItem, null, useSubmittedValues,
lookupSet, 
+                converter, pageDirectionLayout, itemNum);
+    }
+    
+    protected int renderGroupOrItemCheckbox(FacesContext facesContext,
+                                             UIComponent uiComponent, SelectItem selectItem,

+                                             UIComponent selectItemComponent,
+                                             boolean useSubmittedValues, Set lookupSet,
+                                             Converter converter, boolean pageDirectionLayout,

+                                             Integer itemNum) throws IOException
+    {
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
@@ -289,7 +304,8 @@ public class HtmlCheckboxRendererBase ex
 
             boolean disabled = selectItem.isDisabled();
 
-            String itemId = renderCheckbox(facesContext, selectMany, itemStrValue, disabled,
checked, false, itemNum);
+            String itemId = renderCheckbox(facesContext, selectMany, itemStrValue, selectItemComponent,
+                    disabled, checked, false, itemNum);
 
             // label element after the input
             boolean componentDisabled = isDisabled(facesContext, selectMany);
@@ -323,7 +339,16 @@ public class HtmlCheckboxRendererBase ex
      * @return the 'id' value of the rendered element
      */
     protected String renderCheckbox(FacesContext facesContext,
-            UIComponent uiComponent, String value, boolean disabled, boolean checked, 
+            UIComponent uiComponent, String value,
+            boolean disabled, boolean checked, 
+            boolean renderId, Integer itemNum) throws IOException
+    {
+        return renderCheckbox(facesContext, uiComponent, value, null, disabled, checked,
renderId, itemNum);
+    }
+    
+    protected String renderCheckbox(FacesContext facesContext,
+            UIComponent uiComponent, String value, UIComponent selectItemComponent,
+            boolean disabled, boolean checked, 
             boolean renderId, Integer itemNum) throws IOException
     {
         String clientId = uiComponent.getClientId(facesContext);
@@ -333,7 +358,7 @@ public class HtmlCheckboxRendererBase ex
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
-        writer.startElement(HTML.INPUT_ELEM, uiComponent);
+        writer.startElement(HTML.INPUT_ELEM, selectItemComponent);
 
         if (itemId != null)
         {

Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java?rev=1585032&r1=1585031&r2=1585032&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java
(original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java
Sat Apr  5 09:30:10 2014
@@ -40,6 +40,8 @@ import javax.faces.model.SelectItemGroup
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
+import org.apache.myfaces.shared.renderkit.html.util.SelectItemInfo;
+import org.apache.myfaces.shared.renderkit.html.util.SelectItemsUtils;
 
 public class HtmlRadioRendererBase
         extends HtmlRenderer
@@ -109,7 +111,7 @@ public class HtmlRadioRendererBase
         }
 
         Converter converter;
-        List selectItemList = org.apache.myfaces.shared.renderkit.RendererUtils.getSelectItemList(
+        List<SelectItemInfo> selectItemList = SelectItemsUtils.getSelectItemInfoList(
                 selectOne, facesContext);
         converter = HtmlRendererUtils.findUIOutputConverterFailSafe(facesContext, selectOne);
         
@@ -119,12 +121,13 @@ public class HtmlRadioRendererBase
 
         int itemNum = 0;
 
-        for (Iterator it = selectItemList.iterator(); it.hasNext(); )
+        for (Iterator<SelectItemInfo> it = selectItemList.iterator(); it.hasNext();
)
         {
-            SelectItem selectItem = (SelectItem)it.next();
+            SelectItemInfo selectItemInfo = (SelectItemInfo)it.next();
+            SelectItem selectItem = selectItemInfo.getItem();
 
             itemNum = renderGroupOrItemRadio(facesContext, selectOne,
-                                             selectItem, currentValue,
+                                             selectItem, selectItemInfo.getComponent(), currentValue,
                                              converter, pageDirectionLayout, itemNum);
         }
 
@@ -157,7 +160,6 @@ public class HtmlRadioRendererBase
          return (String)selectOne.getAttributes().get(JSFAttr.STYLE_CLASS_ATTR);
      }
 
-
     /**
      * Renders the given SelectItem(Group)
      * @return the itemNum for the next item
@@ -168,6 +170,17 @@ public class HtmlRadioRendererBase
                                          Converter converter, boolean pageDirectionLayout,
                                          Integer itemNum) throws IOException
     {
+        return renderGroupOrItemRadio(facesContext, uiComponent, selectItem, null, 
+                currentValue, converter, pageDirectionLayout, itemNum);
+    }
+
+    protected int renderGroupOrItemRadio(FacesContext facesContext,
+                                         UIComponent uiComponent, SelectItem selectItem,

+                                         UIComponent selectItemComponent,
+                                         Object currentValue,
+                                         Converter converter, boolean pageDirectionLayout,
+                                         Integer itemNum) throws IOException
+    {
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
@@ -264,7 +277,7 @@ public class HtmlRadioRendererBase
     
             boolean itemDisabled = selectItem.isDisabled();
     
-            String itemId = renderRadio(facesContext, selectOne, itemStrValue, itemDisabled,

+            String itemId = renderRadio(facesContext, selectOne, itemStrValue, selectItemComponent,
itemDisabled, 
                     itemChecked, false, itemNum);
     
             // label element after the input
@@ -297,6 +310,18 @@ public class HtmlRadioRendererBase
         renderRadio(facesContext, (UIInput) uiComponent, value, disabled, checked, renderId,
0);
     }
 
+    
+    protected String renderRadio(FacesContext facesContext,
+                               UIInput uiComponent,
+                               String value,
+                               boolean disabled,
+                               boolean checked,
+                               boolean renderId,
+                               Integer itemNum)
+            throws IOException
+    {
+        return renderRadio(facesContext, uiComponent, value, null, disabled, checked, renderId,
itemNum);
+    }    
     /**
      * Renders the input item
      * @return the 'id' value of the rendered element
@@ -304,6 +329,7 @@ public class HtmlRadioRendererBase
     protected String renderRadio(FacesContext facesContext,
                                UIInput uiComponent,
                                String value,
+                               UIComponent selectItemComponent,
                                boolean disabled,
                                boolean checked,
                                boolean renderId,
@@ -317,7 +343,7 @@ public class HtmlRadioRendererBase
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
-        writer.startElement(HTML.INPUT_ELEM, uiComponent);
+        writer.startElement(HTML.INPUT_ELEM, selectItemComponent);
 
         if (itemId != null)
         {

Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSelectableRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSelectableRendererBase.java?rev=1585032&r1=1585031&r2=1585032&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSelectableRendererBase.java
(original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSelectableRendererBase.java
Sat Apr  5 09:30:10 2014
@@ -30,7 +30,8 @@ import javax.faces.component.behavior.Cl
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.convert.Converter;
-import org.apache.myfaces.shared.renderkit.RendererUtils;
+import org.apache.myfaces.shared.renderkit.html.util.SelectItemInfo;
+import org.apache.myfaces.shared.renderkit.html.util.SelectItemsUtils;
 
 public class HtmlSelectableRendererBase extends HtmlRenderer
 {
@@ -55,16 +56,15 @@ public class HtmlSelectableRendererBase 
         }
         writer.writeAttribute(HTML.NAME_ATTR,
                 uiComponent.getClientId(facesContext), null);
-        List selectItemList;
+        List<SelectItemInfo> selectItemList;
         if (selectMany)
         {
             writer.writeAttribute(HTML.MULTIPLE_ATTR, HTML.MULTIPLE_ATTR, null);
-            selectItemList = org.apache.myfaces.shared.renderkit.RendererUtils
-                    .getSelectItemList((UISelectMany) uiComponent, facesContext);
+            selectItemList = SelectItemsUtils.getSelectItemInfoList((UISelectMany) uiComponent,
facesContext);
         }
         else
         {
-            selectItemList = RendererUtils.getSelectItemList(
+            selectItemList = SelectItemsUtils.getSelectItemInfoList(
                     (UISelectOne) uiComponent, facesContext);
         }
 
@@ -157,7 +157,7 @@ public class HtmlSelectableRendererBase 
         Set lookupSet = HtmlRendererUtils.getSubmittedOrSelectedValuesAsSet(selectMany,
                 uiComponent, facesContext, converter);
 
-        HtmlRendererUtils.renderSelectOptions(facesContext, uiComponent, converter, lookupSet,
+        SelectItemsUtils.renderSelectOptions(facesContext, uiComponent, converter, lookupSet,
                 selectItemList);
         // bug #970747: force separate end tag
         writer.writeText(HtmlRendererUtils.STR_EMPTY, null);

Added: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemInfo.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemInfo.java?rev=1585032&view=auto
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemInfo.java
(added)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemInfo.java
Sat Apr  5 09:30:10 2014
@@ -0,0 +1,57 @@
+/*
+ * 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 org.apache.myfaces.shared.renderkit.html.util;
+
+import javax.faces.component.UIComponent;
+import javax.faces.model.SelectItem;
+
+/**
+ *
+ * @author lu4242
+ */
+public class SelectItemInfo
+{
+    private final SelectItem item;
+    
+    private final UIComponent component;
+
+    public SelectItemInfo(SelectItem item, UIComponent component)
+    {
+        this.item = item;
+        this.component = component;
+    }
+
+    /**
+     * @return the item
+     */
+    public SelectItem getItem()
+    {
+        return item;
+    }
+
+    /**
+     * @return the component
+     */
+    public UIComponent getComponent()
+    {
+        return component;
+    }
+    
+}

Added: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemsUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemsUtils.java?rev=1585032&view=auto
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemsUtils.java
(added)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/SelectItemsUtils.java
Sat Apr  5 09:30:10 2014
@@ -0,0 +1,222 @@
+/*
+ * 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 org.apache.myfaces.shared.renderkit.html.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectMany;
+import javax.faces.component.UISelectOne;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.Converter;
+import javax.faces.model.SelectItem;
+import javax.faces.model.SelectItemGroup;
+import org.apache.myfaces.shared.component.EscapeCapable;
+import org.apache.myfaces.shared.renderkit.JSFAttr;
+import org.apache.myfaces.shared.renderkit.RendererUtils;
+import org.apache.myfaces.shared.renderkit.html.HTML;
+import static org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils.isHideNoSelectionOption;
+import org.apache.myfaces.shared.util.SelectItemsIterator;
+
+/**
+ * Utility methods to manipulate SelectItem/SelectItems
+ */
+public class SelectItemsUtils
+{
+    private static final char TABULATOR = '\t';
+
+    public static List<SelectItemInfo> getSelectItemInfoList(UISelectMany uiSelectMany,
+            FacesContext facesContext)
+    {
+        List<SelectItemInfo> list = new ArrayList<SelectItemInfo>();
+
+        for (SelectItemsIterator iter = new SelectItemsIterator(uiSelectMany, facesContext);
iter
+                .hasNext();)
+        {
+            list.add(new SelectItemInfo(iter.next(), iter.getCurrentComponent()));
+        }
+        return list;
+    }
+
+    public static List<SelectItemInfo> getSelectItemInfoList(UISelectOne uiSelectOne,
+            FacesContext facesContext)
+    {
+        List<SelectItemInfo> list = new ArrayList<SelectItemInfo>();
+        for (SelectItemsIterator iter = new SelectItemsIterator(uiSelectOne, facesContext);
iter
+                .hasNext();)
+        {
+            list.add(new SelectItemInfo(iter.next(), iter.getCurrentComponent()));
+        }
+        return list;
+    }
+    
+public static void renderSelectOptions(FacesContext context,
+            UIComponent component, Converter converter, Set lookupSet,
+            List<SelectItemInfo> selectItemList) throws IOException
+    {
+        ResponseWriter writer = context.getResponseWriter();
+        // check for the hideNoSelectionOption attribute
+        boolean hideNoSelectionOption = isHideNoSelectionOption(component);
+        boolean componentDisabled = isTrue(component.getAttributes()
+                .get("disabled"));
+
+        for (Iterator<SelectItemInfo> it = selectItemList.iterator(); it.hasNext();)
+        {
+            SelectItemInfo selectItemInfo = it.next();
+            SelectItem selectItem = selectItemInfo.getItem();
+            if (selectItem instanceof SelectItemGroup)
+            {
+                writer.startElement(HTML.OPTGROUP_ELEM, selectItemInfo.getComponent()); //
component);
+                writer.writeAttribute(HTML.LABEL_ATTR, selectItem.getLabel(),
+                        null);
+                SelectItem[] selectItems = ((SelectItemGroup) selectItem)
+                        .getSelectItems();
+                List<SelectItemInfo> selectItemsGroupList = new ArrayList<SelectItemInfo>(selectItems.length);
+                for (SelectItem item : selectItems)
+                {
+                    selectItemsGroupList.add(new SelectItemInfo(item, null));
+                }
+                renderSelectOptions(context, component, converter, lookupSet,
+                        selectItemsGroupList);
+                writer.endElement(HTML.OPTGROUP_ELEM);
+            }
+            else
+            {
+                String itemStrValue = org.apache.myfaces.shared.renderkit.RendererUtils
+                        .getConvertedStringValue(context, component, converter,
+                                selectItem);
+                boolean selected = lookupSet.contains(itemStrValue); 
+                //TODO/FIX: we always compare the String vales, better fill lookupSet with
Strings 
+                //only when useSubmittedValue==true, else use the real item value Objects
+
+                // IF the hideNoSelectionOption attribute of the component is true
+                // AND this selectItem is the "no selection option"
+                // AND there are currently selected items 
+                // AND this item (the "no selection option") is not selected
+                // (if there is currently no value on UISelectOne, lookupSet contains "")
+                if (hideNoSelectionOption && selectItem.isNoSelectionOption()
+                        && lookupSet.size() != 0
+                        && !(lookupSet.size() == 1 && lookupSet.contains(""))
+                        && !selected)
+                {
+                    // do not render this selectItem
+                    continue;
+                }
+
+                writer.write(TABULATOR);
+                writer.startElement(HTML.OPTION_ELEM, selectItemInfo.getComponent()); //
component);
+                if (itemStrValue != null)
+                {
+                    writer.writeAttribute(HTML.VALUE_ATTR, itemStrValue, null);
+                }
+                else
+                {
+                    writer.writeAttribute(HTML.VALUE_ATTR, "", null);
+                }
+
+                if (selected)
+                {
+                    writer.writeAttribute(HTML.SELECTED_ATTR, HTML.SELECTED_ATTR, null);
+                }
+
+                boolean disabled = selectItem.isDisabled();
+                if (disabled)
+                {
+                    writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
+                }
+
+                String labelClass = null;
+
+                if (componentDisabled || disabled)
+                {
+                    labelClass = (String) component.getAttributes().get(
+                            JSFAttr.DISABLED_CLASS_ATTR);
+                }
+                else
+                {
+                    labelClass = (String) component.getAttributes().get(
+                            JSFAttr.ENABLED_CLASS_ATTR);
+                }
+                if (labelClass != null)
+                {
+                    writer.writeAttribute("class", labelClass, "labelClass");
+                }
+
+                boolean escape;
+                if (component instanceof EscapeCapable)
+                {
+                    escape = ((EscapeCapable) component).isEscape();
+
+                    // Preserve tomahawk semantic. If escape=false
+                    // all items should be non escaped. If escape
+                    // is true check if selectItem.isEscape() is
+                    // true and do it.
+                    // This is done for remain compatibility.
+                    if (escape && selectItem.isEscape())
+                    {
+                        writer.writeText(selectItem.getLabel(), null);
+                    }
+                    else
+                    {
+                        writer.write(selectItem.getLabel());
+                    }
+                }
+                else
+                {
+                    escape = RendererUtils.getBooleanAttribute(component,
+                            JSFAttr.ESCAPE_ATTR, false);
+                    //default is to escape
+                    //In JSF 1.2, when a SelectItem is created by default 
+                    //selectItem.isEscape() returns true (this property
+                    //is not available on JSF 1.1).
+                    //so, if we found a escape property on the component
+                    //set to true, escape every item, but if not
+                    //check if isEscape() = true first.
+                    if (escape || selectItem.isEscape())
+                    {
+                        writer.writeText(selectItem.getLabel(), null);
+                    }
+                    else
+                    {
+                        writer.write(selectItem.getLabel());
+                    }
+                }
+
+                writer.endElement(HTML.OPTION_ELEM);
+            }
+        }
+    }
+
+    private static boolean isTrue(Object obj)
+    {
+        if (obj instanceof String)
+        {
+            return Boolean.valueOf((String) obj);
+        }
+        if (!(obj instanceof Boolean))
+        {
+            return false;
+        }
+        return ((Boolean) obj).booleanValue();
+    }
+}



Mime
View raw message