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.extensions.validator.trinidad;
20  
21  import org.apache.myfaces.trinidad.validator.ClientValidator;
22  import org.apache.myfaces.extensions.validator.internal.UsageInformation;
23  import org.apache.myfaces.extensions.validator.internal.UsageCategory;
24  
25  import javax.faces.validator.Validator;
26  import javax.faces.validator.ValidatorException;
27  import javax.faces.context.FacesContext;
28  import javax.faces.component.UIComponent;
29  import java.io.Serializable;
30  import java.util.Collection;
31  
32  /**
33   * in case of client-side validation a trinidad client validator is added to the component based on the meta-data.
34   * at the postback: the extval validation strategy gets called and after that the added validator.
35   * this wrapper prevents such a server-side double validation.
36   * it just delegates the client-side functionality.
37   *
38   * @since 1.x.1
39   */
40  @UsageInformation(UsageCategory.REUSE)
41  public class ExtValTrinidadClientValidatorWrapper implements Validator, ClientValidator, Serializable
42  {
43      private transient ClientValidator wrapped;
44      private static final long serialVersionUID = 1414547841700621410L;
45  
46      public ExtValTrinidadClientValidatorWrapper(ClientValidator clientValidator)
47      {
48          this.wrapped = clientValidator;
49      }
50  
51      public void validate(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException
52      {
53          //don't validate - the extval validation strategy will do that
54      }
55  
56      public String getClientLibrarySource(FacesContext facesContext)
57      {
58          return wrapped.getClientLibrarySource(facesContext);
59      }
60  
61      public Collection<String> getClientImportNames()
62      {
63          return wrapped.getClientImportNames();
64      }
65  
66      public String getClientScript(FacesContext facesContext, UIComponent uiComponent)
67      {
68          return wrapped.getClientScript(facesContext, uiComponent);
69      }
70  
71      public String getClientValidation(FacesContext facesContext, UIComponent uiComponent)
72      {
73          return wrapped.getClientValidation(facesContext, uiComponent);
74      }
75  }