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