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.custom.tree.renderkit.html;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.context.FacesContext;
23  
24  import org.apache.myfaces.custom.tree.HtmlTreeNode;
25  import org.apache.myfaces.renderkit.html.jsf.ExtendedHtmlLinkRenderer;
26  import org.apache.myfaces.renderkit.html.util.DummyFormUtils;
27  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
28  
29  /**
30   * @JSFRenderer
31   *   renderKitId = "HTML_BASIC" 
32   *   family = "javax.faces.Command"
33   *   type = "org.apache.myfaces.HtmlTreeNode"
34   * 
35   * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
36   * @version $Revision: 659874 $ $Date: 2008-05-24 15:59:15 -0500 (Sat, 24 May 2008) $
37   */
38  public class HtmlTreeNodeRenderer
39      extends ExtendedHtmlLinkRenderer {
40  
41      public void decode(FacesContext facesContext, UIComponent component) {
42          super.decode(facesContext, component);
43          String clientId = component.getClientId(facesContext);
44          String reqValue = (String) facesContext
45              .getExternalContext()
46              .getRequestParameterMap()
47              .get(HtmlRendererUtils
48                  .getHiddenCommandLinkFieldName(DummyFormUtils
49                  .findNestingForm(component, facesContext)));
50          if (reqValue != null && reqValue.equals(clientId)) {
51              HtmlTreeNode node = (HtmlTreeNode) component;
52  
53              node.setSelected(true);
54          }
55      }
56  }