org.apache.wicket.ajax.markup.html.form
Class AjaxSubmitLink

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.link.AbstractLink
                  extended by org.apache.wicket.markup.html.form.AbstractSubmitLink
                      extended by org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink
All Implemented Interfaces:
java.io.Serializable, IClusterable, IConverterLocator, IFormSubmittingComponent

public abstract class AjaxSubmitLink
extends AbstractSubmitLink

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.

It works by splitting the javascript/Ajax calls from the normal non-ajax requests by generating:

 <a href="normal action url" onclick="ajax javascript script; return
 false;">link</a>
 
If/when javascript is turned off in the browser, or it doesn't support javascript, then the browser will not respond to the onclick event, using the href directly. Wicket will then use a normal request target, and call the serverside onClick with a null AjaxRequestTarget. If javascript is enabled, Wicket will send an ajax request, and process it serverside with an AjaxRequestTarget that is supplied to the server-side onClick method. The "return false" in the <a href> onclick handler ensures the browser doesn't perform the normal request too. The latter is nicely illustrated with this:
 <a href="javascript:alert('href event handler');"
 onclick="alert('onclick event handler');">clicking me gives two
 alerts</a>
 
 <a href="javascript:alert('href event handler');"
 onclick="alert('onclick event handler');return false;">clicking me
 gives only one alert</a>
 

Since:
1.2
Author:
Igor Vaynberg (ivaynberg)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor, Component.VisibilityChange
 
Field Summary
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Constructor Summary
AjaxSubmitLink(java.lang.String id)
          Construct.
AjaxSubmitLink(java.lang.String id, Form form)
          Construct.
 
Method Summary
protected  IAjaxCallDecorator getAjaxCallDecorator()
          Returns the IAjaxCallDecorator that will be used to modify the generated javascript.
protected  void onComponentTag(ComponentTag tag)
          Processes the component tag.
protected  void onError(AjaxRequestTarget target, Form form)
          Listener method invoked on form submit with errors
 void onSubmit()
          Final implementation of the Button's onSubmit.
protected abstract  void onSubmit(AjaxRequestTarget target, Form form)
          Listener method invoked on form submit
 
Methods inherited from class org.apache.wicket.markup.html.form.AbstractSubmitLink
getDefaultFormProcessing, getForm, getInputName, setDefaultFormProcessing
 
Methods inherited from class org.apache.wicket.markup.html.link.AbstractLink
disableLink, getAfterDisabledLink, getBeforeDisabledLink, isLinkEnabled, onBeforeRender, onComponentTagBody, setAfterDisabledLink, setBeforeDisabledLink
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getModelObjectAsString, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeginRequest, onDetach, onEndRequest, onModelChanged, onModelChanging, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderHead, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMetaData, setModelObject, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AjaxSubmitLink

public AjaxSubmitLink(java.lang.String id)
Construct.

Parameters:
id -

AjaxSubmitLink

public AjaxSubmitLink(java.lang.String id,
                      Form form)
Construct.

Parameters:
id -
form -
Method Detail

getAjaxCallDecorator

protected IAjaxCallDecorator getAjaxCallDecorator()
Returns the IAjaxCallDecorator that will be used to modify the generated javascript. This is the preferred way of changing the javascript in the onclick handler

Returns:
call decorator used to modify the generated javascript or null for none

onComponentTag

protected void onComponentTag(ComponentTag tag)
Description copied from class: Component
Processes the component tag.

Overrides:
onComponentTag in class Component
Parameters:
tag - Tag to modify

onSubmit

public final void onSubmit()
Final implementation of the Button's onSubmit. AjaxSubmitLinks have there own onSubmit which is called.

See Also:
Button.onSubmit()

onSubmit

protected abstract void onSubmit(AjaxRequestTarget target,
                                 Form form)
Listener method invoked on form submit

Parameters:
target -
form -

onError

protected void onError(AjaxRequestTarget target,
                       Form form)
Listener method invoked on form submit with errors

Parameters:
target -
form - TODO 1.3: Make abstract to be consistent with onsubmit()


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.