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  
20  package org.apache.myfaces.custom.toggle;
21  
22  import javax.faces.component.behavior.ClientBehaviorHolder;
23  import javax.faces.component.html.HtmlPanelGroup;
24  import javax.faces.context.FacesContext;
25  
26  import org.apache.myfaces.component.EventAware;
27  import org.apache.myfaces.component.UniversalProperties;
28  
29  /**
30   * Container class allows user to toggle between view/edit mode.
31   * 
32   * Extends PanelGroup. Allows user to toggle between 'view' mode and 'edit' mode. 
33   * In the togglePanel, include a toggleLink. When the toggleLink is clicked, 
34   * the rest of the group is shown, and the link is hidden.
35   * 
36   * @JSFComponent
37   *   name = "t:togglePanel"
38   *   class = "org.apache.myfaces.custom.toggle.TogglePanel"
39   *   tagClass = "org.apache.myfaces.custom.toggle.TogglePanelTag"
40   *   
41   * @author Sharath
42   * 
43   */
44  public abstract class AbstractTogglePanel extends HtmlPanelGroup
45      implements EventAware, UniversalProperties, ClientBehaviorHolder
46  {
47      public static final String COMPONENT_TYPE = "org.apache.myfaces.TogglePanel";
48      public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.TogglePanel";
49  
50      public static final boolean DEFAULT_TOGGLED = false;
51  
52      public static final boolean DEFAULT_DISABLED = false;
53  
54      /**
55       * You can set toggled to true to force the toggleGroup to always be in toggle 
56       * mode. Default is false.
57       * 
58       * @JSFProperty
59       *   defaultValue="false"
60       * @return
61       */
62      public abstract boolean isToggled();
63      
64      public abstract void setToggled(boolean toggleMode);
65      
66      /**
67       * @JSFProperty
68       *   defaultValue="false"
69       * @return
70       */
71      public abstract boolean isDisabled();
72      
73      public void processDecodes(FacesContext context)
74      {
75          super.processDecodes(context);
76  
77          String hiddenFieldId = this.getClientId(context) + "_hidden";
78          String toggleMode = (String) context.getExternalContext().getRequestParameterMap().get(hiddenFieldId);
79  
80          if (toggleMode != null && toggleMode.trim().equals("1")) {
81              this.setToggled(true);
82          }
83      }
84  
85      public void processUpdates(FacesContext context)
86      {
87          super.processUpdates(context);
88          this.setToggled(false);
89      }
90  }