KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > buffer > Buffer


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.buffer;
17
18 import javax.faces.component.UIComponentBase;
19 import javax.faces.context.FacesContext;
20 import javax.faces.el.ValueBinding;
21
22 /**
23  * @author Sylvain Vieujot (latest modification by $Author: svieujot $)
24  * @version $Revision: 1.1 $ $Date: 2005/01/04 15:41:06 $
25  * $Log: Buffer.java,v $
26  * Revision 1.1 2005/01/04 15:41:06 svieujot
27  * new x:buffer component.
28  *
29  */

30 public class Buffer extends UIComponentBase{
31
32     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.Buffer";
33     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Data";
34     private static final String JavaDoc DEFAULT_RENDERER_TYPE = BufferRenderer.RENDERER_TYPE;
35
36     private String JavaDoc _intoExpression = null;
37
38     public Buffer(){
39         setRendererType(DEFAULT_RENDERER_TYPE);
40     }
41
42     public String JavaDoc getFamily(){
43         return COMPONENT_FAMILY;
44     }
45
46     public void setInto(String JavaDoc intoExpression){
47         _intoExpression = intoExpression;
48     }
49
50     public Object JavaDoc saveState(FacesContext context){
51         Object JavaDoc values[] = new Object JavaDoc[2];
52         values[0] = super.saveState(context);
53         values[1] = _intoExpression;
54         return values;
55     }
56
57     public void restoreState(FacesContext context, Object JavaDoc state){
58         Object JavaDoc values[] = (Object JavaDoc[]) state;
59         super.restoreState(context, values[0]);
60         _intoExpression = (String JavaDoc) values[1];
61     }
62     
63     void fill(Object JavaDoc content, FacesContext facesContext){
64         ValueBinding intoVB;
65         
66         if (_intoExpression == null) {
67             intoVB = getValueBinding("into");
68             _intoExpression = intoVB.getExpressionString();
69         } else {
70             intoVB = facesContext.getApplication().createValueBinding( _intoExpression );
71         }
72
73         intoVB.setValue(facesContext, content.toString());
74     }
75 }
Popular Tags