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<org.apache.wicket.Component>, org.apache.wicket.event.IEventSink, org.apache.wicket.event.IEventSource, org.apache.wicket.feedback.IFeedbackContributor, org.apache.wicket.IConverterLocator, org.apache.wicket.IGenericComponent<T,AjaxEditableLabel<T>>, org.apache.wicket.IMetadataContext<Serializable,org.apache.wicket.Component>, org.apache.wicket.IQueueRegion, org.apache.wicket.markup.html.IHeaderContributor, org.apache.wicket.request.component.IRequestableComponent, org.apache.wicket.util.IHierarchical<org.apache.wicket.Component>, org.apache.wicket.util.io.IClusterable
Direct Known Subclasses:
AjaxEditableChoiceLabel, AjaxEditableMultiLineLabel

public class AjaxEditableLabel<T> extends org.apache.wicket.markup.html.panel.Panel implements org.apache.wicket.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 any window.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 calling FormComponent.getInput() on getEditor(), and the error message by calling:
     String errorMessage = editor.getFeedbackMessage().getMessage();
     
    The default implementation of this method displays the error message in window.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 Classes
    Modifier and Type
    Class
    Description
    protected class 
     
    protected class 
     
  • Field Summary

    Fields inherited from class org.apache.wicket.markup.html.panel.Panel

    PANEL

    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
    Constructor
    Description
    Constructor
    AjaxEditableLabel(String id, org.apache.wicket.model.IModel<T> model)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    add(org.apache.wicket.validation.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 org.apache.wicket.markup.html.form.FormComponent<T>
    Gets the editor component.
    protected final org.apache.wicket.Component
    Gets the label component.
    protected String
    By default this returns "click", users can overwrite this on which event the label behavior should be triggered
    protected org.apache.wicket.markup.html.form.FormComponent<T>
    newEditor(org.apache.wicket.MarkupContainer parent, String componentId, org.apache.wicket.model.IModel<T> model)
    Create a new form component instance to serve as editor.
    protected org.apache.wicket.Component
    newLabel(org.apache.wicket.MarkupContainer parent, String componentId, org.apache.wicket.model.IModel<T> model)
    Create a new form component instance to serve as label.
    protected void
     
    protected void
    onCancel(org.apache.wicket.ajax.AjaxRequestTarget target)
    Invoked when the label is in edit mode, and received a cancel event.
    void
    onEdit(org.apache.wicket.ajax.AjaxRequestTarget target)
    Called when the label is clicked and the component is put in edit mode.
    protected void
    onError(org.apache.wicket.ajax.AjaxRequestTarget target)
    Invoked when the label is in edit mode, received a new input, but that input didn't validate
    protected void
    Dummy override to fix WICKET-1239
    protected void
    Dummy override to fix WICKET-1239
    protected void
    onSubmit(org.apache.wicket.ajax.AjaxRequestTarget target)
    Invoked when the editor was successfully updated.
    setDefaultModel(org.apache.wicket.model.IModel<?> model)
     
    setLabel(org.apache.wicket.model.IModel<String> labelModel)
    The value will be made available to the validator property by means of ${label}.
    setRequired(boolean required)
    Sets the required flag
    setType(Class<?> type)
    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(org.apache.wicket.ajax.attributes.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(org.apache.wicket.ajax.attributes.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

  • Method Details

    • updateLabelAjaxAttributes

      protected void updateLabelAjaxAttributes(org.apache.wicket.ajax.attributes.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.
      Parameters:
      attributes - The Ajax attributes to modify
    • updateEditorAjaxAttributes

      protected void updateEditorAjaxAttributes(org.apache.wicket.ajax.attributes.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.
      Parameters:
      attributes - The Ajax attributes to modify
    • add

      public final AjaxEditableLabel<T> add(org.apache.wicket.validation.IValidator<T> validator)
      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 constructor AjaxEditableLabel(String,IModel) or setDefaultModel(IModel).
      Parameters:
      validator - The validator
      Returns:
      This
    • setLabel

      public final AjaxEditableLabel<T> setLabel(org.apache.wicket.model.IModel<String> labelModel)
      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

      public final AjaxEditableLabel<T> setDefaultModel(org.apache.wicket.model.IModel<?> model)
      Specified by:
      setDefaultModel in interface org.apache.wicket.IGenericComponent<T,AjaxEditableLabel<T>>
      Overrides:
      setDefaultModel in class org.apache.wicket.MarkupContainer
    • setRequired

      public final AjaxEditableLabel<T> setRequired(boolean required)
      Sets the required flag
      Parameters:
      required -
      Returns:
      this for chaining
    • setType

      public final AjaxEditableLabel<T> setType(Class<?> type)
      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

      protected org.apache.wicket.markup.html.form.FormComponent<T> newEditor(org.apache.wicket.MarkupContainer parent, String componentId, org.apache.wicket.model.IModel<T> model)
      Create a new form component instance to serve as editor.
      Parameters:
      parent - The parent component
      componentId - Id that should be used by the component
      model - The model
      Returns:
      The editor
    • shouldTrimInput

      protected boolean shouldTrimInput()
      Determines whether or not the text field should trim its input prior to processing it. The default value is true
      Returns:
      True if the input should be trimmed.
    • newLabel

      protected org.apache.wicket.Component newLabel(org.apache.wicket.MarkupContainer parent, String componentId, org.apache.wicket.model.IModel<T> model)
      Create a new form component instance to serve as label.
      Parameters:
      parent - The parent component
      componentId - Id that should be used by the component
      model - 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

      protected final org.apache.wicket.markup.html.form.FormComponent<T> getEditor()
      Gets the editor component.
      Returns:
      The editor component
    • getLabel

      protected final org.apache.wicket.Component getLabel()
      Gets the label component.
      Returns:
      The label component
    • onBeforeRender

      protected void onBeforeRender()
      Overrides:
      onBeforeRender in class org.apache.wicket.Component
    • onCancel

      protected void onCancel(org.apache.wicket.ajax.AjaxRequestTarget target)
      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

      public void onEdit(org.apache.wicket.ajax.AjaxRequestTarget target)
      Called when the label is clicked and the component is put in edit mode.
      Parameters:
      target - Ajax target
    • onError

      protected void onError(org.apache.wicket.ajax.AjaxRequestTarget target)
      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

      protected void onSubmit(org.apache.wicket.ajax.AjaxRequestTarget target)
      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

      protected String 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

      protected void onModelChanged()
      Dummy override to fix WICKET-1239
      Overrides:
      onModelChanged in class org.apache.wicket.Component
    • onModelChanging

      protected void onModelChanging()
      Dummy override to fix WICKET-1239
      Overrides:
      onModelChanging in class org.apache.wicket.Component