All Implemented Interfaces:
Serializable, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent<Date,DateLabel>, IMetadataContext<Serializable,Component>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable

public class DateLabel extends Label implements IGenericComponent<Date,DateLabel>
A label that is mapped to a java.util.Date object and that uses Joda time to format values.

You can provide a date pattern in two of the constructors. When not provided, DateTimeFormat.shortDate() will be used.

A special option is applyTimeZoneDifference which is an option that says whether to correct for the difference between the client's time zone and server's time zone. This is true by default.

Author:
eelcohillenius
See Also:
  • Constructor Details

    • DateLabel

      public DateLabel(String id, DateConverter converter)
      Construct with a converter.
      Parameters:
      id - The component id
      converter - The converter to use
    • DateLabel

      public DateLabel(String id, IModel<Date> model, DateConverter converter)
      Construct with a converter.
      Parameters:
      id - The component id
      model - The model
      converter - The converter to use
  • Method Details

    • forDatePattern

      public static DateLabel forDatePattern(String id, IModel<Date> model, String datePattern)
      Creates a new DateLabel defaulting to using a short date pattern
      Parameters:
      id - The id of the text field
      model - The model
      datePattern - The pattern to use. Must be not null. See SimpleDateFormat for available patterns.
      Returns:
      new instance
      See Also:
    • forDatePattern

      public static DateLabel forDatePattern(String id, String datePattern)
      Creates a new DateLabel defaulting to using a short date pattern
      Parameters:
      id - The id of the text field
      datePattern - The pattern to use. Must be not null. See SimpleDateFormat for available patterns.
      Returns:
      new instance
      See Also:
    • forDateStyle

      public static DateLabel forDateStyle(String id, IModel<Date> model, String dateStyle)
      Creates a new DateLabel defaulting to using a short date pattern
      Parameters:
      id - The id of the text field
      model - The model
      dateStyle - style to use in case no pattern is provided. Must be two characters from the set {"S", "M", "L", "F", "-"}. Must be not null. See DateTimeFormat.forStyle(String) for options.
      Returns:
      new instance
      See Also:
    • forDateStyle

      public static DateLabel forDateStyle(String id, String dateStyle)
      Creates a new DateLabel defaulting to using a short date pattern
      Parameters:
      id - The id of the text field
      dateStyle - style to use in case no pattern is provided. Must be two characters from the set {"S", "M", "L", "F", "-"}. Must be not null. See DateTimeFormat.forStyle(String) for options.
      Returns:
      new instance
      See Also:
    • forShortStyle

      public static DateLabel forShortStyle(String id)
      Creates a new DateLabel defaulting to using a short date pattern
      Parameters:
      id - The id of the text field
      Returns:
      new instance
      See Also:
    • forShortStyle

      public static DateLabel forShortStyle(String id, IModel<Date> model)
      Creates a new DateLabel defaulting to using a short date pattern
      Parameters:
      id - The id of the text field
      model - The model
      Returns:
      new instance
      See Also:
    • withConverter

      public static DateLabel withConverter(String id, DateConverter converter)
      Creates a new DateLabel using the provided converter.
      Parameters:
      id - The id of the text field
      converter - the date converter
      Returns:
      new instance
      See Also:
    • withConverter

      public static DateLabel withConverter(String id, IModel<Date> model, DateConverter converter)
      Creates a new DateLabel using the provided converter.
      Parameters:
      id - The id of the text field
      model - The model
      converter - the date converter
      Returns:
      new instance
      See Also:
    • getAfter

      public String getAfter()
      Returns:
      after append to label or null
    • getBefore

      public String getBefore()
      Returns:
      before prepend to label or null
    • createConverter

      protected IConverter<?> createConverter(Class<?> type)
      Returns the specialized converter.
      Overrides:
      createConverter in class Component
    • setAfter

      public void setAfter(String after)
      Parameters:
      after - append to label
    • setBefore

      public void setBefore(String before)
      Parameters:
      before - prepend to label
    • onComponentTagBody

      public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
      Overrides:
      onComponentTagBody in class Label