List of usage examples for org.apache.wicket.util.lang Objects longValue
public static long longValue(final Object value) throws NumberFormatException
From source file:org.wicketstuff.datetime.extensions.yui.calendar.DatePicker.java
License:Apache License
/** * {@inheritDoc}/* www.j av a 2 s . co m*/ */ @Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); if (includeYUILibraries()) { YuiLib.load(response); } renderHeadInit(response); // variables for the initialization script Map<String, Object> variables = new HashMap<>(); String widgetId = getEscapedComponentMarkupId(); variables.put("componentId", getComponentMarkupId()); variables.put("widgetId", widgetId); variables.put("datePattern", getDatePattern()); variables.put("fireChangeEvent", notifyComponentOnDateSelected()); variables.put("alignWithIcon", alignWithIcon()); variables.put("hideOnSelect", hideOnSelect()); variables.put("showOnFieldClick", showOnFieldClick()); variables.put("autoHide", autoHide()); variables.put("closeLabel", closeLabel()); String script = getAdditionalJavaScript(); if (script != null) { variables.put("additionalJavascript", Strings.replaceAll(script, "${calendar}", "YAHOO.wicket." + widgetId + "DpJs")); } // print out the initialization properties Map<String, Object> p = new LinkedHashMap<>(); configure(p, response, variables); if (!p.containsKey("navigator") && enableMonthYearSelection()) { p.put("navigator", Boolean.TRUE); } if (enableMonthYearSelection() && p.containsKey("pages") && Objects.longValue(p.get("pages")) > 1) { throw new IllegalStateException("You cannot use a CalendarGroup with month/year selection!"); } // ${calendarInit} StringBuilder calendarInit = new StringBuilder(); appendMapping(p, calendarInit); variables.put("calendarInit", calendarInit.toString()); // render initialization script with the variables interpolated TextTemplate datePickerJs = new PackageTextTemplate(DatePicker.class, "DatePicker.js"); datePickerJs.interpolate(variables); response.render(OnDomReadyHeaderItem.forScript(datePickerJs.asString())); // remove previously generated markup (see onRendered) via javascript in // ajax requests to not render the yui calendar multiple times component.getRequestCycle().find(IPartialPageRequestHandler.class).ifPresent(target -> { String escapedComponentMarkupId = getEscapedComponentMarkupId(); String javascript = "var e = Wicket.$('" + escapedComponentMarkupId + "Dp" + "'); if (e != null && typeof(e.parentNode) != 'undefined' && " + "typeof(e.parentNode.parentNode != 'undefined')) {" + "e.parentNode.parentNode.removeChild(e.parentNode);" + "YAHOO.wicket." + escapedComponentMarkupId + "DpJs.destroy(); delete YAHOO.wicket." + escapedComponentMarkupId + "DpJs;}"; target.prependJavaScript(javascript); }); }