List of usage examples for org.apache.wicket.ajax AjaxRequestTarget appendJavaScript
void appendJavaScript(CharSequence javascript);
If the javascript needs to do something asynchronously (i.e.
From source file:org.hippoecm.frontend.service.popup.AjaxPopupService.java
License:Apache License
@Override public void openPopupWindow(final PopupSettings popupSettings, final String url) { if (url == null) { return;//w w w . j a va2 s . c om } AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { popupSettings.setTarget("'" + url + "'"); StringBuffer javascript = new StringBuffer(); javascript.append("(function() {"); javascript.append(getPopupBlockerDetectionScript()); javascript.append(popupSettings.getPopupJavaScript()); javascript.append("})();"); target.appendJavaScript(javascript.toString()); } }
From source file:org.hippoecm.frontend.usagestatistics.UsageEvent.java
License:Apache License
public void publish() { final AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { target.appendJavaScript(getJavaScript()); }/*from w w w .ja va 2 s . c om*/ }
From source file:org.jabylon.log.viewer.pages.LogViewerPage.java
License:Open Source License
@Override protected void construct() { super.construct(); final TextArea<String> nextLog = new TextArea<String>("nextLog", logcontent); add(nextLog);/*from ww w . java 2 s .c o m*/ nextLog.setOutputMarkupId(true); nextLog.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) { private static final long serialVersionUID = 4831467550166004945L; @Override protected void onPostProcessTarget(AjaxRequestTarget target) { super.onPostProcessTarget(target); String chunk = readChunk(40); if (chunk == null) chunk = ""; logcontent.setObject(chunk); target.appendJavaScript("updateLog();"); target.add(nextLog); } }); final DropDownChoice<LogLevel> logLevel = new DropDownChoice<LogLevel>("loglevel", new EnumSetList(), new LogLevelRenderer()); logLevel.setModel(Model.of(LogbackUtil.getLogLevel())); logLevel.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -4582780686636922915L; protected void onUpdate(AjaxRequestTarget target) { LogbackUtil.setLogLevel(logLevel.getModelObject()); } }); add(logLevel); File logFile = new File(LogbackUtil.getLogFiles().get(0).getLocation()); add(new DownloadLink("dowloadLog", logFile)); }
From source file:org.jabylon.rest.ui.wicket.pages.GenericPage.java
License:Open Source License
@Override public void showFeedback(AjaxRequestTarget target) { target.add(feedbackPanel);//from w w w . j a v a 2s . co m target.appendJavaScript("$('#" + feedbackPanel.getMarkupId() + "').addClass('ajax')" + ".clearQueue().show().slideDown().delay(5000).slideUp().end().hide();"); }
From source file:org.jaulp.wicket.behaviors.AjaxDownloadBehavior.java
License:Apache License
/** * Call this method to initiate the download. * //from w w w. j av a2 s. co m * @param target * the {@link AjaxRequestTarget} */ public void initiate(AjaxRequestTarget target) { String url = getCallbackUrl().toString(); if (antiCache) { url = url + (url.contains("?") ? "&" : "?"); url = url + "antiCache=" + System.currentTimeMillis(); } // the timeout is needed to let Wicket release the channel target.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);"); }
From source file:org.jaulp.wicket.data.provider.examples.refreshingview.ModalDialogWithStylePanel.java
License:Apache License
public ModalDialogWithStylePanel(String id) { super(id);/*from ww w . ja v a 2 s . c om*/ final ModalWindow modal = new ModalWindow("modal"); modal.setCssClassName("w_vegas"); modal.setTitle("Trivial Modal"); AjaxLink<Void> modalLink = new AjaxLink<Void>("modalLink") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { target.appendJavaScript("var originalStyle = $('.wicket-modal').attr('style');" + "$('.wicket-modal').attr('style', originalStyle + 'opacity: 0.5;');"); } }; Fragment modalFragment = new Fragment(modal.getContentId(), "modalContent", this); modalFragment.add(modalLink); modal.setContent(modalFragment); add(modal); add(new AjaxLink<Void>("openModal") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { modal.show(target); } }); }
From source file:org.lbogdanov.poker.web.page.IndexPage.java
License:Apache License
/** * Creates a new instance of <code>Index</code> page. *///w w w. j av a 2s. c o m @SuppressWarnings("unchecked") public IndexPage() { WebMarkupContainer session = new WebMarkupContainer("session"); WebMarkupContainer login = new WebMarkupContainer("login") { @Override protected void onConfigure() { super.onConfigure(); setVisible(userService.getCurrentUser() == null); } }; Form<?> internal = new StatelessForm<Credentials>("internal", new CompoundPropertyModel<Credentials>(new Credentials())); MarkupContainer usernameGroup = new ControlGroup("usernameGroup"); MarkupContainer passwordGroup = new ControlGroup("passwordGroup"); MarkupContainer rememberGroup = new ControlGroup("rememberGroup"); internal.add(new BootstrapFeedbackPanel("feedback"), usernameGroup.add(new RequiredTextField<String>("username") .setLabel(new ResourceModel("login.internal.username"))), passwordGroup.add( new PasswordTextField("password").setLabel(new ResourceModel("login.internal.password"))), rememberGroup.add(new CheckBox("rememberme"), new AjaxFallbackButton("submit", internal) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { Credentials credentials = (Credentials) form.getModelObject(); // TODO Atmosphere issue // getSession().replaceSession(); try { userService.login(credentials.username, credentials.password, credentials.rememberme); if (target != null) { target.appendJavaScript("$('#crsl').carousel({interval: false}).carousel('next');"); target.add(getNavBar()); } } catch (RuntimeException re) { LOGGER.info("Authentication error", re); form.error(IndexPage.this.getString("login.internal.authError")); if (target != null) { target.add(form); } } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { if (target != null) { target.add(form); } } })); IModel<Game> gameModel = new CompoundPropertyModel<Game>(new Game()); IValidator<String> codeValidator = new IValidator<String>() { @Override public void validate(IValidatable<String> validatable) { String code = validatable.getValue(); if (!sessionService.exists(code)) { ValidationError error = new ValidationError(); error.addKey("session.join.invalidCode").setVariable("code", code); validatable.error(error); } } }; Form<?> join = new Form<Game>("join", gameModel); MarkupContainer codeGroup = new ControlGroup("codeGroup").add(new AjaxFallbackButton("submit", join) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { Game game = (Game) form.getModelObject(); setResponsePage(SessionPage.class, new PageParameters().add("code", game.code)); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { if (target != null) { target.add(form); } } }); join.add(new BootstrapFeedbackPanel("feedback"), codeGroup.add(new RequiredTextField<String>("code").setLabel(new ResourceModel("session.join.code")) .add(maximumLength(SESSION_CODE_MAX_LENGTH), codeValidator))); IValidator<String> estimatesValidator = new IValidator<String>() { @Override public void validate(IValidatable<String> validatable) { try { Duration.parse(validatable.getValue()); } catch (IllegalArgumentException e) { ValidationError error = new ValidationError(); error.addKey("session.create.estimates.invalidEstimate").setVariable("estimate", e.getMessage()); validatable.error(error); } } }; Form<?> create = new Form<Game>("create", gameModel); MarkupContainer nameGroup = new ControlGroup("nameGroup"); MarkupContainer estimatesGroup = new ControlGroup("estimatesGroup"); MarkupContainer descriptionGroup = new ControlGroup("descriptionGroup"); create.add(new BootstrapFeedbackPanel("feedback"), nameGroup.add(new RequiredTextField<String>("name") .setLabel(new ResourceModel("session.create.name")).add(maximumLength(SESSION_NAME_MAX_LENGTH))), estimatesGroup.add(new RequiredTextField<String>("estimates") .setLabel(new ResourceModel("session.create.estimates")) .add(maximumLength(SESSION_ESTIMATES_MAX_LENGTH), estimatesValidator)), descriptionGroup.add(new TextArea<String>("description") .setLabel(new ResourceModel("session.create.description")) .add(maximumLength(SESSION_DESCRIPTION_MAX_LENGTH))), new AjaxFallbackButton("submit", create) { @Override public void onSubmit(AjaxRequestTarget target, Form<?> form) { Game game = (Game) form.getModelObject(); String code = sessionService.create(game.name, game.description, game.estimates).getCode(); setResponsePage(SessionPage.class, new PageParameters().add("code", code)); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { if (target != null) { target.add(form); } } }); login.add(internal.setOutputMarkupId(true)); session.add(join.setOutputMarkupId(true), create.setOutputMarkupId(true)); session.add(append("class", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return userService.getCurrentUser() != null ? "active" : null; } })); add(login, session); }
From source file:org.lbogdanov.poker.web.page.SessionPage.java
License:Apache License
/** * Asynchronously publishes messages to the session participants via Atmosphere framework. * //from ww w.j a va 2s .co m * @param target the <code>AjaxRequestTarget</code> instance * @param msg the message to publish * @throws Exception if any error occurred */ @Subscribe(contextAwareFilter = OriginFilter.class) public void publishMessage(AjaxRequestTarget target, Message<?> msg) throws Exception { if (target == null) { LOG.warn("Couldn't sent async message, target was null"); } else { target.appendJavaScript(String.format("Poker.dispatch(%s);", mapper.writeValueAsString(msg))); } }
From source file:org.obiba.onyx.jade.core.wicket.workstation.ExperimentalConditionHistoryPanel.java
License:Open Source License
public ExperimentalConditionHistoryPanel(String id, List<InstrumentCalibration> instrumentCalibrations, final int pageSize, Instrument instrument) { super(id);/*from w ww. ja v a 2s . co m*/ setOutputMarkupId(true); add(new AttributeModifier("class", true, new Model<String>("experimental-condition-history-panel"))); this.instrument = instrument; WebMarkupContainer selectCalibrationId = new WebMarkupContainer("selectCalibrationId"); if (instrumentCalibrations.size() >= 1) selectedInstrumentCalibration = instrumentCalibrations.get(0); final DropDownChoice<InstrumentCalibration> instrumentCalibrationChoice = new DropDownChoice<InstrumentCalibration>( "instrumentCalibrationChoice", new PropertyModel<InstrumentCalibration>(this, "selectedInstrumentCalibration"), instrumentCalibrations, new ChoiceRenderer<InstrumentCalibration>() { private static final long serialVersionUID = 1L; @Override public Object getDisplayValue(InstrumentCalibration object) { return new SpringStringResourceModel(object.getName(), object.getName()).getString(); } @Override public String getIdValue(InstrumentCalibration object, int index) { return object.getName(); } }); instrumentCalibrationChoice.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { OnyxEntityList<ExperimentalCondition> newTable = getTable(pageSize); list.replaceWith(newTable); list = newTable; target.appendJavascript("styleOnyxEntityListNavigationBar('" + getMarkupId() + "');"); target.addComponent(list); } }); selectCalibrationId.add(instrumentCalibrationChoice); add(selectCalibrationId); if (instrumentCalibrations.size() <= 1) { selectCalibrationId.setVisible(false); list = getTable(pageSize + 2); } else { list = getTable(pageSize); } add(list); }
From source file:org.obiba.onyx.jade.core.wicket.workstation.InstrumentPanel.java
License:Open Source License
/** * @param instrumentWindow//from ww w. j a v a 2 s.c o m */ private void registerWindowCallbacks(Dialog instrumentWindow) { // actions to perform on submit instrumentWindow.setCloseButtonCallback(new CloseButtonCallback() { private static final long serialVersionUID = 1L; public boolean onCloseButtonClicked(AjaxRequestTarget target, Status status) { if (status != null && status.equals(Dialog.Status.ERROR)) { displayFeedback(target); return false; } return true; } }); instrumentWindow.setWindowClosedCallback(new WindowClosedCallback() { private static final long serialVersionUID = 1L; public void onClose(AjaxRequestTarget target, Status status) { if (status != null && !status.equals(Dialog.Status.CANCELLED) && !status.equals(Dialog.Status.WINDOW_CLOSED)) { if (!editMode) { setInstrumentUsage(InstrumentUsage.RESERVED); } instrumentService.updateInstrument(getInstrument()); if (!editMode) { InstrumentMeasurementType instrumentMeasurementType = instrumentMeasurementTypeModel .getObject(); instrumentService.addInstrumentMeasurementType(getInstrument(), instrumentMeasurementType); } } Component list = InstrumentPanel.this.findParent(WorkstationPanel.class) .getInstrumentMeasurementTypeList(); target.addComponent(list); target.appendJavascript("styleOnyxEntityListNavigationBar('instrumentContent');"); } }); }