click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r928730 - in /click/trunk/click/extras/src/org/apache/click/extras/control: CheckList.java CreditCardField.java EmailField.java
Date Mon, 29 Mar 2010 11:49:39 GMT
Author: sabob
Date: Mon Mar 29 11:49:39 2010
New Revision: 928730

URL: http://svn.apache.org/viewvc?rev=928730&view=rev
Log:
migrated html imports to head elements

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java
    click/trunk/click/extras/src/org/apache/click/extras/control/CreditCardField.java
    click/trunk/click/extras/src/org/apache/click/extras/control/EmailField.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java?rev=928730&r1=928729&r2=928730&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java Mon Mar 29
11:49:39 2010
@@ -30,11 +30,14 @@ import java.util.Map;
 import org.apache.click.Context;
 import org.apache.click.control.Field;
 import org.apache.click.control.Option;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.JsImport;
+import org.apache.click.element.JsScript;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
 import org.apache.click.util.PropertyUtils;
-
 import org.apache.commons.lang.StringEscapeUtils;
+
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -115,24 +118,10 @@ import org.apache.commons.lang.StringUti
  */
 public class CheckList extends Field {
 
-    // -------------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     private static final long serialVersionUID = 1L;
 
-    /** The CheckList import statements. */
-    public static final String HTML_IMPORTS =
-        "<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}/click/checklist/checklist{1}.css\"/>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/checklist/checklist{1}.js\"></script>\n";
-
-    /** The JavaScript sorting HTML import statements. */
-    public static final String JS_SORT_HTML_IMPORTS =
-          "<script type=\"text/javascript\" src=\"{0}/click/prototype/prototype{1}.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/prototype/builder{1}.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/prototype/effects{1}.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/prototype/dragdrop{1}.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/prototype/controls{1}.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/prototype/slider{1}.js\"></script>\n";
-
     /** The style class which is always set on this element (checkList). */
     protected static final String STYLE_CLASS = "checkList";
 
@@ -156,7 +145,7 @@ public class CheckList extends Field {
         + "   '}'\n"
         + "'}'\n";
 
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /** The height if null not scrollable. */
     protected String height;
@@ -176,7 +165,7 @@ public class CheckList extends Field {
     /** The selected values. */
     protected List selectedValues;
 
-    // ----------------------------------------------------------- Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Create a CheckList field with the given name.
@@ -228,13 +217,14 @@ public class CheckList extends Field {
     public CheckList() {
     }
 
-    // ------------------------------------------------------ Public Attributes
+    // Public Attributes ------------------------------------------------------
 
     /**
      * @see org.apache.click.control.AbstractControl#getTag()
      *
      * @return this controls html tag
      */
+    @Override
     public String getTag() {
         return "div";
     }
@@ -320,9 +310,8 @@ public class CheckList extends Field {
             String msg = "options parameter cannot be null";
             throw new IllegalArgumentException(msg);
         }
-        for (int i = 0; i < options.length; i++) {
-            String value = options[i];
-            getOptionList().add(new Option(value, value));
+        for (String option : options) {
+            getOptionList().add(new Option(option, option));
         }
     }
 
@@ -423,6 +412,7 @@ public class CheckList extends Field {
      *
      * @return the Field focus JavaScript
      */
+    @Override
     public String getFocusJavaScript() {
         HtmlStringBuffer buffer = new HtmlStringBuffer();
 
@@ -497,46 +487,72 @@ public class CheckList extends Field {
      *
      * @return the HTML head import statements for the control
      */
-    public String getHtmlImports() {
-        Context context = getContext();
-        HtmlStringBuffer buffer = new HtmlStringBuffer(400);
-
-        buffer.append(ClickUtils.createHtmlImport(HTML_IMPORTS, context));
-
-        if (isSortable()) {
-            buffer.append(ClickUtils.createHtmlImport(JS_SORT_HTML_IMPORTS,
-                context));
-
-            // Script to execute
-            HtmlStringBuffer script = new HtmlStringBuffer(50);
-            script.append("Sortable.create('");
-            script.append(StringEscapeUtils.escapeJavaScript(getId()));
-            script.append("_ul'");
-
-            if (getHeight() != null) {
-                script.append(", { scroll : '");
-                script.append(StringEscapeUtils.escapeJavaScript(getId()));
-                script.append("'}");
+    @Override
+    public List getHeadElements() {
+        if (headElements == null) {
+            Context context = getContext();
+            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+
+            headElements = super.getHeadElements();
+
+            headElements.add(new CssImport("/click/checklist/checklist.css",
+                versionIndicator));
+            headElements.add(new JsImport("/click/checklist/checklist.js",
+                versionIndicator));
+
+            if (isSortable()) {
+                headElements.add(new JsImport("/click/prototype/prototype.js",
+                    versionIndicator));
+                headElements.add(new JsImport("/click/prototype/builder.js",
+                    versionIndicator));
+                headElements.add(new JsImport("/click/prototype/effects.js",
+                    versionIndicator));
+                headElements.add(new JsImport("/click/prototype/dragdrop.js",
+                    versionIndicator));
+                headElements.add(new JsImport("/click/prototype/controls.js",
+                    versionIndicator));
+                headElements.add(new JsImport("/click/prototype/slider.js",
+                    versionIndicator));
             }
-            script.append(");");
+        }
 
-            buffer.append("<script type=\"text/javascript\">");
-            if (getHeight() != null) {
-                buffer.append("Position.includeScrollOffset = true;");
+        // Note, the addLoadEvent script is recreated and checked if it
+        // is contained in the headElement.
+        String checkListId = getId();
+        JsScript script = new JsScript();
+        script.setId(checkListId + "_js_setup");
+
+        if (!headElements.contains(script)) {
+            script.setExecuteOnDomReady(true);
+
+            HtmlStringBuffer buffer = new HtmlStringBuffer(50);
+
+            if (isSortable()) {
+                if (getHeight() != null) {
+                    buffer.append("Position.includeScrollOffset = true;\n");
+                }
+                // Script to execute
+                buffer.append("Sortable.create('");
+                buffer.append(StringEscapeUtils.escapeJavaScript(checkListId));
+                buffer.append("_ul'");
+
+                if (getHeight() != null) {
+                    buffer.append(", { scroll : '");
+                    buffer.append(StringEscapeUtils.escapeJavaScript(checkListId));
+                    buffer.append("'}");
+                }
+                buffer.append(");");
+
+            } else {
+                buffer.append("initChecklist('");
+                buffer.append(StringEscapeUtils.escapeJavaScript(checkListId));
+                buffer.append("_ul');\n");
             }
-
-            buffer.append("addLoadEvent(function() { ");
-            buffer.append(script);
-            buffer.append(" });</script>\n");
-
-        } else {
-            buffer.append("<script type=\"text/javascript\">");
-            buffer.append("addLoadEvent(function() { initChecklist('");
-            buffer.append(StringEscapeUtils.escapeJavaScript(getId()));
-            buffer.append("_ul'); });</script>\n");
+            script.setContent(buffer.toString());
+            headElements.add(script);
         }
 
-        return buffer.toString();
+        return headElements;
     }
 
     /**
@@ -671,6 +687,7 @@ public class CheckList extends Field {
      *
      * @return selected values as a List of Strings
      */
+    @Override
     public Object getValueObject() {
         return getSelectedValues();
     }
@@ -687,6 +704,7 @@ public class CheckList extends Field {
      *
      * @param object a List of Strings
      */
+    @Override
     public void setValueObject(Object object) {
         if (object instanceof List) {
             setSelectedValues((List) object);
@@ -698,6 +716,7 @@ public class CheckList extends Field {
      *
      * @return the field JavaScript client side validation function
      */
+    @Override
     public String getValidationJavaScript() {
         Object[] args = new Object[4];
         args[0] = getId();
@@ -708,12 +727,13 @@ public class CheckList extends Field {
         return MessageFormat.format(VALIDATE_CHECKLIST_FUNCTION, args);
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * Bind the request submission, setting the {@link #selectedValues} and
      * sort order if the checkList is sortable.
      */
+    @Override
     public void bindRequestValue() {
 
         Context context = getContext();
@@ -785,6 +805,7 @@ public class CheckList extends Field {
      *
      * @return the estimated rendered control size in characters
      */
+    @Override
     public int getControlSizeEst() {
         int bufferSize = 50;
         if (!getOptionList().isEmpty()) {
@@ -800,6 +821,7 @@ public class CheckList extends Field {
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         final boolean sortable = isSortable();
 
@@ -923,6 +945,7 @@ public class CheckList extends Field {
      * </ul>
      * </blockquote>
      */
+    @Override
     public void validate() {
         if (isRequired()) {
             if (getSelectedValues().isEmpty()) {

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/CreditCardField.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/CreditCardField.java?rev=928730&r1=928729&r2=928730&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/CreditCardField.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/CreditCardField.java Mon
Mar 29 11:49:39 2010
@@ -21,10 +21,12 @@ package org.apache.click.extras.control;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.click.Context;
 
 import org.apache.click.control.Option;
 import org.apache.click.control.Select;
 import org.apache.click.control.TextField;
+import org.apache.click.element.JsImport;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
 
@@ -123,7 +125,7 @@ import org.apache.click.util.HtmlStringB
  */
 public class CreditCardField extends TextField {
 
-    // -------------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     private static final long serialVersionUID = 1L;
 
@@ -156,7 +158,7 @@ public class CreditCardField extends Tex
         CARD_OPTIONS.add(new Option(DISCOVER, "Discover"));
     }
 
-    // -------------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     /**
      * The field validation JavaScript function template.
@@ -183,11 +185,7 @@ public class CreditCardField extends Tex
         + "   '}'\n"
         + "'}'\n";
 
-    /** The CreditCardField imports statement. */
-    public static final String HTML_IMPORTS =
-        "<script type=\"text/javascript\" src=\"{0}/click/extras-control{1}.js\"></script>\n";
-
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /**
      * The type of credit card: <tt>["VISA" | "MASTER" | "AMEX" | "DINERS" |
@@ -198,7 +196,7 @@ public class CreditCardField extends Tex
     /** The card type Select. */
     protected Select cardTypeSelect = new Select(SELECT_NAME);
 
-    // ----------------------------------------------------------- Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Construct the credit card field with the given name.
@@ -265,7 +263,7 @@ public class CreditCardField extends Tex
         cardTypeSelect.addAll(CARD_OPTIONS);
     }
 
-    // ------------------------------------------------------ Public Attributes
+    // Public Attributes ------------------------------------------------------
 
     /**
      * Return the selected Credit Card type: &nbsp;
@@ -303,16 +301,26 @@ public class CreditCardField extends Tex
      *
      * @return the HTML head import statements for the control
      */
-    public String getHtmlImports() {
-        return ClickUtils.createHtmlImport(HTML_IMPORTS, getContext());
+    @Override
+    public List getHeadElements() {
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+
+            Context context = getContext();
+            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+
+            headElements.add(new JsImport("/click/extras-control.js", versionIndicator));
+        }
+        return headElements;
     }
 
-    // -------------------------------------------------------- Public Methods
+    // Public Methods --------------------------------------------------------
 
     /**
      * Bind the request submission, setting the value property and
      * {@link #cardType} property if defined in the request.
      */
+    @Override
     public void bindRequestValue() {
         super.bindRequestValue();
 
@@ -324,6 +332,7 @@ public class CreditCardField extends Tex
      *
      * @return the estimated rendered control size in characters
      */
+    @Override
     public int getControlSizeEst() {
         return 400;
     }
@@ -335,6 +344,7 @@ public class CreditCardField extends Tex
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         // Render card number field
         super.render(buffer);
@@ -354,6 +364,7 @@ public class CreditCardField extends Tex
      *
      * @return the field JavaScript client side validation function
      */
+    @Override
     public String getValidationJavaScript() {
         Object[] args = new Object[9];
         args[0] = getId();
@@ -381,7 +392,7 @@ public class CreditCardField extends Tex
      * <ul>
      *   <li>/click-control.properties
      *     <ul>
-     *       <li>field-maxlenght-error</li>
+     *       <li>field-maxlength-error</li>
      *       <li>field-minlength-error</li>
      *       <li>field-required-error</li>
      *     </ul>
@@ -394,6 +405,7 @@ public class CreditCardField extends Tex
      * </ul>
      * </blockquote>
      */
+    @Override
     public void validate() {
         super.validate();
 

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/EmailField.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/EmailField.java?rev=928730&r1=928729&r2=928730&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/EmailField.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/EmailField.java Mon Mar 29
11:49:39 2010
@@ -19,8 +19,11 @@
 package org.apache.click.extras.control;
 
 import java.text.MessageFormat;
+import java.util.List;
+import org.apache.click.Context;
 
 import org.apache.click.control.TextField;
+import org.apache.click.element.JsImport;
 import org.apache.click.util.ClickUtils;
 
 /**
@@ -59,7 +62,7 @@ public class EmailField extends TextFiel
 
     private static final long serialVersionUID = 1L;
 
-    // -------------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     /**
      * The field validation JavaScript function template.
@@ -85,11 +88,7 @@ public class EmailField extends TextFiel
         + "   '}'\n"
         + "'}'\n";
 
-    /** The EmailField.js imports statement. */
-    public static final String HTML_IMPORTS =
-        "<script type=\"text/javascript\" src=\"{0}/click/extras-control{1}.js\"></script>\n";
-
-    // ----------------------------------------------------------- Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Construct an Email Field with the given name. The default email field
@@ -175,7 +174,7 @@ public class EmailField extends TextFiel
         setSize(30);
     }
 
-    // ------------------------------------------------------ Public Attributes
+    // Public Attributes ------------------------------------------------------
 
     /**
      * Return the EmailField HTML head imports statements for the following
@@ -189,8 +188,17 @@ public class EmailField extends TextFiel
      *
      * @return the HTML head import statements for the control
      */
-    public String getHtmlImports() {
-        return ClickUtils.createHtmlImport(HTML_IMPORTS, getContext());
+    @Override
+    public List getHeadElements() {
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+
+            Context context = getContext();
+            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+
+            headElements.add(new JsImport("/click/extras-control.js", versionIndicator));
+        }
+        return headElements;
     }
 
     /**
@@ -202,6 +210,7 @@ public class EmailField extends TextFiel
      *
      * @return the field JavaScript client side validation function
      */
+    @Override
     public String getValidationJavaScript() {
         Object[] args = new Object[8];
         args[0] = getId();
@@ -218,7 +227,7 @@ public class EmailField extends TextFiel
         return MessageFormat.format(VALIDATE_EMAILFIELD_FUNCTION, args);
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * Process the EmailField request submission.
@@ -242,6 +251,7 @@ public class EmailField extends TextFiel
      * </ul>
      * </blockquote>
      */
+    @Override
     public void validate() {
         setError(null);
 



Mime
View raw message