You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by kn...@apache.org on 2007/03/07 21:03:09 UTC

svn commit: r515729 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java

Author: knopp
Date: Wed Mar  7 12:03:08 2007
New Revision: 515729

URL: http://svn.apache.org/viewvc?view=rev&rev=515729
Log:
Nested forms support

Modified:
    incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java

Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java?view=diff&rev=515729&r1=515728&r2=515729
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java Wed Mar  7 12:03:08 2007
@@ -342,8 +342,16 @@
 				}
 				else
 				{
+					// this is the root form
+					Form formToProcess = this;
+
+					// find out whether it was a nested form that was submitted
+					if (submittingButton != null)
+					{
+						formToProcess = submittingButton.getForm();
+					}
 					// process the form for this request
-					if (process())
+					if (formToProcess.process())
 					{
 						// let clients handle further processing
 						delegateSubmit(submittingButton);
@@ -796,42 +804,56 @@
 	 */
 	protected void onComponentTag(final ComponentTag tag)
 	{
-		checkComponentTag(tag, "form");
 		super.onComponentTag(tag);
-
-		// If the javascriptid is already generated then use that on even it was
-		// before the first render. Bbecause there could be a component which
-		// already uses it to submit the forum. This should be fixed when we
-		// pre parse the markup so that we know the id is at front.
-		if (!Strings.isEmpty(javascriptId))
+		if (isRootForm())
 		{
-			tag.put("id", javascriptId);
-		}
-		else
-		{
-			javascriptId = (String)tag.getAttributes().get("id");
-			if (Strings.isEmpty(javascriptId))
+			checkComponentTag(tag, "form");
+
+			// If the javascriptid is already generated then use that on even it
+			// was before the first render. Because there could be a component
+			// which already uses it to submit the forum. This should be fixed
+			// when we pre parse the markup so that we know the id is at front.
+			if (!Strings.isEmpty(javascriptId))
 			{
-				javascriptId = getJavascriptId();
 				tag.put("id", javascriptId);
 			}
-		}
-		tag.put("method", getMethod());
-		tag.put("action", Strings.replaceAll(urlFor(IFormSubmitListener.INTERFACE), "&", "&"));
-		if (multiPart)
-		{
-			tag.put("enctype", "multipart/form-data");
-		}
-		else
-		{
-			// sanity check
-			String enctype = (String)tag.getAttributes().get("enctype");
-			if ("multipart/form-data".equalsIgnoreCase(enctype))
+			else
 			{
-				// though not set explicitly in Java, this is a multipart form
-				setMultiPart(true);
+				javascriptId = (String)tag.getAttributes().get("id");
+				if (Strings.isEmpty(javascriptId))
+				{
+					javascriptId = getJavascriptId();
+					tag.put("id", javascriptId);
+				}
+			}
+			
+			tag.put("method", getMethod());
+			tag.put("action", Strings.replaceAll(urlFor(IFormSubmitListener.INTERFACE), "&",
+					"&"));
+			
+			if (multiPart)
+			{
+				tag.put("enctype", "multipart/form-data");
+			}
+			else
+			{
+				// sanity check
+				String enctype = (String)tag.getAttributes().get("enctype");
+				if ("multipart/form-data".equalsIgnoreCase(enctype))
+				{
+					// though not set explicitly in Java, this is a multipart
+					// form
+					setMultiPart(true);
+				}
 			}
 		}
+		else
+		{
+			tag.setName("div");
+			tag.remove("method");
+			tag.remove("action");
+			tag.remove("enctype");
+		}		
 	}
 
 	/**
@@ -1488,5 +1510,35 @@
 	public final void error(String error, Map args)
 	{
 		error(new MapVariableInterpolator(error, args).toString());
+	}
+	
+	/**
+	 * Returns whether the form is a root form, which means that there's no
+	 * other form in it's parent hierarchy.
+	 * 
+	 * @return true if form is a root form, false otherwise
+	 */
+	public boolean isRootForm()
+	{
+		return findParent(Form.class) == null;
+	}
+
+	/**
+	 * Returns the root form or this, if this is the root form.
+	 * 
+	 * @return root form or this form
+	 */
+	public Form getRootForm()
+	{
+		Form form;
+		Form parent = this;
+		do
+		{
+			form = parent;
+			parent = (Form) form.findParent(Form.class);
+		}
+		while (parent != null);
+
+		return form;
 	}
 }



Re: Backporting nested forms (Was: Re: svn commit: r515729 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java)

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Matej Knopp:

> Thanks for pointing  that out. I've added the  javadoc and fixed
> set/getDefaultButton.
>
> However, the  HIDDEN_FIELD_FAKE_SUBMIT is not related  to nested
> forms.
>
> Anyway, i'd say the form can be removed from the list.

Thanks a lot!  It's very good if every developer can add things to
backport in that  page, and take care of backporting  at least one
of the things listed and update  the list accordingly.  As I'm new
to the  project, I  don't always  know what  is good  to backport,
what isn't,  what should  be backported  and what  shouldn't.  And
especially when I do it myself,  I need to check the full revision
log on  every branch to  understand what changes went  where, why,
and by whom.  Did I mention it sucks a lot of time?
-- 
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

Re: Backporting nested forms (Was: Re: svn commit: r515729 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java)

Posted by Matej Knopp <ma...@knopp.sk>.
Thanks for pointing that out. I've added the javadoc and fixed 
set/getDefaultButton.

However, the HIDDEN_FIELD_FAKE_SUBMIT is not related to nested forms.

Anyway, i'd say the form can be removed from the list.

-Matej

Jean-Baptiste Quenot wrote:
> * knopp@apache.org:
>> Author: knopp
>> Date: Wed Mar  7 12:03:08 2007
>> New Revision: 515729
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=515729
>> Log:
>> Nested forms support
>>
>> Modified:
>>     incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java
> 
> Hi Matej,
> 
> Thanks for backporting this.  Can  we consider that Form is synced
> now  between trunk  and 1.x?   I noticed  still some  differences,
> like:
> 
> * Javadoc stating nested forms
> * HIDDEN_FIELD_FAKE_SUBMIT and such
> * getDefaultButton() checks isRootForm() in trunk
> * onComponentTagBody()
> 
> May I kindly request you to review the changes, or otherwise state
> that the  differences are minor so  we can remove class  Form from
> [1]the list of things to backport from trunk.
> 
> Thanks a lot,


Backporting nested forms (Was: Re: svn commit: r515729 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java)

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* knopp@apache.org:
> Author: knopp
> Date: Wed Mar  7 12:03:08 2007
> New Revision: 515729
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=515729
> Log:
> Nested forms support
> 
> Modified:
>     incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/markup/html/form/Form.java

Hi Matej,

Thanks for backporting this.  Can  we consider that Form is synced
now  between trunk  and 1.x?   I noticed  still some  differences,
like:

* Javadoc stating nested forms
* HIDDEN_FIELD_FAKE_SUBMIT and such
* getDefaultButton() checks isRootForm() in trunk
* onComponentTagBody()

May I kindly request you to review the changes, or otherwise state
that the  differences are minor so  we can remove class  Form from
[1]the list of things to backport from trunk.

Thanks a lot,
-- 
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

[1] http://cwiki.apache.org/confluence/display/WICKET/To+Sync+Between+Branches