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  package org.apache.myfaces.component.html.ext;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.view.facelets.ComponentConfig;
23  import javax.faces.view.facelets.ComponentHandler;
24  import javax.faces.view.facelets.FaceletContext;
25  import javax.faces.view.facelets.MetaRuleset;
26  
27  public class HtmlDataTableTagHandler extends ComponentHandler
28  {
29      
30      public HtmlDataTableTagHandler(ComponentConfig config)
31      {
32          super(config);
33      }
34      
35      @Override
36      public void onComponentCreated(FaceletContext ctx, UIComponent c,
37              UIComponent parent)
38      {
39           // Add a detailStampRow component, so detailStamp rendering will be delegated
40           // to a component that can be used in ajax.
41          UIComponent detailStampRow = ctx.getFacesContext().
42              getApplication().createComponent(ctx.getFacesContext(),
43                  HtmlDetailStampRow.COMPONENT_TYPE, HtmlDetailStampRow.DEFAULT_RENDERER_TYPE);
44          detailStampRow.setId("detailStampRow");
45          c.getFacets().put(AbstractHtmlDataTable.DETAIL_STAMP_ROW_FACET_NAME, detailStampRow);
46          
47          // Add a special component that is used to render a row on an ajax operation.
48          UIComponent row = ctx.getFacesContext().
49              getApplication().createComponent(ctx.getFacesContext(),
50                  HtmlTableRow.COMPONENT_TYPE, HtmlTableRow.DEFAULT_RENDERER_TYPE);
51          row.setId("row");
52          c.getFacets().put(AbstractHtmlDataTable.TABLE_ROW_FACET_NAME, row);
53      }
54  
55      @Override
56      public void onComponentPopulated(FaceletContext ctx, UIComponent c,
57              UIComponent parent)
58      {
59          //Check and remove detailStampRow component if there is no detailStamp
60          UIComponent detailStamp = c.getFacet(AbstractHtmlDataTable.DETAIL_STAMP_FACET_NAME);
61          if (detailStamp == null)
62          {
63              UIComponent detailStampRow = c.getFacet(AbstractHtmlDataTable.DETAIL_STAMP_ROW_FACET_NAME);
64              if (detailStampRow != null)
65              {
66                  c.getFacets().remove(AbstractHtmlDataTable.DETAIL_STAMP_ROW_FACET_NAME);
67              }
68          }
69          
70          HtmlDataTable dataTable = (HtmlDataTable) c;
71          if (!dataTable.isAjaxRowRender())
72          {
73              c.getFacets().remove(AbstractHtmlDataTable.TABLE_ROW_FACET_NAME);
74          }
75      }
76  
77      protected MetaRuleset createMetaRuleset(Class type)
78      {
79          return super.createMetaRuleset(type).alias("class", "styleClass");
80      }
81  }