KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > datalist > HtmlDataList


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.datalist;
17
18 import javax.faces.component.UIComponent;
19 import javax.faces.component.UIData;
20 import javax.faces.context.FacesContext;
21 import javax.faces.el.ValueBinding;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * @author Manfred Geiler (latest modification by $Author: mmarinschek $)
27  * @version $Revision: 1.7 $ $Date: 2005/03/24 10:06:22 $
28  */

29 public class HtmlDataList
30         extends UIData
31 {
32
33     public void processDecodes(FacesContext context)
34     {
35         int first = getFirst();
36         int rows = getRows();
37         int last;
38         if (rows == 0)
39         {
40             last = getRowCount();
41         }
42         else
43         {
44             last = first + rows;
45         }
46         for (int rowIndex = first; rowIndex < last; rowIndex++)
47         {
48             setRowIndex(rowIndex);
49             if (isRowAvailable())
50             {
51                 for (Iterator JavaDoc it = getChildren().iterator(); it.hasNext();)
52                 {
53                     UIComponent child = (UIComponent)it.next();
54                     if (!child.isRendered())
55                     {
56                         continue;
57                     }
58                     child.processDecodes(context);
59                 }
60             }
61         }
62
63         setRowIndex(-1);
64     }
65
66
67     public void setRowIndex(int rowIndex)
68     {
69         super.setRowIndex(rowIndex);
70         String JavaDoc rowIndexVar = getRowIndexVar();
71         String JavaDoc rowCountVar = getRowCountVar();
72         if (rowIndexVar != null || rowCountVar != null)
73         {
74             Map JavaDoc requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
75             if (rowIndex >= 0)
76             {
77                 //regular row index, update request scope variables
78
if (rowIndexVar != null)
79                 {
80                     requestMap.put(getRowIndexVar(), new Integer JavaDoc(rowIndex));
81                 }
82                 if (rowCountVar != null)
83                 {
84                     requestMap.put(getRowCountVar(), new Integer JavaDoc(getRowCount()));
85                 }
86             }
87             else
88             {
89                 //rowIndex == -1 means end of loop --> remove request scope variables
90
if (rowIndexVar != null)
91                 {
92                     requestMap.remove(getRowIndexVar());
93                 }
94                 if (rowCountVar != null)
95                 {
96                     requestMap.remove(getRowCountVar());
97                 }
98             }
99         }
100     }
101
102
103     //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
104

105     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlDataList";
106     private static final String JavaDoc DEFAULT_RENDERER_TYPE = "org.apache.myfaces.List";
107
108     private String JavaDoc _layout = null;
109     private String JavaDoc _rowIndexVar = null;
110     private String JavaDoc _rowCountVar = null;
111
112     public HtmlDataList()
113     {
114         setRendererType(DEFAULT_RENDERER_TYPE);
115     }
116
117
118     public void setLayout(String JavaDoc layout)
119     {
120         _layout = layout;
121     }
122
123     public String JavaDoc getLayout()
124     {
125         if (_layout != null) return _layout;
126         ValueBinding vb = getValueBinding("layout");
127         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
128     }
129
130     public void setRowIndexVar(String JavaDoc rowIndexVar)
131     {
132         _rowIndexVar = rowIndexVar;
133     }
134
135     public String JavaDoc getRowIndexVar()
136     {
137         if (_rowIndexVar != null) return _rowIndexVar;
138         ValueBinding vb = getValueBinding("rowIndexVar");
139         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
140     }
141
142     public void setRowCountVar(String JavaDoc rowCountVar)
143     {
144         _rowCountVar = rowCountVar;
145     }
146
147     public String JavaDoc getRowCountVar()
148     {
149         if (_rowCountVar != null) return _rowCountVar;
150         ValueBinding vb = getValueBinding("rowCountVar");
151         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
152     }
153
154
155     public Object JavaDoc saveState(FacesContext context)
156     {
157         Object JavaDoc values[] = new Object JavaDoc[4];
158         values[0] = super.saveState(context);
159         values[1] = _layout;
160         values[2] = _rowIndexVar;
161         values[3] = _rowCountVar;
162         return ((Object JavaDoc) (values));
163     }
164
165     public void restoreState(FacesContext context, Object JavaDoc state)
166     {
167         Object JavaDoc values[] = (Object JavaDoc[])state;
168         super.restoreState(context, values[0]);
169         _layout = (String JavaDoc)values[1];
170         _rowIndexVar = (String JavaDoc)values[2];
171         _rowCountVar = (String JavaDoc)values[3];
172     }
173     //------------------ GENERATED CODE END ---------------------------------------
174
}
175
Popular Tags