View Javadoc

1   /*
2    * $Id: ValidationParameterTag.java,v 1.17 2011/06/16 09:29:41 jbmeslin Exp $
3    * 
4    */
5   package org.rcfaces.core.internal.taglib;
6   
7   import javax.el.ValueExpression;
8   import javax.faces.component.UIComponent;
9   import javax.faces.webapp.UIComponentClassicTagBase;
10  import javax.servlet.jsp.JspException;
11  import javax.servlet.jsp.tagext.Tag;
12  import javax.servlet.jsp.tagext.TagSupport;
13  
14  import org.rcfaces.core.internal.manager.IValidationParameters;
15  
16  /**
17   * 
18   * @author Olivier Oeuillot (latest modification by $Author: jbmeslin $)
19   * @version $Revision: 1.17 $ $Date: 2011/06/16 09:29:41 $
20   */
21  public class ValidationParameterTag extends TagSupport implements Tag {
22      private static final String REVISION = "$Revision: 1.17 $";
23  
24      private static final long serialVersionUID = -1595891873980056092L;
25  
26      private static final boolean CLIENT_SIDE_DEFAULT_VALUE = true;
27  
28      private String name;
29  
30      private ValueExpression value;
31  
32      private boolean clientSide = CLIENT_SIDE_DEFAULT_VALUE;
33  
34      public final void setName(String name) {
35          this.name = name;
36      }
37  
38      public final void setValue(ValueExpression value) {
39          this.value = value;
40      }
41  
42      public boolean isClientSide() {
43          return clientSide;
44      }
45  
46      public void setClientSide(boolean clientSide) {
47          this.clientSide = clientSide;
48      }
49  
50      public int doStartTag() throws JspException {
51  
52          // Locate our parent UIComponentTag
53          UIComponentClassicTagBase tag = UIComponentClassicTagBase
54                  .getParentUIComponentClassicTagBase(pageContext);
55          if (tag == null) { // PENDING - i18n
56              throw new JspException("Not nested in a UIComponentTag");
57          }
58  
59          // Nothing to do unless this tag created a component
60          if (!tag.getCreated()) {
61              return (SKIP_BODY);
62          }
63  
64          // FacesContext facesContext = FacesContext.getCurrentInstance();
65          // Application application = facesContext.getApplication();
66  
67          UIComponent component = tag.getComponentInstance();
68          if ((component instanceof IValidationParameters) == false) {
69              throw new JspException(
70                      "Component does not implement IValidationParameters");
71  
72          }
73  
74          IValidationParameters validatonParameterManager = (IValidationParameters) component;
75  
76          if (value.isLiteralText() == false) {
77              validatonParameterManager.setValidationParameter(name, value,
78                      clientSide);
79  
80          } else {
81              validatonParameterManager.setValidationParameter(name, value,
82                      clientSide);
83          }
84  
85          return (SKIP_BODY);
86      }
87  
88      public void release() {
89          name = null;
90          value = null;
91          clientSide = CLIENT_SIDE_DEFAULT_VALUE;
92  
93          super.release();
94      }
95  
96  }