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 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:
  • Constructor Details

  • Method Details

    • updateLabelAjaxAttributes

      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.
      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

      public final AjaxEditableLabel<T> add(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(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(IModel<?> model)
      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 interface IGenericComponent<T,AjaxEditableLabel<T>>
      Overrides:
      setDefaultModel in class MarkupContainer
      Parameters:
      model - The model
      Returns:
      This
    • 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 FormComponent<T> newEditor(MarkupContainer parent, String componentId, 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 Component newLabel(MarkupContainer parent, String componentId, 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 FormComponent<T> getEditor()
      Gets the editor component.
      Returns:
      The editor component
    • getLabel

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

      protected void 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 Component.onBeforeRender() call to its children it is strongly recommended that super call is made at the end of the override.

      Changes to the component tree can be made only before calling super.onBeforeRender().
      Overrides:
      onBeforeRender in class Component
      See Also:
    • onCancel

      protected void onCancel(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(AjaxRequestTarget target)
      Called when the label is clicked and the component is put in edit mode.
      Parameters:
      target - Ajax target
    • onError

      protected void onError(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(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 Component
    • onModelChanging

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