@Override protected void processSubmission(String elementName) { String value = request.getParameter(elementName); tracker.recordInput(this, value); updateClientTimeZone(elementName); Date parsedValue = null; try { if (InternalUtils.isNonBlank(value)) { // Regardless of the timeZone set on the DateFormat, the value is parsed in // the current default TimeZone. Use the calendar to adjust it out. Date inDefaultTimeZone = format.parse(value); parsedValue = convertDateToClientTimeZone(inDefaultTimeZone); } } catch (ParseException ex) { tracker.recordError(this, messages.format("tapx-date-value-not-parseable", value)); return; } try { fieldValidationSupport.validate(parsedValue, resources, validate); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } if (min != null && parsedValue.before(min)) { tracker.recordError(this, messages.get("tapx-date-value-to-early")); return; } if (max != null && parsedValue.after(max)) { tracker.recordError(this, messages.get("tapx-date-value-too-late")); return; } this.value = parsedValue; }
@SuppressWarnings({"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue = toValue(submittedValue); putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); }
/** * Allows the validation decorator to write markup after the field has written all of its markup. * In addition, may invoke the <code>core/fields:showValidationError</code> function to present * the field's error (if it has one) to the user. */ @AfterRender final void afterDecorator() { decorator.afterField(this); String error = validationTracker.getError(this); if (error != null) { javaScriptSupport .require("t5/core/fields") .invoke("showValidationError") .with(assignedClientId, error); } }
/** Renders the options, including the blank option. */ @BeforeRenderTemplate void options(MarkupWriter writer) { selectedClientValue = tracker.getInput(this); // Use the value passed up in the form submission, if available. // Failing that, see if there is a current value (via the value parameter), and // convert that to a client value for later comparison. if (selectedClientValue == null) selectedClientValue = value == null ? null : encoder.toClient(value); if (showBlankOption()) { writer.element("option", "value", ""); writer.write(blankLabel); writer.end(); } SelectModelVisitor renderer = new Renderer(writer); model.visit(renderer); }
public void beginRender(MarkupWriter writer) { String value = tracker.getInput(this); if (value == null) { value = formatCurrentValue(); } String clientId = getClientId(); String triggerId = clientId + "-trigger"; writer.element( "input", "type", hideTextField ? "hidden" : "text", "name", getControlName(), "id", clientId, "value", value); if (isDisabled()) { writer.attributes("disabled", "disabled"); } validate.render(writer); resources.renderInformalParameters(writer); decorateInsideField(); writer.end(); // Now the trigger icon. writer.element( "img", "id", triggerId, "class", "t-calendar-trigger", "src", icon.toClientURL(), "alt", "[Show]"); writer.end(); // img writeTimeZone(writer); JSONObject spec = new JSONObject( "clientId", clientId, "clientDateFormat", formatConverter.convertToClient(format)) .put("time", time) .put("singleClick", singleClick); if (max != null) { spec.put("max", convertDateToClientTimeZone(max).getTime()); } if (min != null) { spec.put("min", convertDateToClientTimeZone(min).getTime()); } javascriptSupport.addInitializerCall("tapxDateField", spec); }
private boolean inError(Field field) { ValidationTracker tracker = environment.peekRequired(ValidationTracker.class); return tracker.inError(field); }