View Javadoc
1   package org.andromda.cartridges.jsf.taglib;
2   
3   import javax.faces.application.Application;
4   import javax.faces.component.UIComponent;
5   import javax.faces.context.FacesContext;
6   import javax.faces.el.ValueBinding;
7   import javax.faces.webapp.UIComponentTag;
8   
9   import org.andromda.cartridges.jsf.component.JSFValidatorComponent;
10  
11  
12  /**
13   * The tag class for the <code>s:validatorScript</code> tag.
14   */
15  public class JSFValidatorTag
16      extends UIComponentTag
17  {
18      /**
19       * Whether or not client side validation should be enabled
20       */
21      private String client;
22  
23      /**
24       * Sets whether or not client side validation shall be enabled.
25       *
26       * @param clientIn a true/false string.
27       */
28      public void setClient(final String clientIn)
29      {
30          this.client = clientIn;
31      }
32  
33      /**
34       * Sets properties for the component.
35       *
36       * @param component The component whose properties we're setting
37       */
38      @Override
39      public void setProperties(final UIComponent component)
40      {
41          super.setProperties(component);
42  
43          final String attributeName = JSFValidatorComponent.CLIENT;
44          final String attributeValue = this.client;
45          if (attributeValue != null)
46          {
47              if (UIComponentTag.isValueReference(this.client))
48              {
49                  final FacesContext context = FacesContext.getCurrentInstance();
50                  final Application application = context.getApplication();
51                  final ValueBinding binding = application.createValueBinding(attributeValue);
52                  component.setValueBinding(
53                      attributeName,
54                      binding);
55              }
56              else
57              {
58                  component.getAttributes().put(
59                      attributeName,
60                      attributeValue);
61              }
62          }
63          final String validatorId = this.getId();
64          if (validatorId != null)
65          {
66              component.setId(validatorId);
67          }
68      }
69  
70      /**
71       * Sets the <code>client</code> property to null.
72       *
73       * @see javax.servlet.jsp.tagext.Tag#release()
74       */
75      @Override
76      public void release()
77      {
78          super.release();
79          this.client = null;
80      }
81  
82      /**
83       * Returns the renderer type, which is null.
84       */
85      @Override
86      public String getRendererType()
87      {
88          return null;
89      }
90  
91      /**
92       * The component type.
93       */
94      private static final String COMPONENT_TYPE = JSFValidatorComponent.class.getName();
95  
96      /**
97       * Returns the component type, which is
98       * <code>org.andromda.cartridges.jsf.component.JSFValidatorScript</code>.
99       */
100     @Override
101     public String getComponentType()
102     {
103         return COMPONENT_TYPE;
104     }
105 }