View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.renderkit.html.ext;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.component.UISelectMany;
25  import javax.faces.context.FacesContext;
26  import javax.faces.convert.Converter;
27  import javax.faces.convert.ConverterException;
28  
29  import org.apache.myfaces.component.UserRoleUtils;
30  import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
31  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlListboxRendererBase;
32  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
33  
34  
35  /**
36   * @JSFRenderer
37   *   renderKitId = "HTML_BASIC"
38   *   family = "javax.faces.SelectOne"
39   *   type = "org.apache.myfaces.Listbox"
40   *   
41   * @JSFRenderer
42   *   renderKitId = "HTML_BASIC"
43   *   family = "javax.faces.SelectMany"
44   *   type = "org.apache.myfaces.Listbox"
45   * 
46   * @author Manfred Geiler (latest modification by $Author: lu4242 $)
47   * @version $Revision: 1327287 $ $Date: 2012-04-17 16:21:09 -0500 (Tue, 17 Apr 2012) $
48   */
49  public class HtmlListboxRenderer
50          extends HtmlListboxRendererBase
51  {
52      @Override
53      protected boolean isCommonPropertiesOptimizationEnabled(FacesContext facesContext)
54      {
55          return true;
56      }
57  
58      @Override
59      protected boolean isCommonEventsOptimizationEnabled(FacesContext facesContext)
60      {
61          return true;
62      }
63      
64      protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
65      {
66          if (!UserRoleUtils.isEnabledOnUserRole(uiComponent))
67          {
68              return true;
69          }
70          else
71          {
72              return super.isDisabled(facesContext, uiComponent);
73          }
74      }
75  
76      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
77  
78          if(HtmlRendererUtils.isDisplayValueOnly(uiComponent))
79          {
80              HtmlRendererUtils.renderDisplayValueOnlyForSelects(facesContext, uiComponent, true);
81          }
82          else
83          {
84              super.encodeEnd(facesContext, uiComponent);
85          }
86      }
87      
88      /**
89       * Overrides HtmlListboxRendererBase to handle valueType attribute on UISelectMany.
90       */
91      @Override
92      public Object getConvertedValue(FacesContext facesContext,
93              UIComponent component, Object submittedValue)
94              throws ConverterException
95      {
96          RendererUtils.checkParamValidity(facesContext, component, null);
97          
98          if (component instanceof UISelectMany) 
99          {
100             // invoke getConvertedUISelectManyValue() with considerValueType = true
101             return RendererUtils.getConvertedUISelectManyValue(facesContext,
102                     (UISelectMany) component, submittedValue, true); 
103         } 
104         else 
105         {
106             // component is not a UISelectMany --> no change needed
107             return super.getConvertedValue(facesContext, component, submittedValue);
108         }
109     }
110     
111     /**
112      * Overrides HtmlListboxRendererBase to handle valueType attribute on UISelectMany.
113      */
114     @Override
115     protected Converter getConverter(FacesContext facesContext,
116             UIComponent component)
117     {
118         if (component instanceof UISelectMany)
119         {
120             // invoke findUISelectManyConverterFailsafe() with considerValueType = true
121             return HtmlRendererUtils.findUISelectManyConverterFailsafe(facesContext, 
122                     (UISelectMany) component, true);
123         }
124         else
125         {
126             // component is not a UISelectMany --> no change needed
127             return super.getConverter(facesContext, component);
128         }
129     }
130 
131 }