You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/01/04 22:26:23 UTC
svn commit: r492750 - in /incubator/wicket/branches/wicket-1.x/wicket/src:
main/java/wicket/ajax/form/ main/java/wicket/ajax/markup/html/form/
test/java/wicket/markup/html/list/
Author: ivaynberg
Date: Thu Jan 4 13:26:22 2007
New Revision: 492750
URL: http://svn.apache.org/viewvc?view=rev&rev=492750
Log:
we dont need to pass in a form, we can look it up in the hieararchy if the component that has this behavior is inside a form
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/form/AjaxFormSubmitBehavior.java
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/markup/html/list/IncrementalTableNavigationPage_ExpectedResult_1-2.html
Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/form/AjaxFormSubmitBehavior.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/form/AjaxFormSubmitBehavior.java?view=diff&rev=492750&r1=492749&r2=492750
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/form/AjaxFormSubmitBehavior.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/form/AjaxFormSubmitBehavior.java Thu Jan 4 13:26:22 2007
@@ -16,6 +16,7 @@
*/
package wicket.ajax.form;
+import wicket.Component;
import wicket.ajax.AjaxEventBehavior;
import wicket.ajax.AjaxRequestTarget;
import wicket.markup.html.form.Button;
@@ -44,6 +45,8 @@
*/
private static final long serialVersionUID = 1L;
+ private Component owner;
+
private Form form;
@@ -61,9 +64,35 @@
this.form = form;
}
+ private Form getForm()
+ {
+ if (form == null)
+ {
+ // try to find form in the hierarchy of owning component
+ Component cursor = getComponent();
+ while (cursor != null && !(cursor instanceof Form))
+ {
+ cursor = cursor.getParent();
+ }
+ if (cursor == null)
+ {
+ throw new IllegalStateException(
+ "form was not specified in the constructor and cannot "
+ + "be found in the hierarchy of the component this behavior "
+ + "is attached to");
+ }
+ else
+ {
+ form = (Form)cursor;
+ }
+ }
+ return form;
+ }
+
+
protected CharSequence getEventHandler()
{
- final String formId = form.getMarkupId();
+ final String formId = getForm().getMarkupId();
final CharSequence url = getCallbackUrl();
@@ -84,8 +113,8 @@
protected void onEvent(AjaxRequestTarget target)
{
- form.onFormSubmitted();
- if (!form.hasError())
+ getForm().onFormSubmitted();
+ if (!getForm().hasError())
{
onSubmit(target);
}
Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java?view=diff&rev=492750&r1=492749&r2=492750
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitButton.java Thu Jan 4 13:26:22 2007
@@ -41,6 +41,16 @@
* Construct.
*
* @param id
+ */
+ public AjaxSubmitButton(String id)
+ {
+ this(id, null);
+ }
+
+ /**
+ * Construct.
+ *
+ * @param id
* @param form
*/
public AjaxSubmitButton(String id, final Form form)
@@ -56,7 +66,7 @@
{
AjaxSubmitButton.this.onSubmit(target, form);
}
-
+
protected void onError(AjaxRequestTarget target)
{
AjaxSubmitButton.this.onError(target, form);
@@ -121,8 +131,9 @@
*
* TODO 1.3: Make abstract to be consistent with onsubmit()
*/
- protected void onError(AjaxRequestTarget target, Form form) {
-
+ protected void onError(AjaxRequestTarget target, Form form)
+ {
+
}
}
Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java?view=diff&rev=492750&r1=492749&r2=492750
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/ajax/markup/html/form/AjaxSubmitLink.java Thu Jan 4 13:26:22 2007
@@ -14,108 +14,118 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package wicket.ajax.markup.html.form;
-
-import wicket.ajax.AjaxRequestTarget;
-import wicket.ajax.IAjaxCallDecorator;
-import wicket.ajax.form.AjaxFormSubmitBehavior;
-import wicket.markup.ComponentTag;
-import wicket.markup.html.WebMarkupContainer;
-import wicket.markup.html.form.Form;
-import wicket.util.string.AppendingStringBuffer;
-
-/**
- * A link that submits a form via ajax. Since this link takes the form as a
- * constructor argument it does not need to be inside form's component
- * hierarchy.
- *
- * @since 1.2
- *
- * @author Igor Vaynberg (ivaynberg)
- */
-public abstract class AjaxSubmitLink extends WebMarkupContainer
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * Construct.
- *
- * @param id
- * @param form
- */
- public AjaxSubmitLink(String id, final Form form)
- {
- super(id);
-
- form.setOutputMarkupId(true);
-
- add(new AjaxFormSubmitBehavior(form, "onclick")
- {
-
- private static final long serialVersionUID = 1L;
-
- protected void onSubmit(AjaxRequestTarget target)
- {
- AjaxSubmitLink.this.onSubmit(target, form);
- }
-
- protected void onError(AjaxRequestTarget target)
- {
- AjaxSubmitLink.this.onError(target, form);
- }
-
- protected CharSequence getEventHandler()
- {
- return new AppendingStringBuffer(super.getEventHandler()).append("; return false;");
- }
-
- protected IAjaxCallDecorator getAjaxCallDecorator()
- {
- return AjaxSubmitLink.this.getAjaxCallDecorator();
- }
- });
-
- }
-
- /**
- * Returns the {@link IAjaxCallDecorator} that will be used to modify the
- * generated javascript. This is the preferred way of changing the
- * javascript in the onclick handler
- *
- * @return call decorator used to modify the generated javascript or null
- * for none
- */
- protected IAjaxCallDecorator getAjaxCallDecorator()
- {
- return null;
- }
-
- protected void onComponentTag(ComponentTag tag)
- {
- super.onComponentTag(tag);
- checkComponentTag(tag, "a");
- tag.put("href", "#");
- }
-
- /**
- * Listener method invoked on form submit
- *
- * @param target
- * @param form
- */
- protected abstract void onSubmit(AjaxRequestTarget target, Form form);
-
- /**
- * Listener method invoked on form submit with errors
- *
- * @param target
- * @param form
- *
- * TODO 1.3: Make abstract to be consistent with onsubmit()
- */
- protected void onError(AjaxRequestTarget target, Form form)
- {
-
- }
-
-}
+package wicket.ajax.markup.html.form;
+
+import wicket.ajax.AjaxRequestTarget;
+import wicket.ajax.IAjaxCallDecorator;
+import wicket.ajax.form.AjaxFormSubmitBehavior;
+import wicket.markup.ComponentTag;
+import wicket.markup.html.WebMarkupContainer;
+import wicket.markup.html.form.Form;
+import wicket.util.string.AppendingStringBuffer;
+
+/**
+ * A link that submits a form via ajax. Since this link takes the form as a
+ * constructor argument it does not need to be inside form's component
+ * hierarchy.
+ *
+ * @since 1.2
+ *
+ * @author Igor Vaynberg (ivaynberg)
+ */
+public abstract class AjaxSubmitLink extends WebMarkupContainer
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ *
+ * @param id
+ */
+ public AjaxSubmitLink(String id)
+ {
+ this(id, null);
+ }
+
+ /**
+ * Construct.
+ *
+ * @param id
+ * @param form
+ */
+ public AjaxSubmitLink(String id, final Form form)
+ {
+ super(id);
+
+ form.setOutputMarkupId(true);
+
+ add(new AjaxFormSubmitBehavior(form, "onclick")
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void onSubmit(AjaxRequestTarget target)
+ {
+ AjaxSubmitLink.this.onSubmit(target, form);
+ }
+
+ protected void onError(AjaxRequestTarget target)
+ {
+ AjaxSubmitLink.this.onError(target, form);
+ }
+
+ protected CharSequence getEventHandler()
+ {
+ return new AppendingStringBuffer(super.getEventHandler()).append("; return false;");
+ }
+
+ protected IAjaxCallDecorator getAjaxCallDecorator()
+ {
+ return AjaxSubmitLink.this.getAjaxCallDecorator();
+ }
+ });
+
+ }
+
+ /**
+ * Returns the {@link IAjaxCallDecorator} that will be used to modify the
+ * generated javascript. This is the preferred way of changing the
+ * javascript in the onclick handler
+ *
+ * @return call decorator used to modify the generated javascript or null
+ * for none
+ */
+ protected IAjaxCallDecorator getAjaxCallDecorator()
+ {
+ return null;
+ }
+
+ protected void onComponentTag(ComponentTag tag)
+ {
+ super.onComponentTag(tag);
+ checkComponentTag(tag, "a");
+ tag.put("href", "#");
+ }
+
+ /**
+ * Listener method invoked on form submit
+ *
+ * @param target
+ * @param form
+ */
+ protected abstract void onSubmit(AjaxRequestTarget target, Form form);
+
+ /**
+ * Listener method invoked on form submit with errors
+ *
+ * @param target
+ * @param form
+ *
+ * TODO 1.3: Make abstract to be consistent with onsubmit()
+ */
+ protected void onError(AjaxRequestTarget target, Form form)
+ {
+
+ }
+
+}
Modified: incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/markup/html/list/IncrementalTableNavigationPage_ExpectedResult_1-2.html
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/markup/html/list/IncrementalTableNavigationPage_ExpectedResult_1-2.html?view=diff&rev=492750&r1=492749&r2=492750
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/markup/html/list/IncrementalTableNavigationPage_ExpectedResult_1-2.html (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/markup/html/list/IncrementalTableNavigationPage_ExpectedResult_1-2.html Thu Jan 4 13:26:22 2007
@@ -3,6 +3,6 @@
<title>Paged Table Page</title>
</head>
<body><ul><li wicket:id="table"><span wicket:id="txt">three</span></li><li wicket:id="table"><span wicket:id="txt">four</span></li></ul>
-<a href="/WicketTester/WicketTester?wicket:interface=:0:prev:2:ILinkListener" wicket:id="prev">Prev</a><a href="/WicketTester/WicketTester?wicket:interface=:0:nextNext:2:ILinkListener" wicket:id="nextNext">NextNext</a>
+<a href="/WicketTester/WicketTester?wicket:interface=:0:prev:4:ILinkListener" wicket:id="prev">Prev</a><a href="/WicketTester/WicketTester?wicket:interface=:0:nextNext:4:ILinkListener" wicket:id="nextNext">NextNext</a>
</body>
</html>