public Date getFromDate() { if (fromDate != null && fromDate.getDate() != null) { return fromDate.getDate(); } else { return null; } }
public Date getToDate() { if (toDate != null && toDate.getDate() != null) { return toDate.getDate(); } else { return null; } }
@Override protected void initForm( FormItemContainer formLayout, Controller listener, final UserRequest ureq) { titleContainer = FormLayoutContainer.createHorizontalFormLayout("titleLayout", getTranslator()); formLayout.add(titleContainer); // spacer formLayout.add(new SpacerElementImpl("spacer1")); long defaultWeekRange = numDaysRange_ * 24 * 60 * 60 * 1000; // from date fromDate = new JSDateChooser( "fromDate", new Date(new Date().getTime() - defaultWeekRange), getLocale()); fromDate.setLabel("datechooser.bdate", null); fromDate.setExampleKey("datechooser.example.bdate", null); fromDate.setDisplaySize(fromDate.getExampleDateString().length()); formLayout.add(fromDate); // end date toDate = new JSDateChooser("toDate", new Date(), getLocale()); toDate.setLabel("datechooser.edate", null); toDate.setExampleKey("datechooser.example.edate", null); toDate.setDisplaySize(toDate.getExampleDateString().length()); formLayout.add(toDate); // submit button subm = new FormSubmit("subm", "datechooser.generate"); formLayout.add(subm); formLayout.add(new SpacerElementImpl("spacer2")); }
@Override @SuppressWarnings("unused") protected boolean validateFormLogic(UserRequest ureq) { boolean retVal = true; // datefields are valid // check complex rules involving checks over multiple elements Date fromDateVal = fromDate.getDate(); Date toDateVal = toDate.getDate(); if (!fromDate.hasError() && !toDate.hasError()) { // check valid dates // if both are set, check from < to if (fromDateVal != null && toDateVal != null) { /* * bugfix http://bugs.olat.org/jira/browse/OLAT-813 valid dates and not * empty, in easy mode we assume that Start and End date should * implement the meaning of * ----false---|S|-----|now|-TRUE---------|E|---false--->t ............. * Thus we check for Startdate < Enddate, error otherwise */ if (fromDateVal.after(toDateVal)) { fromDate.setTranslator( Util.createPackageTranslator( org.olat.course.condition.Condition.class, ureq.getLocale(), fromDate.getTranslator())); fromDate.setErrorKey("form.easy.error.bdateafteredate", null); retVal = false; } } else { if (fromDateVal == null && !fromDate.isEmpty()) { // not a correct begin date fromDate.setTranslator( Util.createPackageTranslator( org.olat.course.condition.Condition.class, ureq.getLocale(), fromDate.getTranslator())); fromDate.setErrorKey("form.easy.error.bdate", null); retVal = false; } if (toDateVal == null && !toDate.isEmpty()) { toDate.setTranslator( Util.createPackageTranslator( org.olat.course.condition.Condition.class, ureq.getLocale(), toDate.getTranslator())); toDate.setErrorKey("form.easy.error.edate", null); retVal = false; } } } return retVal; }