View Javadoc

1   /*
2    * $Id: ValidationParameterHandler.java,v 1.2 2007/09/13 08:38:13 oeuillot Exp $
3    */
4   package org.rcfaces.core.internal.facelets;
5   
6   import javax.faces.component.UIComponent;
7   
8   import org.rcfaces.core.internal.manager.IValidationParameters;
9   
10  import com.sun.facelets.FaceletContext;
11  import com.sun.facelets.tag.TagAttribute;
12  import com.sun.facelets.tag.TagConfig;
13  import com.sun.facelets.tag.TagException;
14  import com.sun.facelets.tag.TagHandler;
15  import com.sun.facelets.tag.jsf.ComponentSupport;
16  
17  /**
18   * 
19   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
20   * @version $Revision: 1.2 $ $Date: 2007/09/13 08:38:13 $
21   */
22  public class ValidationParameterHandler extends TagHandler {
23      private static final String REVISION = "$Revision: 1.2 $";
24  
25      private final TagAttribute name;
26  
27      private final TagAttribute value;
28  
29      private final TagAttribute clientSide;
30  
31      public ValidationParameterHandler(TagConfig config) {
32          super(config);
33          this.name = this.getRequiredAttribute("name");
34          this.value = this.getRequiredAttribute("value");
35          this.clientSide = this.getAttribute("clientSide");
36      }
37  
38      public void apply(FaceletContext ctx, UIComponent parent) {
39          if (parent == null) {
40              throw new TagException(this.tag, "Parent UIComponent was null");
41          }
42  
43          // only process if the parent is new to the tree
44          if (ComponentSupport.isNew(parent) == false) {
45              return;
46          }
47  
48          boolean clientSide = this.clientSide.getBoolean(ctx);
49  
50          IValidationParameters clientDataCapability = (IValidationParameters) parent;
51  
52          String nameValue = name.getValue(ctx);
53          if (value.isLiteral()) {
54              clientDataCapability.setValidationParameter(nameValue, value
55                      .getValue(), clientSide);
56              return;
57          }
58  
59          clientDataCapability.setValidationParameter(nameValue, value
60                  .getValueExpression(ctx, String.class), clientSide);
61      }
62  
63  }