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.compiler;
20  
21  import java.io.IOException;
22  
23  import javax.el.ELException;
24  import javax.faces.FacesException;
25  import javax.faces.component.UIComponent;
26  import javax.faces.component.UniqueIdVendor;
27  import javax.faces.view.facelets.FaceletContext;
28  import javax.faces.view.facelets.FaceletException;
29  
30  import org.apache.myfaces.view.facelets.AbstractFaceletContext;
31  import org.apache.myfaces.view.facelets.FaceletCompositionContext;
32  import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
33  
34  final class UILiteralTextHandler extends AbstractUIHandler
35  {
36  
37      protected final String txtString;
38  
39      public UILiteralTextHandler(String txtString)
40      {
41          this.txtString = txtString;
42      }
43  
44      public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
45              ELException
46      {
47          if (parent != null)
48          {
49              UIComponent c = new UILiteralText(this.txtString);
50              //c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
51              //AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
52              UniqueIdVendor uniqueIdVendor = FaceletCompositionContext.getCurrentInstance(ctx).getUniqueIdVendorFromStack();
53              if (uniqueIdVendor == null)
54              {
55                  uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
56              }
57              if (uniqueIdVendor != null)
58              {
59                  // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
60                  // and call createUniqueId()
61                  String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
62                  c.setId(uid);
63              }
64              this.addComponent(ctx, parent, c);
65          }
66      }
67  
68      public String getText()
69      {
70          return this.txtString;
71      }
72  
73      public String getText(FaceletContext ctx)
74      {
75          return this.txtString;
76      }
77  }