List of usage examples for org.apache.wicket.ajax AjaxRequestTarget getHeaderResponse
IHeaderResponse getHeaderResponse();
From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.MultiUpdatingTimerBehavior.java
License:Apache License
/** * /* w ww. j a v a 2s. c o m*/ * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(AjaxRequestTarget) */ @Override protected final void respond(final AjaxRequestTarget target) { if (!isStopped() && isEnabled(getComponent())) { onTimer(target); target.getHeaderResponse().render(OnLoadHeaderItem.forScript(getJsTimeoutCall(updateInterval))); } }
From source file:com.googlecode.wickedcharts.showcase.options.WicketSplineUpdatingOptions.java
License:Apache License
private LiveDataSeries createSeries(final List<Point> data) { LiveDataSeries series = new LiveDataSeries(this, 1000) { private static final long serialVersionUID = 1L; @Override// www . j av a2s. c om public Point update(final LiveDataUpdateEvent event) { JavaScriptParameters params = event.getParameters(); System.out.println(params.getParameterValue("currentTime")); // switch color depending on y-value double yValue = Math.random(); String newColor; if (yValue > 0.5d) { newColor = "#00ff00"; } else { newColor = "#ff0000"; } Point point = new Point(); point.setX(new Date().getTime()); point.setY(yValue); point.setMarker(new Marker().setFillColor(HexColor.fromString(newColor))); // update color of series via javascript AjaxRequestTarget target = ((WicketLiveDataUpdateEvent) event).getAjaxRequestTarget(); target.getHeaderResponse().render(OnDomReadyHeaderItem.forScript( event.getJavascriptChartName() + ".series[0].graph.attr('stroke', '" + newColor + "');")); return point; } }; series.addJavaScriptParameter("currentTime", "new Date()"); series.setData(data); series.setName("Random Data"); return series; }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.java
License:Open Source License
@SuppressWarnings("nls") public static void generateResponse(final AjaxRequestTarget target, Page page) { WebClientSession webClientSession = WebClientSession.get(); if (target != null && page instanceof MainPage && webClientSession != null && webClientSession.getWebClient() != null && webClientSession.getWebClient().getSolution() != null) { if (target instanceof CloseableAjaxRequestTarget && ((CloseableAjaxRequestTarget) target).isClosed()) { return; }//from w w w . ja v a2 s. com // do executed the events for before generating the response. webClientSession.getWebClient().executeEvents(); if (webClientSession.getWebClient() == null || webClientSession.getWebClient().getSolution() == null) { // how can web client be null here ? return; } final MainPage mainPage = ((MainPage) page); if (mainPage.getPageMap() instanceof ModifiedAccessStackPageMap) { // at every request mark the pagemap as dirty so lru eviction really works ((ModifiedAccessStackPageMap) mainPage.getPageMap()).flagDirty(); } // If the main form is switched then do a normal redirect. if (mainPage.isMainFormSwitched()) { mainPage.versionPush(); RequestCycle.get().setResponsePage(page); } else { page.visitChildren(WebTabPanel.class, new Component.IVisitor<WebTabPanel>() { public Object component(WebTabPanel component) { component.initalizeFirstTab(); return IVisitor.CONTINUE_TRAVERSAL; } }); mainPage.addWebAnchoringInfoIfNeeded(); final Set<WebCellBasedView> tableViewsToRender = new HashSet<WebCellBasedView>(); final List<String> valueChangedIds = new ArrayList<String>(); final List<String> invalidValueIds = new ArrayList<String>(); final Map<WebCellBasedView, List<Integer>> tableViewsWithChangedRowIds = new HashMap<WebCellBasedView, List<Integer>>(); // first, get all invalidValue & valueChanged components page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() { public Object component(Component component) { if (component instanceof IDisplayData && !((IDisplayData) component).isValueValid()) { invalidValueIds.add(component.getMarkupId()); } if (((IProviderStylePropertyChanges) component).getStylePropertyChanges() .isValueChanged()) { if (component.getParent().isVisibleInHierarchy()) { // the component will get added to the target & rendered only if it's parent is visible in hierarchy because changed flag is also set (see the visitor below) // so we will only list these components if they are visible otherwise ajax timer could end up sending hundreds of id's that don't actually render every 5 seconds // because the valueChanged flag is cleared only by onRender valueChangedIds.add(component.getMarkupId()); if (component instanceof MarkupContainer) { ((MarkupContainer) component).visitChildren(IDisplayData.class, new IVisitor<Component>() { public Object component(Component comp) { // labels/buttons that don't display data are not changed if (!(comp instanceof ILabel)) { valueChangedIds.add(comp.getMarkupId()); } return CONTINUE_TRAVERSAL; } }); } } } return CONTINUE_TRAVERSAL; } }); // add changed components to target; if a component is changed, the change check won't go deeper in hierarchy page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() { public Object component(Component component) { if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) { if (component.getParent().isVisibleInHierarchy()) { target.addComponent(component); generateDragAttach(component, target.getHeaderResponse()); WebForm parentForm = component.findParent(WebForm.class); boolean isDesignMode = parentForm != null && parentForm.isDesignMode(); if (!component.isVisible() || (component instanceof WrapperContainer && !((WrapperContainer) component).getDelegate().isVisible())) { ((IProviderStylePropertyChanges) component).getStylePropertyChanges() .setRendered(); if (isDesignMode) { target.appendJavascript("Servoy.ClientDesign.hideSelected('" + component.getMarkupId() + "')"); } } else { if (isDesignMode) { target.appendJavascript("Servoy.ClientDesign.refreshSelected('" + component.getMarkupId() + "')"); } // some components need to perform js layout tasks when their markup is replaced when using anchored layout mainPage.getPageContributor().markComponentForAnchorLayoutIfNeeded(component); } ListItem<IRecordInternal> row = component.findParent(ListItem.class); if (row != null) { WebCellBasedView wcbv = row.findParent(WebCellBasedView.class); if (wcbv != null) { if (tableViewsWithChangedRowIds.get(wcbv) == null) { tableViewsWithChangedRowIds.put(wcbv, new ArrayList<Integer>()); } List<Integer> ids = tableViewsWithChangedRowIds.get(wcbv); int changedRowIdx = wcbv.indexOf(row); if (changedRowIdx >= 0 && !ids.contains(changedRowIdx)) { ids.add(changedRowIdx); } } } } return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; } else if (component instanceof WebCellBasedView) tableViewsToRender.add((WebCellBasedView) component); return component.isVisible() ? IVisitor.CONTINUE_TRAVERSAL : IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; } }); page.visitChildren(IComponentToRequestAttacher.class, new Component.IVisitor<Component>() { public Object component(Component component) { ((IComponentToRequestAttacher) component).attachComponents(target); return IVisitor.CONTINUE_TRAVERSAL; } }); final List<String> visibleEditors = new ArrayList<String>(); page.visitChildren(WebDataHtmlArea.class, new Component.IVisitor<Component>() { public Object component(Component component) { visibleEditors.add(((WebDataHtmlArea) component).getEditorID()); return IVisitor.CONTINUE_TRAVERSAL; } }); StringBuffer argument = new StringBuffer(); for (String id : visibleEditors) { argument.append("\""); argument.append(id); argument.append("\""); if (visibleEditors.indexOf(id) != visibleEditors.size() - 1) { argument.append(","); } } target.prependJavascript("Servoy.HTMLEdit.removeInvalidEditors(" + argument + ");"); String rowSelectionScript, columnResizeScript; for (final WebCellBasedView wcbv : tableViewsToRender) { if (wcbv.isScrollMode()) wcbv.scrollViewPort(target, true); wcbv.updateRowSelection(target); List<Integer> changedIds = tableViewsWithChangedRowIds.get(wcbv); List<Integer> selectedIndexesChanged = wcbv.getIndexToUpdate(false); List<Integer> mergedIds = selectedIndexesChanged != null ? selectedIndexesChanged : new ArrayList<Integer>(); if (changedIds != null) { for (Integer id : changedIds) { if (!mergedIds.contains(id)) { mergedIds.add(id); } } } rowSelectionScript = wcbv.getRowSelectionScript(mergedIds); wcbv.clearSelectionByCellActionFlag(); if (rowSelectionScript != null) target.appendJavascript(rowSelectionScript); columnResizeScript = wcbv.getColumnResizeScript(); if (columnResizeScript != null) target.appendJavascript(columnResizeScript); } // double check if the page contributor is changed, because the above IStylePropertyChanges ischanged could have altered it. if (mainPage.getPageContributor().getStylePropertyChanges().isChanged()) { target.addComponent((Component) mainPage.getPageContributor()); } if (invalidValueIds.size() == 0) { target.appendJavascript("setValidationFailed(null);"); //$NON-NLS-1$ } else { target.appendJavascript("setValidationFailed('" + invalidValueIds.get(0) + "');"); //$NON-NLS-1$ } Component comp = mainPage.getAndResetToFocusComponent(); if (comp != null) { if (comp instanceof WebDataHtmlArea) { target.appendJavascript("tinyMCE.activeEditor.focus()"); } else { target.focusComponent(comp); } } else if (mainPage.getAndResetMustFocusNull()) { // This is needed for example when showing a non-modal dialog in IE7 (or otherwise // the new window would be displayed in the background). target.focusComponent(null); } if (valueChangedIds.size() > 0) { argument = new StringBuffer(); for (String id : valueChangedIds) { argument.append("\""); argument.append(id); argument.append("\""); if (valueChangedIds.indexOf(id) != valueChangedIds.size() - 1) { argument.append(","); } } target.prependJavascript("storeValueAndCursorBeforeUpdate(" + argument + ");"); target.appendJavascript("restoreValueAndCursorAfterUpdate();"); } //if we have admin info, show it String adminInfo = mainPage.getAdminInfo(); if (adminInfo != null) { adminInfo = Utils.stringReplace(adminInfo, "\r", ""); adminInfo = Utils.stringReplace(adminInfo, "\n", "\\n"); target.appendJavascript("alert('Servoy admin info : " + adminInfo + "');"); } // If we have a status text, set it. String statusText = mainPage.getStatusText(); if (statusText != null) { target.appendJavascript("setStatusText('" + statusText + "');"); } String show = mainPage.getShowUrlScript(); if (show != null) { target.appendJavascript(show); } mainPage.renderJavascriptChanges(target); if (((WebClientInfo) webClientSession.getClientInfo()).getProperties().isBrowserInternetExplorer() && ((WebClientInfo) webClientSession.getClientInfo()).getProperties() .getBrowserVersionMajor() < 9) { target.appendJavascript("Servoy.Utils.checkWebFormHeights();"); } try { if (isStyleSheetLimitForIE(page.getSession())) { target.appendJavascript("testStyleSheets();"); } } catch (Exception e) { Debug.error(e);//cannot retrieve session/clientinfo/properties? target.appendJavascript("testStyleSheets();"); } } } }
From source file:com.servoy.j2db.server.headlessclient.DivWindow.java
License:Open Source License
public static void deleteStoredBounds(AjaxRequestTarget target, String dialogName) { target.getHeaderResponse().renderJavascriptReference(JAVA_SCRIPT); target.appendJavascript("Wicket.DivWindow.deletePosition(\"" + dialogName + "\");"); }
From source file:com.socialsite.BasePanel.java
License:Open Source License
/** * fires a event with the collection of all the updated dom elements after * the wicket ajax response. To subscribe the event call the * <code>SocialSite.Ajax.registerPostAjax</code>. Your callback function * will be called with a jQuery Wrapped set of all the update dom as the * first argument./*from w w w.j ava 2 s. com*/ * * NOTE: call this only once after all the components are added to the * target * * * @param target * ajax target */ public void firePostAjaxUpdateEvent(final AjaxRequestTarget target) { final StringBuffer script = new StringBuffer(" SocialSite.Ajax.handle(["); for (final Component component : target.getComponents()) { script.append("\"" + component.getMarkupId() + "\","); } script.append("])"); target.getHeaderResponse().renderOnDomReadyJavascript(script.toString()); }
From source file:org.artifactory.webapp.wicket.behavior.AbstractAjaxRestartableTimerBehavior.java
License:Apache License
/** * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget) *///from ww w . j a v a2 s. c om @Override protected final void respond(final AjaxRequestTarget target) { onTimer(target); if (!stopped && isEnabled(getComponent())) { target.getHeaderResponse().renderOnLoadJavaScript(getJsTimeoutCall(updateInterval)); } }
From source file:org.hippoecm.frontend.dialog.ButtonWrapper.java
License:Apache License
public void setEnabled(boolean isset) { enabled = isset;/*from w w w.j a va2s. c om*/ if (button != null && WebApplicationHelper.isPartOfPage(button)) { button.setEnabled(isset); if (ajax) { AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { if (!isset) { renderAttribute(target, "disabled", "disabled"); } else { target.appendJavaScript( "Wicket.$('" + button.getMarkupId() + "').removeAttribute('disabled')"); for (Behavior behavior : button.getBehaviors()) { ComponentTag tag = new ComponentTag("button", XmlTag.TagType.OPEN_CLOSE); behavior.onComponentTag(button, tag); behavior.renderHead(button, target.getHeaderResponse()); for (Map.Entry<String, Object> entry : tag.getAttributes().entrySet()) { renderAttribute(target, entry.getKey(), entry.getValue()); } } } } } } }
From source file:org.hippoecm.frontend.dialog.DialogWindow.java
License:Apache License
/** * Shows the modal window./*from w w w . j a v a 2s . c o m*/ * * @param target Request target associated with current ajax request. */ public void show(final AjaxRequestTarget target) { if (!super.isShown()) { getContent().setVisible(true); target.add(this); target.getHeaderResponse().render(OnDomReadyHeaderItem.forScript(getWindowOpenJavaScript())); } }
From source file:org.hippoecm.frontend.plugins.richtext.dialog.AbstractRichTextEditorDialog.java
License:Apache License
@Override public void onClose() { final RichTextEditorAction<T> action = cancelled ? cancelAction : closeAction; if (action != null) { final String script = action.getJavaScript(getModelObject()); if (StringUtils.isNotBlank(script)) { AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { target.getHeaderResponse().render(OnDomReadyHeaderItem.forScript(script)); }//from w w w . j av a 2s . c o m } } super.onClose(); }
From source file:org.hippoecm.frontend.widgets.AutoCompleteTextFieldWidget.java
License:Apache License
@Override protected void onRemove() { final AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { final String containerId = getMarkupId() + "-autocomplete-container"; // Remove element and add a second check after 1 second which ensures the element is also removed if // the AutoCompleteTextFieldWidget is used in a dialog that is closed by pressing ESC while the // AutoComplete is starting to render. final String js = String.format("if (jQuery) { " + "jQuery('#%s').remove(); " + "window.setTimeout(function() { " + "jQuery('#%s').remove() " + "}, 1000); " + "}", containerId, containerId); target.getHeaderResponse().render(OnLoadHeaderItem.forScript(js)); }/*from w w w. ja v a 2 s . co m*/ super.onRemove(); }