org.apache.wicket.extensions.ajax.markup.html
Class AjaxEditableLabel<T>

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.panel.Panel
                  extended by org.apache.wicket.extensions.ajax.markup.html.AjaxEditableLabel<T>
Type Parameters:
T -
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IConverterLocator, IGenericComponent<T>, 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>

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.

Author:
Igor Vaynberg (ivaynberg), Eelco Hillenius
See Also:
Serialized Form

Nested Class Summary
protected  class AjaxEditableLabel.EditorAjaxBehavior
           
protected  class AjaxEditableLabel.LabelAjaxBehavior
           
 
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_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
AjaxEditableLabel(String id)
          Constructor
AjaxEditableLabel(String id, IModel<T> model)
          Constructor
 
Method Summary
 AjaxEditableLabel<T> add(IValidator<T> validator)
          Adds a validator to this form component.
protected  String defaultNullLabel()
          Override this to display a different value when the model object is null.
<C> org.apache.wicket.util.convert.IConverter<C>
getConverter(Class<C> type)
          Implementation that returns null by default (panels don't typically need converters anyway).
protected  FormComponent<T> getEditor()
          Gets the editor component.
protected  Component getLabel()
          Gets the label component.
protected  String getLabelAjaxEvent()
          By default this returns "onclick" uses can overwrite this on which event the label behavior should be triggered
 IModel<T> getModel()
           
 T getModelObject()
           
protected  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 onBeforeRender()
           
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 validate
protected  void onModelChanged()
          Dummy override to fix WICKET-1239
protected  void onModelChanging()
          Dummy override to fix WICKET-1239
protected  void onSubmit(AjaxRequestTarget target)
          Invoked when the editor was successfully updated.
 AjaxEditableLabel<T> setDefaultModel(IModel<?> model)
           
 AjaxEditableLabel<T> setLabel(IModel<String> labelModel)
          The value will be made available to the validator property by means of ${label}.
 void setModel(IModel<T> model)
           
 void setModelObject(T object)
           
 AjaxEditableLabel<T> setRequired(boolean required)
          Sets the required flag
 AjaxEditableLabel<T> setType(Class<?> type)
          Sets the type that will be used when updating the model for this component.
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
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, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, 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, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onComponentTag, onConfigure, onDetach, onEvent, onInitialize, onReAdd, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AjaxEditableLabel

public AjaxEditableLabel(String id)
Constructor

Parameters:
id -

AjaxEditableLabel

public AjaxEditableLabel(String id,
                         IModel<T> model)
Constructor

Parameters:
id -
model -
Method Detail

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

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.

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

getConverter

public <C> org.apache.wicket.util.convert.IConverter<C> getConverter(Class<C> type)
Implementation that returns null by default (panels don't typically need converters anyway). This is used by the embedded default instances of label and form field to determine whether they should use a converter like they normally would (when this method returns null), or whether they should use a custom converter (when this method is overridden and returns not null).

Specified by:
getConverter in interface IConverterLocator
Overrides:
getConverter in class Component

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)
Overrides:
setDefaultModel in class MarkupContainer

getModel

public IModel<T> getModel()
Specified by:
getModel in interface IGenericComponent<T>

getModelObject

public T getModelObject()
Specified by:
getModelObject in interface IGenericComponent<T>

setModel

public void setModel(IModel<T> model)
Specified by:
setModel in interface IGenericComponent<T>

setModelObject

public void setModelObject(T object)
Specified by:
setModelObject in interface IGenericComponent<T>

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

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

protected String getLabelAjaxEvent()
By default this returns "onclick" uses 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()
Overrides:
onBeforeRender in class Component

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


Copyright © 2006–2020 Apache Software Foundation. All rights reserved.