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.WebMarkupContainerWithAssociatedMarkup
                  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, IClusterable, IConverterLocator, IHeaderPartContainerProvider
Direct Known Subclasses:
AjaxEditableChoiceLabel, AjaxEditableMultiLineLabel

public class AjaxEditableLabel<T>
extends Panel

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
           
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor<T extends Component>, Component.VisibilityChange
 
Field Summary
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_CONFIGURED, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, 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.
 IConverter getConverter(Class<?> type)
          Implementation that returns null by default (panels don't typically need converters anyway).
protected  FormComponent<T> getEditor()
          Gets the editor component.
protected  WebComponent 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
protected  FormComponent<T> newEditor(MarkupContainer parent, String componentId, IModel<T> model)
          Create a new form component instance to serve as editor.
protected  WebComponent newLabel(MarkupContainer parent, String componentId, IModel<T> model)
          Create a new form component instance to serve as label.
protected  void onBeforeRender()
          Called just before a component is rendered.
protected  void onCancel(AjaxRequestTarget target)
          Invoked when the label is in edit mode, and received a cancel event.
protected  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)
          Sets the given model.
 AjaxEditableLabel<T> setLabel(IModel<String> labelModel)
          The value will be made available to the validator property by means of ${label}.
 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.
 
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
onComponentTag, onComponentTagBody, renderHead
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
newHeaderPartContainer, renderHeadFromAssociatedMarkupFile
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onAfterRenderChildren, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, renderNext, replace, setMarkupStream, size, swap, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, onAfterRender, onAttach, onBeginRequest, onConfigure, onDetach, onEndRequest, onInitialize, onRemove, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, 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

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 IConverter getConverter(Class<?> 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
Parameters:
type - The type to convert to
Returns:
The converter that should be used by this component
See Also:
Component.getConverter(java.lang.Class)

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.

Overrides:
setDefaultModel in class MarkupContainer
Parameters:
model - The model
Returns:
This
See Also:
MarkupContainer.setDefaultModel(org.apache.wicket.model.IModel)

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 WebComponent 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 WebComponent getLabel()
Gets the label component.

Returns:
The label component

onBeforeRender

protected void onBeforeRender()
Description copied from class: Component
Called just before a 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.

Overrides:
onBeforeRender in class Component
See Also:
Component.onBeforeRender()

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

protected 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
See Also:
Component.onModelChanged()

onModelChanging

protected void onModelChanging()
Dummy override to fix WICKET-1239

Overrides:
onModelChanging in class Component
See Also:
Component.onModelChanging()


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.