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.custom.validatebeanbehavior;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponentBase;
24  import javax.faces.context.FacesContext;
25  import javax.faces.context.ResponseWriter;
26  
27  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
28  
29  /**
30   * Wrapper component for UIMessages, to make sure there always is a messages placeholder in the DOM.
31   *
32   * @author Jan-Kees van Andel
33   */
34  @JSFComponent
35  public class UIMessagesWrapper extends UIComponentBase {
36  
37      /**
38       * The component type for this component.
39       */
40      public static final String COMPONENT_TYPE = "org.apache.myfaces.custom.validatebeanbehavior.UIMessagesWrapper";
41  
42      /**
43       * The component family for this component.
44       */
45      public static final String COMPONENT_FAMILY = "org.apache.myfaces.custom.MessagesWrapper";
46  
47      @Override
48      public String getFamily() {
49          return COMPONENT_FAMILY;
50      }
51  
52      @Override
53      public void encodeBegin(FacesContext context) throws IOException {
54          super.encodeBegin(context);
55  
56          final ResponseWriter writer = context.getResponseWriter();
57          writer.write("<div id=\"");
58          writer.write(getClientId());
59          writer.write("\">");
60      }
61  
62      @Override
63      public void encodeEnd(FacesContext context) throws IOException {
64          final ResponseWriter writer = context.getResponseWriter();
65          writer.write("</div>");
66  
67          super.encodeEnd(context);
68      }
69  }