Example usage for org.apache.wicket.ajax.attributes AjaxRequestAttributes setWicketAjaxResponse

List of usage examples for org.apache.wicket.ajax.attributes AjaxRequestAttributes setWicketAjaxResponse

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.attributes AjaxRequestAttributes setWicketAjaxResponse.

Prototype

public AjaxRequestAttributes setWicketAjaxResponse(final boolean wicketAjaxResponse) 

Source Link

Usage

From source file:com.hubeleon.wicketlist.HomePage.java

License:Open Source License

public HomePage() {

    final WebMarkupContainer divList = new WebMarkupContainer("ochConfirmCDRsTable");
    divList.setOutputMarkupId(true);//  w  w w.j a v  a 2  s  . co  m
    divList.setOutputMarkupPlaceholderTag(true);
    setVersioned(false);

    final List<CDRInfo> cdrInfoArray = new ArrayList();
    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
        try (Closeable closeable = ObjectifyService.begin()) {
            System.out.println(" #######  get all cdr list");
            List<CDRInfo> ths = ofy().load().type(CDRInfo.class).list();
            cdrInfoArray.addAll(ths);
        }
    }

    final ListView list = new ListView<CDRInfo>("listview", cdrInfoArray) {

        protected void populateItem(final ListItem<CDRInfo> listItem) {

            final CDRInfo cdr = (CDRInfo) listItem.getModelObject();

            System.out.println("Populating List for  " + cdr.getCdrId() + " with status  "
                    + cdr.getCdrStatusType() + " retrieved from database ");

            listItem.setOutputMarkupId(true);
            listItem.setOutputMarkupPlaceholderTag(true);

            listItem.add(new Label("cdr", (cdr.getCdrId() != null ? cdr.getCdrId() : "")));
            listItem.add(new Label("evseId", (cdr.getEvseId() != null ? cdr.getEvseId() : "")));
            final Label lblStatus = new Label("status", new PropertyModel<String>(cdr, "cdrStatusType"));
            lblStatus.setOutputMarkupId(true);
            lblStatus.setOutputMarkupPlaceholderTag(true);

            listItem.add(lblStatus);

            listItem.add(new Label("startDateTime",
                    (cdr.getStartDateTime().toString() != null ? cdr.getStartDateTime().toString() : "")));
            listItem.add(new Label("endDateTime",
                    (cdr.getEndDateTime().toString() != null ? cdr.getEndDateTime().toString() : "")));
            listItem.add(new Label("duration", (cdr.getDuration() != null ? cdr.getDuration() : "")));

            listItem.add(new Label("instance", cdr.getInstance() != null ? cdr.getInstance() : ""));
            listItem.add(new Label("tokenType", cdr.getTokenType() != null ? cdr.getTokenType() : ""));
            listItem.add(new Label("tokenSubType", cdr.getTokenSubType() != null ? cdr.getTokenSubType() : ""));
            listItem.add(new Label("contractId", cdr.getContractId() != null ? cdr.getContractId() : ""));
            listItem.add(new Label("liveAuthId", cdr.getLiveAuthId() != null ? cdr.getLiveAuthId() : ""));

            final Form<CDRInfo> form = new Form<CDRInfo>("myForm", new Model(cdr)) {

                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

                protected void onSubmit(AjaxRequestTarget target, Form<CDRInfo> form) {
                    CDRInfo c = (CDRInfo) this.getModelObject();
                    System.err.println("######## STATUS:" + c.getCdrStatusType());
                    //this.setResponsePage(new MovieDisplayPage(movie));
                };
            };

            form.setOutputMarkupId(true);
            form.setOutputMarkupPlaceholderTag(true);

            final HiddenField currentState = new HiddenField("currentState",
                    new PropertyModel<String>(cdr, "cdrStatusType"));
            currentState.setOutputMarkupId(true);
            form.add(currentState);

            final HiddenField hcdr = new HiddenField("cdrId", new PropertyModel<String>(cdr, "cdrId"));
            hcdr.setOutputMarkupId(true);
            form.add(hcdr);

            final Model<String> btnStyle = new Model<String>("btn-warning");

            AjaxButton btn = new AjaxButton("stateAcceptButton",
                    new PropertyModel<String>(cdr, "cdrStatusType"), form) {

                protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);
                    attributes.setWicketAjaxResponse(false);
                }

                protected void onClick(AjaxRequestTarget target, Form form) {

                }

                protected void onSubmit(AjaxRequestTarget target, Form form) {
                    System.out.println(" ####### " + hcdr.getDefaultModelObjectAsString() + " - "
                            + currentState.getDefaultModelObjectAsString());
                    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
                        try (Closeable closeable = ObjectifyService.begin()) {
                            CDRInfo result = (CDRInfo) ofy().load().type(CDRInfo.class)
                                    .id(hcdr.getDefaultModelObjectAsString()).now();
                            result.setCdrStatusType("Accepted");
                            System.out.println("Persisting to database " + result.getCdrId() + " - "
                                    + result.getCdrStatusType() + " ::: " + target.getLastFocusedElementId());
                            ofy().save().entity(result).now();
                            setReuseItems(true);
                            addStateChange();
                            modelChanging();
                            // Remove item and invalidate listView
                            List<CDRInfo> currentList = (List<CDRInfo>) getList();
                            for (CDRInfo i : currentList) {
                                if (i.getCdrId().equalsIgnoreCase(result.getCdrId())) {
                                    System.out.println("#### Found entry and updating state to : "
                                            + result.getCdrStatusType());
                                    currentList.remove(i);
                                    i.setCdrStatusType(result.getCdrStatusType());
                                    System.out.println("#### set list " + currentList);
                                    setList(currentList);
                                    target.appendJavaScript(" document.getElementById('" + lblStatus.getId()
                                            + "').value='" + result.getCdrStatusType() + "';");
                                    System.out.println("#### model changed ");
                                    modelChanged();
                                    System.out.println("#### remove all ");
                                    removeAll();
                                    break;
                                } else {
                                    System.out.println("#### NOT FOUND as charge record " + i.getCdrId()
                                            + ", while we are looking for " + result.getCdrId());
                                }
                            }
                        }
                    }
                    target.add(lblStatus);
                    setResponsePage(HomePage.class);
                }

            };

            btn.add(AttributeModifier.append("class", btnStyle));

            btn.add(new AttributeModifier("cdrStatusType", cdr) {
                protected String newValue(final String currentValue, final String replacementValue) {
                    System.out
                            .println("######## New Value 1:" + replacementValue + " old value " + currentValue);
                    return currentValue + replacementValue;
                }

            });

            form.add(btn);

            AjaxButton btnReject = new AjaxButton("stateRejectButton",
                    new PropertyModel<String>(cdr, "cdrStatusType"), form) {

                protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);
                    attributes.setWicketAjaxResponse(false);
                    System.out.println("########updateAjaxAttributes");
                }

                protected void onSubmit(AjaxRequestTarget target, Form form) {
                    System.out.println(" ####### " + hcdr.getDefaultModelObjectAsString() + " - "
                            + currentState.getDefaultModelObjectAsString());
                    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
                        try (Closeable closeable = ObjectifyService.begin()) {
                            CDRInfo result = (CDRInfo) ofy().load().type(CDRInfo.class)
                                    .id(hcdr.getDefaultModelObjectAsString()).now();
                            result.setCdrStatusType("Rejected");
                            System.out.println("Persisting to database " + result.getCdrId() + " - "
                                    + result.getCdrStatusType() + " ::: " + target.getLastFocusedElementId());
                            ofy().save().entity(result).now();
                            getList().remove(result);
                        }
                    }
                    target.add(divList);
                }

            };

            btnReject.add(AttributeModifier.append("class", btnStyle));

            btnReject.add(new AttributeModifier("cdrStatusType", cdr) {
                protected String newValue(final String currentValue, final String replacementValue) {
                    System.out.println("######## New Value Reject Button:" + replacementValue + " old value "
                            + currentValue);
                    return currentValue + replacementValue;
                }

            });

            form.add(btnReject);
            listItem.add(form);

        }
    };
    list.setOutputMarkupId(true);
    list.setOutputMarkupPlaceholderTag(true);
    divList.setOutputMarkupId(true);
    divList.setOutputMarkupPlaceholderTag(true);
    divList.add(list);

    add(divList);

}

From source file:com.wicketinaction.HandlebarsButton.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    // let Wicket.Ajax/jQuery know that the result is JSON so it will parse it for you
    attributes.setDataType("json");

    // tell Wicket.Ajax to not try to process the Ajax response because it is not the normal <ajax-response>
    attributes.setWicketAjaxResponse(false);

    // register the onSuccess listener that will execute Handlebars logic
    AjaxCallListener listener = new AjaxCallListener() {
        @Override//from   w ww  .j  a  v  a 2 s. c  o  m
        public CharSequence getSuccessHandler(Component component) {
            // returns an instance of JsonFunction, so Wicket will render it as is
            return onSuccessFunction;
        }
    };

    // the following handlers are not JsonFunction and they will be wrapped in JsonFunction by Wicket and the
    // appropriate parameters will be passed.

    // For the 'before' handler it looks like: function(attrs, jqXHR, settings){Wicket.Log.info('[Wicket Ajax 6 demo]: executing a before handler');}
    listener.onBefore("Wicket.Log.info('[Wicket Ajax 6 demo]: executing a before handler');");

    // For the 'complete' handler it looks like: function(attrs, jqXHR, textStatus){Wicket.Log.info('[Wicket Ajax 6 demo]: executing a complete handler');}
    listener.onComplete(
            "Wicket.Log.info('[Wicket Ajax 6 demo]: executing a complete handler. Status: ' + textStatus);");

    // change the return to 'false' and the Ajax call wont be executed at all.
    listener.onPrecondition("return true;");

    attributes.getAjaxCallListeners().add(listener);
}

From source file:org.apache.openmeetings.web.components.user.calendar.CalendarPanel.java

License:Apache License

public CalendarPanel(String id) {
    super(id);/*from   w  ww .j  a v a 2 s  .  c  o m*/
    WebMarkupContainer calendar = new WebMarkupContainer("calendar");
    calendar.setOutputMarkupId(true);
    calendar.setMarkupId("calendar");
    add(calendar);

    final CalendarForm form = new CalendarForm("appointment",
            new CompoundPropertyModel<Appointment>(new Appointment()));
    add(form);

    //fetchEvents
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 6880514947331946407L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setDataType("json");
            attributes.setWicketAjaxResponse(false);
            attributes.getAjaxCallListeners().add(new AjaxCallListener().onSuccess("callback(data);"));
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(
                    JavaScriptHeaderItem.forScript("var fetchEventsFunc = "
                            + this.getCallbackFunction(context("start"), context("end"), context("callback"),
                                    resolved("_start", "start.getTime()"), resolved("_end", "end.getTime()"))
                            + ";", "fetchEventsFunc"));
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            Calendar start = WebSession.getCalendar();
            start.setTimeInMillis(
                    getRequestCycle().getRequest().getRequestParameters().getParameterValue("_start").toLong());
            Calendar end = WebSession.getCalendar();
            end.setTimeInMillis(
                    getRequestCycle().getRequest().getRequestParameters().getParameterValue("_end").toLong());
            JSONArray events = new JSONArray();
            for (Appointment a : Application.getBean(AppointmentDao.class)
                    .getAppointmentsByRange(WebSession.getUserId(), start.getTime(), end.getTime())) {
                try {
                    events.put(new JSONObject().put("id", a.getAppointmentId())
                            .put("title", a.getAppointmentName())
                            .put("description", a.getAppointmentDescription())
                            .put("start", WebSession.getDateFormat().format(a.getAppointmentStarttime()))
                            .put("end", WebSession.getDateFormat().format(a.getAppointmentEndtime()))
                            .put("allDay", false));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            getRequestCycle().scheduleRequestHandlerAfterCurrent(
                    new TextRequestHandler("application/json", "UTF-8", events.toString()));
        }
    });
    //dropEvent
    add(new DropResizeBehavior(true, "dropEventFunc"));
    //resizeEvent
    add(new DropResizeBehavior(false, "resizeEventFunc"));
    //create on click-and-drag
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 6880514947331946407L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners()
                    .add(new AjaxCallListener().onSuccess("$('#appointment').dialog('open');"));
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(JavaScriptHeaderItem.forScript(
                    "var selectFunc = " + this.getCallbackFunction(context("start"), context("end"),
                            context("allDay"), context("jsEvent"), context("view"),
                            resolved("_start", "start.getTime()"), resolved("_end", "end.getTime()")) + ";",
                    "selectFunc"));
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            Calendar start = WebSession.getCalendar();
            start.setTimeInMillis(
                    getRequestCycle().getRequest().getRequestParameters().getParameterValue("_start").toLong());
            Calendar end = WebSession.getCalendar();
            end.setTimeInMillis(
                    getRequestCycle().getRequest().getRequestParameters().getParameterValue("_end").toLong());

            if (start.equals(end)) {
                end.add(Calendar.HOUR_OF_DAY, 1);
            }
            Appointment a = new Appointment();
            a.setAppointmentStarttime(start.getTime());
            a.setAppointmentEndtime(end.getTime());
            form.setModelObject(a);

            target.add(form);
        }
    });
    //eventClick
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 6880514947331946407L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners()
                    .add(new AjaxCallListener().onSuccess("$('#appointment').dialog('open');"));
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(
                    JavaScriptHeaderItem.forScript(
                            "var eventClickFunc = " + this.getCallbackFunction(context("event"),
                                    context("jsEvent"), context("view"), resolved("_id", "event.id")) + ";",
                            "eventClickFunc"));
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            Appointment a = Application.getBean(AppointmentDao.class).getAppointmentById(
                    getRequestCycle().getRequest().getRequestParameters().getParameterValue("_id").toLong());
            form.setModelObject(a);

            target.add(form);
        }
    });
}

From source file:org.wicketstuff.objectautocomplete.ObjectAutoCompleteBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    attributes.setWicketAjaxResponse(false);
    attributes.setDataType("text");
}