Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 98186 invoked from network); 27 May 2009 16:18:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 May 2009 16:18:57 -0000 Received: (qmail 14913 invoked by uid 500); 27 May 2009 16:19:10 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 14900 invoked by uid 500); 27 May 2009 16:19:10 -0000 Mailing-List: contact click-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@incubator.apache.org Delivered-To: mailing list click-commits@incubator.apache.org Received: (qmail 14888 invoked by uid 99); 27 May 2009 16:19:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 May 2009 16:19:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 May 2009 16:19:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 109012388863; Wed, 27 May 2009 16:18:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r779229 - /incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java Date: Wed, 27 May 2009 16:18:47 -0000 To: click-commits@incubator.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090527161848.109012388863@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Wed May 27 16:18:47 2009 New Revision: 779229 URL: http://svn.apache.org/viewvc?rev=779229&view=rev Log: improved Form to track the insert offset of the two HiddenFields which Form adds. CLK-447 Modified: incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java Modified: incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java?rev=779229&r1=779228&r2=779229&view=diff ============================================================================== --- incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java (original) +++ incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java Wed May 27 16:18:47 2009 @@ -626,6 +626,12 @@ /** The label <td> "style" attribute value. */ protected String labelStyle; + /** + * Track the index offset when adding Controls. This ensures HiddenFields + * added by Form does not interfere with Controls added by users. + */ + private int insertIndexOffset; + // ----------------------------------------------------------- Constructors /** @@ -687,7 +693,10 @@ */ public Control insert(Control control, int index) { - super.insert(control, index); + // Adjust index for hidden fields added by Form. CLK-447 + int realIndex = Math.min(index, getControls().size() - insertIndexOffset); + + super.insert(control, realIndex); if (control instanceof Field) { Field field = (Field) control; @@ -697,7 +706,9 @@ getButtonList().add(field); } else { - getFieldList().add(field); + // Adjust index for hidden fields added by Form + realIndex = Math.min(index, getFieldList().size() - insertIndexOffset); + getFieldList().add(realIndex, field); } field.setForm(this); @@ -1151,18 +1162,9 @@ HiddenField nameField = (HiddenField) getField(FORM_NAME); if (nameField == null) { - - nameField = new HiddenField(FORM_NAME, String.class) { - - // Override setName to ensure name cannot be changed once set - public void setName(String name) { - if (this.name != null) { - return; - } - super.setName(name); - } - }; + nameField = new ImmutableNameHiddenField(FORM_NAME, String.class); add(nameField); + insertIndexOffset++; } nameField.setValue(name); } @@ -2154,18 +2156,9 @@ // CLK-267: check against adding a duplicate field HiddenField field = (HiddenField) getField(submitTokenName); if (field == null) { - - field = new HiddenField(submitTokenName, Long.class) { - - // Override setName to ensure name cannot be changed once set - public void setName(String name) { - if (this.name != null) { - return; - } - super.setName(name); - } - }; + field = new ImmutableNameHiddenField(submitTokenName, Long.class); add(field); + insertIndexOffset++; } // Save state info to form and session @@ -2720,4 +2713,34 @@ return ((Field) control).isHidden(); } } + + // ---------------------------------------------------------- Inner Classes + + /** + * Provides a HiddenField which name cannot be changed, once it is set. + */ + private class ImmutableNameHiddenField extends HiddenField { + + /** + * Create a field with the given name and value. + * + * @param name the field name + * @param valueClass the Class of the value Object + */ + public ImmutableNameHiddenField(String name, Class valueClass) { + super(name, valueClass); + } + + /** + * Set the field name. The field name cannot be changed once it is set. + * + * @param name the name of the field + */ + public void setName(String name) { + if (this.name != null) { + return; + } + super.setName(name); + } + } }