List of usage examples for org.springframework.web.servlet.support BindStatus getEditor
@Nullable
public PropertyEditor getEditor()
From source file:org.hdiv.web.servlet.tags.form.SelectTagHDIV.java
/** * Returns '<code>true</code>' if the bound value requires the * resultant '<code>select</code>' tag to be multi-select. *///w ww .j av a 2 s .c o m private boolean forceMultiple() throws JspException { BindStatus bindStatus = getBindStatus(); Class valueType = bindStatus.getValueType(); if (valueType != null && typeRequiresMultiple(valueType)) { return true; } else if (bindStatus.getEditor() != null) { Object editorValue = bindStatus.getEditor().getValue(); if (editorValue != null && typeRequiresMultiple(editorValue.getClass())) { return true; } } return false; }
From source file:org.hdiv.web.servlet.tags.form.SelectedValueComparatorHDIV.java
/** * Returns <code>true</code> if the supplied candidate value is equal to the value bound to * the supplied {@link BindStatus}. Equality in this case differs from standard Java equality and * is described in more detail <a href="#equality-contract">here</a>. */// w ww.ja va 2 s . co m public static boolean isSelected(BindStatus bindStatus, Object candidateValue) { if (bindStatus == null) { return (candidateValue == null); } // Check obvious equality matches with the candidate first, // both with the rendered value and with the original value. Object boundValue = bindStatus.getValue(); if (ObjectUtils.nullSafeEquals(boundValue, candidateValue)) { return true; } Object actualValue = bindStatus.getActualValue(); if (actualValue != null && actualValue != boundValue && ObjectUtils.nullSafeEquals(actualValue, candidateValue)) { return true; } if (actualValue != null) { boundValue = actualValue; } else if (boundValue == null) { return false; } // Non-null value but no obvious equality with the candidate value: // go into more exhaustive comparisons. boolean selected = false; if (boundValue.getClass().isArray()) { selected = collectionCompare(CollectionUtils.arrayToList(boundValue), candidateValue, bindStatus); } else if (boundValue instanceof Collection) { selected = collectionCompare((Collection) boundValue, candidateValue, bindStatus); } else if (boundValue instanceof Map) { selected = mapCompare((Map) boundValue, candidateValue, bindStatus); } if (!selected) { selected = exhaustiveCompare(boundValue, candidateValue, bindStatus.getEditor(), null); } return selected; }
From source file:org.openmrs.web.taglib.FormatDateTag.java
public int doStartTag() { RequestContext requestContext = (RequestContext) this.pageContext .getAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE); if (date == null && getPath() != null) { try {/*from ww w. j av a 2s.com*/ // get the "path" object from the pageContext String resolvedPath = getPath(); String nestedPath = (String) pageContext.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE); if (nestedPath != null) { resolvedPath = nestedPath + resolvedPath; } BindStatus status = new BindStatus(requestContext, resolvedPath, false); log.debug("status: " + status); if (status.getValue() != null) { log.debug("status.value: " + status.getValue()); if (status.getValue().getClass() == Date.class) { // if no editor was registered all will go well here date = (Date) status.getValue(); } else { // if a "Date" property editor was registerd for the form, the status.getValue() // object will be a java.lang.String. This is useless. Try getting the original // value from the troublesome editor log.debug("status.valueType: " + status.getValueType()); Timestamp timestamp = (Timestamp) status.getEditor().getValue(); date = new Date(timestamp.getTime()); } } } catch (Exception e) { log.warn("Unable to get a date object from path: " + getPath(), e); return SKIP_BODY; } } if (!dateWasSet && date == null) { log.warn("Both 'date' and 'path' cannot be null. Page: " + pageContext.getPage() + " localname:" + pageContext.getRequest().getLocalName() + " rd:" + pageContext.getRequest().getRequestDispatcher("")); return SKIP_BODY; } if (type == null) { type = ""; } DateFormat dateFormat = null; if (format != null && format.length() > 0) { dateFormat = new SimpleDateFormat(format, Context.getLocale()); } else if (type.equals("xml")) { dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Context.getLocale()); } else { log.debug("context locale: " + Context.getLocale()); if (type.equals("long")) { dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Context.getLocale()); } else if (type.equals("medium")) { dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Context.getLocale()); } else { dateFormat = Context.getDateFormat(); } } if (dateFormat == null) { dateFormat = new SimpleDateFormat("MM-dd-yyyy"); } String datestr = ""; try { if (date != null) { if (type.equals("milliseconds")) { datestr = "" + date.getTime(); } else { if (showTodayOrYesterday && (DateUtils.isSameDay(Calendar.getInstance().getTime(), date) || OpenmrsUtil.isYesterday(date))) { //print only time of day but maintaining the format(24 Vs 12) if any was specified String timeFormatString = (format != null && !format.contains("a")) ? "HH:mm" : "h:mm a"; dateFormat = new SimpleDateFormat(timeFormatString); if (DateUtils.isSameDay(Calendar.getInstance().getTime(), date)) { datestr = Context.getMessageSourceService().getMessage("general.today") + " " + dateFormat.format(date); } else { datestr = Context.getMessageSourceService().getMessage("general.yesterday") + " " + dateFormat.format(date); } } else { datestr = dateFormat.format(date); } } } } catch (IllegalArgumentException e) { //format or date is invalid log.error("date: " + date); log.error("format: " + format); log.error(e); datestr = date.toString(); } try { pageContext.getOut().write(datestr); } catch (IOException e) { log.error(e); } // reset the objects to null because taglibs are reused release(); return SKIP_BODY; }