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.view.facelets.pss.acid.component;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  import javax.faces.component.FacesComponent;
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.UIComponentBase;
26  import javax.faces.component.UIViewRoot;
27  import javax.faces.context.FacesContext;
28  import javax.faces.event.AbortProcessingException;
29  import javax.faces.event.PreRenderViewEvent;
30  import javax.faces.event.SystemEvent;
31  import javax.faces.event.SystemEventListener;
32  import javax.faces.view.ViewDeclarationLanguage;
33  
34  @FacesComponent(value = "com.myapp.UIAddSimpleIncludeVDL")
35  public class UIAddSimpleIncludeVDL extends UIComponentBase implements
36          SystemEventListener
37  {
38  
39      //
40      // Constructor
41      //
42  
43      public UIAddSimpleIncludeVDL()
44      {
45          setRendererType(null);
46  
47          FacesContext context = FacesContext.getCurrentInstance();
48          UIViewRoot root = context.getViewRoot();
49  
50          root.subscribeToViewEvent(PreRenderViewEvent.class, this);
51      }
52  
53      //
54      // Public methods
55      //
56  
57      @Override
58      public String getFamily()
59      {
60  
61          return "com.myapp";
62      }
63  
64      public boolean isListenerForSource(Object source)
65      {
66  
67          return (source instanceof UIViewRoot);
68      }
69  
70      public void processEvent(SystemEvent event) throws AbortProcessingException
71      {
72          FacesContext facesContext = FacesContext.getCurrentInstance();
73          if (!facesContext.isPostback())
74          {
75              ViewDeclarationLanguage vdl = facesContext.getApplication().
76                  getViewHandler().getViewDeclarationLanguage(
77                      facesContext, facesContext.getViewRoot().getViewId());
78  
79              Map<String, Object> attributes = new HashMap<String, Object>();
80              attributes.put("src", "/addSimpleIncludeVDL_1_1.xhtml");
81              UIComponent component = vdl.createComponent(facesContext, 
82                  "http://java.sun.com/jsf/facelets", 
83                  "include", attributes);
84              getChildren().add(component);
85              
86          }
87      }
88  }