1 16 package org.apache.myfaces.custom.collapsiblepanel; 17 18 import javax.faces.component.html.HtmlPanelGroup; 19 import javax.faces.context.FacesContext; 20 import javax.faces.el.ValueBinding; 21 22 28 public class HtmlCollapsiblePanel extends HtmlPanelGroup 29 { 30 32 private static final boolean DEFAULT_COLLAPSED = true; 34 35 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCollapsiblePanel"; 36 public static final String COMPONENT_FAMILY = "javax.faces.Panel"; 37 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.CollapsiblePanel"; 38 39 private Boolean _collapsed = null; 40 private String _value = null; 41 42 public HtmlCollapsiblePanel() 43 { 44 setRendererType(DEFAULT_RENDERER_TYPE); 45 } 46 47 public String getFamily() 48 { 49 return COMPONENT_FAMILY; 50 } 51 52 public void setCollapsed(boolean collapsed) 53 { 54 _collapsed = new Boolean (collapsed); 55 } 56 57 public boolean isCollapsed() 58 { 59 if (_collapsed != null) return _collapsed.booleanValue(); 60 ValueBinding vb = getValueBinding("collapsed"); 61 Boolean v = vb != null ? (Boolean )vb.getValue(getFacesContext()) : null; 62 return v != null ? v.booleanValue() : DEFAULT_COLLAPSED; 63 } 64 65 public void setValue(String value) 66 { 67 _value = value; 68 } 69 70 public String getValue() 71 { 72 if (_value != null) return _value; 73 ValueBinding vb = getValueBinding("value"); 74 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 75 } 76 77 public Object saveState(FacesContext context) 78 { 79 Object values[] = new Object [3]; 80 values[0] = super.saveState(context); 81 values[1] = _collapsed; 82 values[2] = _value; 83 return ((Object ) (values)); 84 } 85 86 public void restoreState(FacesContext context, Object state) 87 { 88 Object values[] = (Object [])state; 89 super.restoreState(context, values[0]); 90 _collapsed = (Boolean )values[1]; 91 _value = (String )values[2]; 92 } 93 } 95 | Popular Tags |