/** * Factory method for create a new {@link DateTimeField}. * * @param id * the id * @param model * the model * @return the {@link DateTimeField}. */ public static DateTimeField newDateTimeField(final String id, final IModel<Date> model) { final DateTimeField dateTextField = new DateTimeField(id, model); dateTextField.setOutputMarkupId(true); return dateTextField; }
@Override protected void configure(final Map<String, Object> widgetProperties, final IHeaderResponse response, final Map<String, Object> initVariables) { super.configure(widgetProperties, response, initVariables); DateTimeField.this.configure(widgetProperties); } };
/** * Checks whether the current {@link Locale} uses the 12h or 24h time format. This method can be * overridden to e.g. always use 24h format. * * @return true, if the current {@link Locale} uses the 12h format.<br/> * false, otherwise */ protected boolean use12HourFormat() { String pattern = DateTimeFormat.patternForStyle("-S", getLocale()); return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1 || pattern.indexOf('K') != -1; }
/** * @return either 12 or 24, depending on the hour format of the current {@link Locale} */ private int getMaximumHours() { return getMaximumHours(use12HourFormat()); }
setType(Date.class); add(dateField = newDateTextField(DATE, dateFieldModel)); dateField.add(newDatePicker()); add(hoursField = newHoursTextField(HOURS, new PropertyModel<Integer>(this, HOURS), Integer.class)); add(minutesField = newMinutesTextField(MINUTES, new PropertyModel<Integer>(this, MINUTES), Integer.class)); add(amOrPmChoice = new DropDownChoice<AM_PM>(AM_OR_PM_CHOICE, new PropertyModel<AM_PM>( this, AM_OR_PM), Arrays.asList(AM_PM.values()))); add(new WebMarkupContainer("hoursSeparator")
DateTimeZone.forTimeZone(getClientTimeZone())); if (use12HourFormat()) setConvertedInput(newDateInstance(date.getMillis())); DateTimeField.this.error(e.getMessage()); invalid();
protected void onBeforeRender() dateField.setRequired(isRequired()); hoursField.setRequired(isRequired()); minutesField.setRequired(isRequired()); boolean use12HourFormat = use12HourFormat(); amOrPmChoice.setVisible(use12HourFormat); Date modelObject = (Date)getDefaultModelObject(); if (modelObject == null) TimeZone zone = getClientTimeZone(); if (zone != null)
@Override public void convertInput() { Date modelObject = (Date)getDefaultModelObject(); getDateTextField().setConvertedInput(modelObject != null ? modelObject : newDateInstance()); super.convertInput(); }
/** * create a new {@link TextField} instance for hours to be added to this panel. * * @param id * the component id * @param model * model that should be used by the {@link TextField} * @param type * the type of the text field * @return a new text field instance */ protected TextField<Integer> newHoursTextField(final String id, IModel<Integer> model, Class<Integer> type) { TextField<Integer> hoursTextField = new TextField<>(id, model, type); hoursTextField.add(getMaximumHours() == 24 ? RangeValidator.range(0, 23) : RangeValidator .range(1, 12)); hoursTextField.setLabel(new Model<>(HOURS)); return hoursTextField; }
/** * Instantiates a new {@link LabeledDateTimeFieldPanel}. * * @param id * the id * @param model * the model * @param labelModel * the label model */ public LabeledDateTimeFieldPanel(final String id, final IModel<M> model, final IModel<String> labelModel) { super(id, model, labelModel); setOutputMarkupId(true); add(dateTimeField = newDateTimeField("dateTimeField", model)); add(feedback = newComponentFeedbackPanel("feedback", dateTimeField)); final String markupId = dateTimeField.getMarkupId(); add(label = newLabel("label", markupId, getLabel())); }
setType(Date.class); add(dateField = newDateTextField(DATE, dateFieldModel)); dateField.add(newDatePicker()); add(hoursField = newHoursTextField(HOURS, new PropertyModel<Integer>(this, HOURS), Integer.class)); add(minutesField = newMinutesTextField(MINUTES, new PropertyModel<Integer>(this, MINUTES), Integer.class)); add(amOrPmChoice = new DropDownChoice<AM_PM>(AM_OR_PM_CHOICE, new PropertyModel<AM_PM>( this, AM_OR_PM), Arrays.asList(AM_PM.values()))); add(new WebMarkupContainer("hoursSeparator")
DateTimeZone.forTimeZone(getClientTimeZone())); if (use12HourFormat()) setConvertedInput(newDateInstance(date.getMillis())); DateTimeField.this.error(e.getMessage()); invalid();
protected void onBeforeRender() dateField.setRequired(isRequired()); hoursField.setRequired(isRequired()); minutesField.setRequired(isRequired()); boolean use12HourFormat = use12HourFormat(); amOrPmChoice.setVisible(use12HourFormat); Date modelObject = (Date)getDefaultModelObject(); if (modelObject == null) TimeZone zone = getClientTimeZone(); if (zone != null)
/** * @return either 12 or 24, depending on the hour format of the current {@link Locale} */ private int getMaximumHours() { return getMaximumHours(use12HourFormat()); }
@Override public void convertInput() { Date modelObject = (Date)getDefaultModelObject(); getDateTextField().setConvertedInput(modelObject != null ? modelObject : newDateInstance()); super.convertInput(); }
/** * create a new {@link TextField} instance for hours to be added to this panel. * * @param id * the component id * @param model * model that should be used by the {@link TextField} * @param type * the type of the text field * @return a new text field instance */ protected TextField<Integer> newHoursTextField(final String id, IModel<Integer> model, Class<Integer> type) { TextField<Integer> hoursTextField = new TextField<>(id, model, type); hoursTextField.add(getMaximumHours() == 24 ? RangeValidator.range(0, 23) : RangeValidator .range(1, 12)); hoursTextField.setLabel(new Model<>(HOURS)); return hoursTextField; }
/** * Instantiates a new {@link LabeledDateTimeFieldPanel}. * * @param id * the id * @param model * the model * @param labelModel * the label model */ public LabeledDateTimeFieldPanel(final String id, final IModel<M> model, final IModel<String> labelModel) { super(id, model, labelModel); setOutputMarkupId(true); add(dateTimeField = newDateTimeField("dateTimeField", model)); add(feedback = newComponentFeedbackPanel("feedback", dateTimeField)); final String markupId = dateTimeField.getMarkupId(); add(label = newLabel("label", markupId, getLabel())); }
/** * Factory method for create a new {@link DateTimeField}. * * @param id * the id * @param model * the model * @return the {@link DateTimeField}. */ public static DateTimeField newDateTimeField(final String id, final IModel<Date> model) { final DateTimeField dateTextField = new DateTimeField(id, model); dateTextField.setOutputMarkupId(true); return dateTextField; }
@Override protected void configure(final Map<String, Object> widgetProperties, final IHeaderResponse response, final Map<String, Object> initVariables) { super.configure(widgetProperties, response, initVariables); DateTimeField.this.configure(widgetProperties); } };
/** * Checks whether the current {@link Locale} uses the 12h or 24h time format. This method can be * overridden to e.g. always use 24h format. * * @return true, if the current {@link Locale} uses the 12h format.<br/> * false, otherwise */ protected boolean use12HourFormat() { String pattern = DateTimeFormat.patternForStyle("-S", getLocale()); return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1 || pattern.indexOf('K') != -1; }