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,org.apache.wicket.util.IHierarchical<Component>,org.apache.wicket.util.io.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.statusset.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
Nested ClassesModifier and TypeClassDescriptionprotected classprotected 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal AjaxEditableLabel<T>add(IValidator<T> validator) Adds a validator to this form component.protected StringOverride this to display a different value when the model object is null.protected final FormComponent<T>Gets the editor component.protected final ComponentgetLabel()Gets the label component.protected StringBy 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 ComponentnewLabel(MarkupContainer parent, String componentId, IModel<T> model) Create a new form component instance to serve as label.protected voidprotected voidonCancel(AjaxRequestTarget target) Invoked when the label is in edit mode, and received a cancel event.voidonEdit(AjaxRequestTarget target) Called when the label is clicked and the component is put in edit mode.protected voidonError(AjaxRequestTarget target) Invoked when the label is in edit mode, received a new input, but that input didn't validateprotected voidDummy override to fix WICKET-1239protected voidDummy override to fix WICKET-1239protected voidonSubmit(AjaxRequestTarget target) Invoked when the editor was successfully updated.final AjaxEditableLabel<T>setDefaultModel(IModel<?> 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 booleanDetermines whether or not the text field should trim its input prior to processing it.protected voidupdateEditorAjaxAttributes(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 voidupdateLabelAjaxAttributes(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, newMarkupSourcingStrategyMethods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSessionMethods 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, visitChildrenMethods 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, wrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.wicket.IGenericComponent
getDefaultModel, getDefaultModelObject, getModel, getModelObject, setDefaultModelObject, setModel, setModelObjectMethods inherited from interface org.apache.wicket.IQueueRegion
dequeue, newDequeueContextMethods 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
- Specified by:
setDefaultModelin interfaceIGenericComponent<T,AjaxEditableLabel<T>> - Overrides:
setDefaultModelin classMarkupContainer
-
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
- Overrides:
onBeforeRenderin classComponent
-
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:
onModelChangedin classComponent
-
onModelChanging
Dummy override to fix WICKET-1239- Overrides:
onModelChangingin classComponent
-