- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IMetadataContext<Serializable,
,Component> IFormSubmitter
,IFormSubmittingComponent
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
A link which can be used exactly like a Button to submit a Form. The onclick of the link will use
JavaScript to submit the form.
You can use this class 2 ways. First with the constructor without a Form object then this Link must be inside a Form so that it knows what form to submit to. Second way is to use the Form constructor then that form will be used to submit to.
Form f = new Form("linkForm", new CompoundPropertyModel(mod)); f.add(new TextField("value1")); f.add(new SubmitLink("link1") { protected void onSubmit() { System.out.println("Link1 was clicked, value1 is: " + mod.getValue1()); }; }); add(new SubmitLink("link2",f) { protected void onSubmit() { System.out.println("Link2 was clicked, value1 is: " + mod.getValue1()); }; }); <form wicket:id="linkForm" > <input wicket:id="value1" type="text" size="30"/> <a wicket:id="link1">Press link1 to submit</a> <input type="submit" value="Send"/> </form> <a wicket:id="link2">Press link 2 to submit</a>
If this link is not placed in a form or given a form to cooperate with, it will fall back to a
normal link behavior, meaning that onSubmit()
will be called without any other
consequences.
To customize the JavaScript code used to submit the form we must override getTriggerJavaScript()
.
This can be helpful to implement additional client side behaviors like disabling the link during form submission.
- Author:
- chris, jcompagner, Igor Vaynberg (ivaynberg), Eelco Hillenius
- See Also:
-
Field Summary
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
Constructor Summary
ConstructorDescriptionSubmitLink
(String id) With this constructor the SubmitLink must be inside a Form.SubmitLink
(String id, Form<?> form) With this constructor the SubmitLink will submit theForm
that is given when the link is clicked on.SubmitLink
(String id, IModel<?> model) With this constructor the SubmitLink must be inside a Form.SubmitLink
(String id, IModel<?> model, Form<?> form) With this constructor the SubmitLink will submit theForm
that is given when the link is clicked on. -
Method Summary
Modifier and TypeMethodDescriptionprotected CharSequence
The JavaScript which triggers this link.void
Override this method to provide special submit handling in a multi-button form.protected void
Processes the component tag.void
onError()
Method that is invoked when form processing fails; for example, when there are validation errors.final void
This method is here as a means to fall back on normal link behavior when this link is not nested in a form.void
onSubmit()
Override this method to provide special submit handling in a multi-button form.void
renderHead
(IHeaderResponse response) Render to the web response whatever the component wants to contribute to the head section.protected boolean
Controls whether or not clicking on this link will trigger a javascript submit event, firing any submit handler added to the form.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, getBody, onComponentTagBody, onDetach, setBody
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SubmitLink
With this constructor the SubmitLink must be inside a Form.- Parameters:
id
- The id of the submitlink.
-
SubmitLink
With this constructor the SubmitLink will submit theForm
that is given when the link is clicked on. The SubmitLink doesn't have to be inside theForm
. But currently if it is outside theForm
and the SubmitLink is rendered first, then theForm
will have a generated javascript/css id. The markup javascript/css id that can exist will be overridden.- Parameters:
id
- The id of the submitlink.form
- The form which this submitlink must submit.
-
SubmitLink
With this constructor the SubmitLink must be inside a Form.- Parameters:
id
- The id of the submitlink.model
- The model for this submitlink, It won't be used by the submit link itself, but it can be used for keeping state
-
SubmitLink
With this constructor the SubmitLink will submit theForm
that is given when the link is clicked on. The SubmitLink doesn't have to be in inside theForm
. But currently if it is outside theForm
and the SubmitLink will be rendered first. Then theForm
will have a generated javascript/css id. The markup javascript/css id that can exist will be overridden.- Parameters:
id
- The id of the submitlink.model
- The model for this submitlink, It won't be used by the submit link itself, but it can be used for keeping stateform
- The form which this submitlink must submit.
-
-
Method Details
-
onLinkClicked
This method is here as a means to fall back on normal link behavior when this link is not nested in a form. Not intended to be called by clients directly.- See Also:
-
onComponentTag
Description copied from class:Component
Processes the component tag. Overrides of this method most likely should call the super implementation.- Overrides:
onComponentTag
in classComponent
- Parameters:
tag
- Tag to modify
-
renderHead
Description copied from class:Component
Render to the web response whatever the component wants to contribute to the head section.- Specified by:
renderHead
in interfaceIHeaderContributor
- Overrides:
renderHead
in classComponent
- Parameters:
response
- Response object
-
shouldTriggerJavaScriptSubmitEvent
Controls whether or not clicking on this link will trigger a javascript submit event, firing any submit handler added to the form. True by default.- Returns:
- true if form's javascript submit handlers should be invoked, false otherwise
-
getTriggerJavaScript
The JavaScript which triggers this link. Method is non-final so that subclasses can decorate the provided script by wrapping their own JS around a call to super.getTriggerJavaScript().- Returns:
- The JavaScript to be executed when the link is clicked.
-
onError
Description copied from interface:IFormSubmitter
Method that is invoked when form processing fails; for example, when there are validation errors. -
onAfterSubmit
Override this method to provide special submit handling in a multi-button form. This method will be called after the form's onSubmit method. -
onSubmit
Override this method to provide special submit handling in a multi-button form. This method will be called before the form's onSubmit method.
-