Module org.apache.wicket.extensions
Class AjaxEditableLabel<T>
java.lang.Object
org.apache.wicket.Component
org.apache.wicket.MarkupContainer
org.apache.wicket.markup.html.WebMarkupContainer
org.apache.wicket.markup.html.panel.Panel
org.apache.wicket.extensions.ajax.markup.html.AjaxEditableLabel<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IGenericComponent<T,
,AjaxEditableLabel<T>> IMetadataContext<Serializable,
,Component> IQueueRegion
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
AjaxEditableChoiceLabel
,AjaxEditableMultiLineLabel
public class AjaxEditableLabel<T>
extends Panel
implements IGenericComponent<T,AjaxEditableLabel<T>>
An implementation of ajaxified edit-in-place component using a
TextField
as it's editor.
There are several methods that can be overridden for customization.
onEdit(org.apache.wicket.ajax.AjaxRequestTarget)
is called when the label is clicked and the editor is to be displayed. The default implementation switches the label for the editor and places the caret at the end of the text.onSubmit(org.apache.wicket.ajax.AjaxRequestTarget)
is called when in edit mode, the user submitted new content, that content validated well, and the model value successfully updated. This implementation also clears anywindow.status
set.onError(org.apache.wicket.ajax.AjaxRequestTarget)
is called when in edit mode, the user submitted new content, but that content did not validate. Get the current input by callingFormComponent.getInput()
ongetEditor()
, and the error message by calling:String errorMessage = editor.getFeedbackMessage().getMessage();
The default implementation of this method displays the error message inwindow.status
, redisplays the editor, selects the editor's content and sets the focus on it.onCancel(org.apache.wicket.ajax.AjaxRequestTarget)
is called when in edit mode, the user choose not to submit the contents (he/she pressed escape). The default implementation displays the label again without any further action.
- Author:
- Igor Vaynberg (ivaynberg), Eelco Hillenius
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
protected class
-
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
-
Method Summary
Modifier and TypeMethodDescriptionfinal AjaxEditableLabel<T>
add
(IValidator<T> validator) Adds a validator to this form component.protected String
Override this to display a different value when the model object is null.protected final FormComponent<T>
Gets the editor component.protected final Component
getLabel()
Gets the label component.protected String
By default this returns "click", users can overwrite this on which event the label behavior should be triggeredprotected FormComponent<T>
newEditor
(MarkupContainer parent, String componentId, IModel<T> model) Create a new form component instance to serve as editor.protected Component
newLabel
(MarkupContainer parent, String componentId, IModel<T> model) Create a new form component instance to serve as label.protected void
Called on all visible components before any component is rendered.protected void
onCancel
(AjaxRequestTarget target) Invoked when the label is in edit mode, and received a cancel event.void
onEdit
(AjaxRequestTarget target) Called when the label is clicked and the component is put in edit mode.protected void
onError
(AjaxRequestTarget target) Invoked when the label is in edit mode, received a new input, but that input didn't validateprotected void
Dummy override to fix WICKET-1239protected void
Dummy override to fix WICKET-1239protected void
onSubmit
(AjaxRequestTarget target) Invoked when the editor was successfully updated.final AjaxEditableLabel<T>
setDefaultModel
(IModel<?> model) Sets the given model.final AjaxEditableLabel<T>
The value will be made available to the validator property by means of ${label}.final AjaxEditableLabel<T>
setRequired
(boolean required) Sets the required flagfinal AjaxEditableLabel<T>
Sets the type that will be used when updating the model for this component.protected boolean
Determines whether or not the text field should trim its input prior to processing it.protected void
updateEditorAjaxAttributes
(AjaxRequestAttributes attributes) Gives a chance to the specializations to modify the Ajax attributes for the request when this component switches from a label to an editor.protected void
updateLabelAjaxAttributes
(AjaxRequestAttributes attributes) Gives a chance to the specializations to modify the Ajax attributes for the request when this component switches from an editor to a label.Methods inherited from class org.apache.wicket.markup.html.panel.Panel
getRegionMarkup, newMarkupSourcingStrategy
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, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onDetach, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, 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, onAfterRender, onComponentTag, onConfigure, onEvent, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, 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 org.apache.wicket.IGenericComponent
getDefaultModel, getDefaultModelObject, getModel, getModelObject, setDefaultModelObject, setModel, setModelObject
Methods inherited from interface org.apache.wicket.IQueueRegion
dequeue, newDequeueContext
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AjaxEditableLabel
Constructor- Parameters:
id
-
-
AjaxEditableLabel
Constructor- Parameters:
id
-model
-
-
-
Method Details
-
updateLabelAjaxAttributes
Gives a chance to the specializations to modify the Ajax attributes for the request when this component switches from an editor to a label.- Parameters:
attributes
- The Ajax attributes to modify
-
updateEditorAjaxAttributes
Gives a chance to the specializations to modify the Ajax attributes for the request when this component switches from a label to an editor.- Parameters:
attributes
- The Ajax attributes to modify
-
add
Adds a validator to this form component. A model must be available for this component before Validators can be added. Either add this Component to its parent (already having a Model), or provide one before this call via constructorAjaxEditableLabel(String,IModel)
orsetDefaultModel(IModel)
.- Parameters:
validator
- The validator- Returns:
- This
-
setLabel
The value will be made available to the validator property by means of ${label}. It does not have any specific meaning to FormComponent itself.- Parameters:
labelModel
-- Returns:
- this for chaining
-
setDefaultModel
Description copied from class:Component
Sets the given model.WARNING: DO NOT OVERRIDE THIS METHOD UNLESS YOU HAVE A VERY GOOD REASON FOR IT. OVERRIDING THIS MIGHT OPEN UP SECURITY LEAKS AND BREAK BACK-BUTTON SUPPORT.
- Specified by:
setDefaultModel
in interfaceIGenericComponent<T,
AjaxEditableLabel<T>> - Overrides:
setDefaultModel
in classMarkupContainer
- Parameters:
model
- The model- Returns:
- This
-
setRequired
Sets the required flag- Parameters:
required
-- Returns:
- this for chaining
-
setType
Sets the type that will be used when updating the model for this component. If no type is specified String type is assumed.- Parameters:
type
-- Returns:
- this for chaining
-
newEditor
Create a new form component instance to serve as editor.- Parameters:
parent
- The parent componentcomponentId
- Id that should be used by the componentmodel
- The model- Returns:
- The editor
-
shouldTrimInput
Determines whether or not the text field should trim its input prior to processing it. The default value istrue
- Returns:
- True if the input should be trimmed.
-
newLabel
Create a new form component instance to serve as label.- Parameters:
parent
- The parent componentcomponentId
- Id that should be used by the componentmodel
- The model- Returns:
- The editor
-
getLabelAjaxEvent
By default this returns "click", users can overwrite this on which event the label behavior should be triggered- Returns:
- The event name
-
getEditor
Gets the editor component.- Returns:
- The editor component
-
getLabel
Gets the label component.- Returns:
- The label component
-
onBeforeRender
Description copied from class:Component
Called on all visible components before any component is rendered.NOTE: If you override this, you *must* call super.onBeforeRender() within your implementation. Because this method is responsible for cascading
Changes to the component tree can be made only before calling super.onBeforeRender().Component.onBeforeRender()
call to its children it is strongly recommended that super call is made at the end of the override.- Overrides:
onBeforeRender
in classComponent
- See Also:
-
onCancel
Invoked when the label is in edit mode, and received a cancel event. Typically, nothing should be done here.- Parameters:
target
- the ajax request target
-
onEdit
Called when the label is clicked and the component is put in edit mode.- Parameters:
target
- Ajax target
-
onError
Invoked when the label is in edit mode, received a new input, but that input didn't validate- Parameters:
target
- the ajax request target
-
onSubmit
Invoked when the editor was successfully updated. Use this method e.g. to persist the changed value. This implementation displays the label and clears any window status that might have been set in onError.- Parameters:
target
- The ajax request target
-
defaultNullLabel
Override this to display a different value when the model object is null. Default is...
- Returns:
- The string which should be displayed when the model object is null.
-
onModelChanged
Dummy override to fix WICKET-1239- Overrides:
onModelChanged
in classComponent
-
onModelChanging
Dummy override to fix WICKET-1239- Overrides:
onModelChanging
in classComponent
-