KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > div > Div


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.div;
17
18 import javax.faces.component.UIOutput;
19 import javax.faces.context.FacesContext;
20 import javax.faces.el.ValueBinding;
21
22 import org.apache.myfaces.component.html.util.HtmlComponentUtils;
23
24 /**
25  * @author bdudney (latest modification by $Author: svieujot $)
26  * @version $Revision: 1.2 $ $Date: 2005/02/09 17:41:30 $
27  * $Log: Div.java,v $
28  * Revision 1.2 2005/02/09 17:41:30 svieujot
29  * Apply Sean Schofield's patch for MYFACES-104
30  *
31  * Revision 1.1 2004/11/08 03:43:20 bdudney
32  * Added a div element. x:div to use, inserts a div with class or style attributes
33  *
34  */

35 public class Div extends UIOutput {
36   public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.Div";
37   public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Output";
38   private static final String JavaDoc DEFAULT_RENDERER_TYPE = DivRenderer.RENDERER_TYPE;
39
40   private String JavaDoc _style = null;
41   private String JavaDoc _styleClass = null;
42
43   // ------------------------------------------------------------ Constructors
44
public Div() {
45     setRendererType(DEFAULT_RENDERER_TYPE);
46   }
47
48   public String JavaDoc getFamily() {
49     return COMPONENT_FAMILY;
50   }
51
52   public String JavaDoc getClientId(FacesContext context)
53   {
54       String JavaDoc clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
55       if (clientId == null)
56       {
57           clientId = super.getClientId(context);
58       }
59
60       return clientId;
61     }
62
63   public String JavaDoc getStyle() {
64     if (_style != null)
65       return _style;
66     ValueBinding vb = getValueBinding("style");
67     return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
68   }
69
70   public void setStyle(String JavaDoc style) {
71     this._style = style;
72   }
73
74   public String JavaDoc getStyleClass() {
75     if (_styleClass != null)
76       return _styleClass;
77     ValueBinding vb = getValueBinding("styleClass");
78     return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
79   }
80
81   public void setStyleClass(String JavaDoc styleClass) {
82     this._styleClass = styleClass;
83   }
84
85   public void restoreState(FacesContext context, Object JavaDoc state) {
86     Object JavaDoc values[] = (Object JavaDoc[]) state;
87     super.restoreState(context, values[0]);
88     _style = (String JavaDoc) values[1];
89     _styleClass = (String JavaDoc) values[2];
90   }
91
92   public Object JavaDoc saveState(FacesContext context) {
93     Object JavaDoc values[] = new Object JavaDoc[3];
94     values[0] = super.saveState(context);
95     values[1] = _style;
96     values[2] = _styleClass;
97     return values;
98   }
99 }
Popular Tags