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.component.UISelectOne;
26  import javax.faces.context.FacesContext;
27  import javax.faces.convert.Converter;
28  import javax.faces.convert.ConverterException;
29  
30  import org.apache.myfaces.component.UserRoleUtils;
31  import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
32  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlMenuRendererBase;
33  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
34  
35  
36  /**
37   * @JSFRenderer
38   *   renderKitId = "HTML_BASIC"
39   *   family = "javax.faces.SelectOne"
40   *   type = "org.apache.myfaces.Menu"
41   *   
42   * @JSFRenderer
43   *   renderKitId = "HTML_BASIC"
44   *   family = "javax.faces.SelectMany"
45   *   type = "org.apache.myfaces.Menu"
46   * 
47   * @author Manfred Geiler (latest modification by $Author: lu4242 $)
48   * @version $Revision: 1327287 $ $Date: 2012-04-17 16:21:09 -0500 (Tue, 17 Apr 2012) $
49   */
50  public class HtmlMenuRenderer
51          extends HtmlMenuRendererBase
52  {
53      //private static final Log log = LogFactory.getLog(HtmlMenuRenderer.class);
54      
55      @Override
56      protected boolean isCommonPropertiesOptimizationEnabled(FacesContext facesContext)
57      {
58          return true;
59      }
60  
61      @Override
62      protected boolean isCommonEventsOptimizationEnabled(FacesContext facesContext)
63      {
64          return true;
65      }
66      
67      protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
68      {
69          if (!UserRoleUtils.isEnabledOnUserRole(uiComponent))
70          {
71              return true;
72          }
73          else
74          {
75              return super.isDisabled(facesContext, uiComponent);
76          }
77      }
78  
79      public void encodeEnd(FacesContext facesContext, UIComponent component)
80              throws IOException
81      {
82          if(HtmlRendererUtils.isDisplayValueOnly(component))
83          {
84              HtmlRendererUtils.renderDisplayValueOnlyForSelects(facesContext, component, true);
85          }
86          else
87          {
88              super.encodeEnd(facesContext, component);
89          }
90      }
91      
92      /**
93       * Overrides HtmlMenuRendererBase to handle valueType attribute on UISelectMany.
94       */
95      @Override
96      public Object getConvertedValue(FacesContext facesContext,
97              UIComponent component, Object submittedValue)
98              throws ConverterException
99      {
100         RendererUtils.checkParamValidity(facesContext, component, null);
101         
102         if (component instanceof UISelectMany) 
103         {
104             // invoke getConvertedUISelectManyValue() with considerValueType = true
105             return RendererUtils.getConvertedUISelectManyValue(facesContext,
106                     (UISelectMany) component, submittedValue, true); 
107         } 
108         else 
109         {
110             // component is not a UISelectMany --> no change needed
111             return super.getConvertedValue(facesContext, component, submittedValue);
112         }
113     }
114     
115     /**
116      * Overrides HtmlMenuRendererBase to handle valueType attribute on UISelectMany.
117      */
118     @Override
119     protected Converter getConverter(FacesContext facesContext,
120             UIComponent component)
121     {
122         if (component instanceof UISelectMany)
123         {
124             // invoke findUISelectManyConverterFailsafe() with considerValueType = true
125             return HtmlRendererUtils.findUISelectManyConverterFailsafe(facesContext, 
126                     (UISelectMany) component, true);
127         }
128         else
129         {
130             // component is not a UISelectMany --> no change needed
131             return super.getConverter(facesContext, component);
132         }
133     }
134 
135 }