View Javadoc

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.view.facelets.tag.jsf.html;
21  
22  import javax.faces.component.UIColumn;
23  import javax.faces.component.UIData;
24  import javax.faces.component.UIOutput;
25  import javax.faces.component.UIPanel;
26  import javax.faces.component.UIViewRoot;
27  import javax.faces.component.html.HtmlColumn;
28  import javax.faces.component.html.HtmlDataTable;
29  import javax.faces.component.html.HtmlOutputText;
30  import javax.faces.context.ResponseWriter;
31  
32  import org.apache.myfaces.renderkit.html.HtmlTableRenderer;
33  import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
34  import org.apache.myfaces.view.facelets.FaceletTestCase;
35  import org.apache.myfaces.view.facelets.bean.Example;
36  import org.apache.myfaces.view.facelets.util.FastWriter;
37  import org.junit.Test;
38  
39  public class DataTableTestCase extends FaceletTestCase
40  {
41  
42      @Override
43      protected void setupComponents() throws Exception
44      {
45          application.addComponent(UIViewRoot.COMPONENT_TYPE, UIViewRoot.class
46                  .getName());
47          application.addComponent(UIPanel.COMPONENT_TYPE,
48                  UIPanel.class.getName());        
49          application.addComponent(HtmlDataTable.COMPONENT_TYPE,
50                  HtmlDataTable.class.getName());
51          application.addComponent(UIColumn.COMPONENT_TYPE,
52                  UIColumn.class.getName());        
53          application.addComponent(HtmlColumn.COMPONENT_TYPE,
54                  HtmlColumn.class.getName());
55          application.addComponent(HtmlOutputText.COMPONENT_TYPE,
56                  HtmlOutputText.class.getName());
57      }
58  
59      @Override
60      protected void setupConvertersAndValidators() throws Exception
61      {
62      }
63  
64      @Override
65      protected void setupRenderers() throws Exception
66      {
67          renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
68                  "javax.faces.Text", new HtmlTextRenderer());
69          renderKit.addRenderer(UIData.COMPONENT_FAMILY,
70                  "javax.faces.Table", new HtmlTableRenderer());
71      }
72  
73      @Test
74      public void testDataTable() throws Exception
75      {
76          facesContext.getExternalContext().getRequestMap().put("company",
77                  Example.createCompany());
78  
79          UIViewRoot root = facesContext.getViewRoot();
80          vdl.buildView(facesContext, root, "dataTable.xml");
81  
82          FastWriter fw = new FastWriter();
83          ResponseWriter rw = facesContext.getResponseWriter();
84          rw = rw.cloneWithWriter(fw);
85          facesContext.setResponseWriter(rw);
86          root.encodeAll(facesContext);
87          //System.out.println(fw);
88      }
89  
90  }