This documentation is for an old version of fiftyfive-wicket (2.0.9).


fiftyfive.wicket.basic
Class CountLabel

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.markup.html.WebComponent
          extended by org.apache.wicket.markup.html.basic.Label
              extended by fiftyfive.wicket.basic.CountLabel
All Implemented Interfaces:
Serializable, IClusterable, IConverterLocator

public class CountLabel
extends Label

Displays a label with up to three different variations based on whether a numeric model is zero, one, or greater than one. This is incredibly useful for printing count messages where the phrasing needs to change according to singular and plural rules, like this:

In addition, the label can contain a hyperlink that you specify by calling setLink().

To achieve the output shown in the example above, you would first add these entries to your localizable properties file associated with your page or panel:

 friends.zero = There are no friends in your network.
 friends.one = There is <a href="${href}">one friend</a> in your network.
 friends.many = There are <a href="${href}">${count} friends</a> in your network.

Then, construct the label and add it to your page or panel like so:

 add(new CountLabel("friends", numFriendsModel)
     .setLink(MyFriendsPage.class));

It's that simple.

This class is a simple Label wrapper around a CountMessageModel, which does most of the work. Refer to the class documentation of CountMessageModel for more details.

Since:
2.0
See Also:
Serialized Form

Nested Class Summary
 
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, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
CountLabel(String id, IModel<? extends Number> count)
          Constructs a label that will a display zero, singular or plural variation based on the value of the specified count model.
 
Method Summary
 CountLabel setLink(Class<? extends Page> page)
           
 CountLabel setLink(Class<? extends Page> page, PageParameters params)
           
 
Methods inherited from class org.apache.wicket.markup.html.basic.Label
onComponentTag, onComponentTagBody
 
Methods inherited from class org.apache.wicket.markup.html.WebComponent
onRender
 
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, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, 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, onBeforeRender, onBeginRequest, onConfigure, onDetach, onEndRequest, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setDefaultModel, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupIdImpl, setMarkupStream, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, toString, toString, 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

CountLabel

public CountLabel(String id,
                  IModel<? extends Number> count)
Constructs a label that will a display zero, singular or plural variation based on the value of the specified count model.

Parameters:
id - The wicket:id of the label component. This is will also be used as the message key to look up the message strings in the localized properties file.
count - A number that will be used to choose either the id.zero, id.one or id.many string from the properties file. It will also be made available to the string as an interpolated ${count} variable.
Method Detail

setLink

public CountLabel setLink(Class<? extends Page> page)
Returns:
this to allow chaining
See Also:
CountMessageModel.setLink(Class)

setLink

public CountLabel setLink(Class<? extends Page> page,
                          PageParameters params)
Returns:
this to allow chaining
See Also:
CountMessageModel.setLink(Class,PageParameters)


Copyright © 2011 55 Minutes. All Rights Reserved.