Example usage for org.apache.wicket.ajax AjaxRequestTarget addChildren

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget addChildren

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget addChildren.

Prototype

void addChildren(MarkupContainer parent, Class<?> childCriteria);

Source Link

Document

Visits all children of the specified parent container and adds them to the target if they are of same type as childCriteria

Usage

From source file:org.onexus.ui.authentication.persona.PersonaSignInPage.java

License:Apache License

public PersonaSignInPage(final PageParameters parameters) {
    super(parameters);

    add(new Image("logo", LOGO));
    add(new GuestPanel("browserId", GuestPanel.Style.GREEN) {

        private static final long serialVersionUID = 1L;

        @Override/*from  w ww  .jav  a2s  . c om*/
        protected void onSuccess(AjaxRequestTarget target) {
            BrowserId browserId = SessionHelper.getBrowserId(Session.get());

            if (browserId != null) {
                if (((IAuthenticatedSession) WebSession.get()).authenticate(browserId.getEmail(), null)) {

                    // logon successful. Continue to the original destination
                    continueToOriginalDestination();
                    // Ups, no original destination. Go to the home page
                    throw new RestartResponseException(
                            getSession().getPageFactory().newPage(getApplication().getHomePage()));

                } else {
                    onFailure(target, "You are not authorized");
                }
            }
        }

        @Override
        protected void onFailure(AjaxRequestTarget target, final String failureReason) {
            error("The authentication failed: " + failureReason);
            target.addChildren(getPage(), IFeedback.class);
        }

    });

    add(new FeedbackPanel("feedback").setOutputMarkupId(true));
}

From source file:org.sakaiproject.attendance.tool.panels.EventInputPanel.java

License:Educational Community License

private void processSave(AjaxRequestTarget target, Form<?> form, boolean addAnother) {
    AttendanceEvent e = (AttendanceEvent) form.getModelObject();
    e.setAttendanceSite(attendanceLogic.getCurrentAttendanceSite());
    boolean result = attendanceLogic.updateAttendanceEvent(e);

    if (result) {
        StringResourceModel temp = new StringResourceModel("attendance.add.success", null,
                new String[] { e.getName() });
        getSession().success(temp.getString());
    } else {// w  w  w  .j a v a  2  s .co m
        error(getString("attendance.add.failure"));
        target.addChildren(form, FeedbackPanel.class);
    }

    final Class<? extends Page> currentPageClass = getPage().getPageClass();
    if (addAnother) {
        if (Overview.class.equals(currentPageClass)) {
            window.close(target);

            Overview overviewPage = (Overview) getPage();
            final ModalWindow window2 = overviewPage.getAddOrEditItemWindow();
            window2.setTitle(new ResourceModel("attendance.add.header"));
            window2.setContent(new EventInputPanel(window2.getContentId(), window2, null, true));
            target.addChildren(form, FeedbackPanel.class);
            window2.show(target);
        }
    } else {
        if (EventView.class.equals(currentPageClass)) {
            setResponsePage(new EventView(attendanceEvent, ((EventView) getPage()).getReturnPage()));
        } else {
            setResponsePage(currentPageClass);
        }
    }
}

From source file:org.sakaiproject.attendance.tool.panels.EventInputPanel.java

License:Educational Community License

private AjaxSubmitLink createSubmitLink(final String id, final Form<?> form, final boolean createAnother) {
    return new AjaxSubmitLink(id, form) {
        @Override//from  w w w  .  j ava 2s. c  o m
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onSubmit(target, form);

            processSave(target, form, createAnother);
        }

        @Override
        public boolean isEnabled() {
            return !attendanceLogic.getCurrentAttendanceSite().getIsSyncing();
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addChildren(form, FeedbackPanel.class);
        }

        @Override
        public boolean isVisible() {
            if (createAnother) {
                return !isEditing;
            }

            return super.isVisible();
        }
    };
}

From source file:org.sakaiproject.gradebookng.tool.actions.GradeUpdateAction.java

License:Educational Community License

@Override
public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) {
    final GradebookPage page = (GradebookPage) target.getPage();

    // clear the feedback message at the top of the page
    target.addChildren(page, FeedbackPanel.class);

    final String rawOldGrade = params.get("oldScore").textValue();
    final String rawNewGrade = params.get("newScore").textValue();

    if (StringUtils.isNotBlank(rawNewGrade)
            && (!NumberUtil.isValidLocaleDouble(rawNewGrade) || FormatHelper.validateDouble(rawNewGrade) < 0)) {
        target.add(page.updateLiveGradingMessage(page.getString("feedback.error")));

        return new ArgumentErrorResponse("Grade not valid");
    }/*from   w  w w  .ja  v  a2s.co  m*/

    final String oldGrade = FormatHelper.formatGradeFromUserLocale(rawOldGrade);
    final String newGrade = FormatHelper.formatGradeFromUserLocale(rawNewGrade);

    final String assignmentId = params.get("assignmentId").asText();
    final String studentUuid = params.get("studentId").asText();
    final String categoryId = params.has("categoryId") ? params.get("categoryId").asText() : null;

    // We don't pass the comment from the use interface,
    // but the service needs it otherwise it will assume 'null'
    // so pull it back from the service and poke it in there!
    final String comment = businessService.getAssignmentGradeComment(Long.valueOf(assignmentId), studentUuid);

    // for concurrency, get the original grade we have in the UI and pass it into the service as a check
    final GradeSaveResponse result = businessService.saveGrade(Long.valueOf(assignmentId), studentUuid,
            oldGrade, newGrade, comment);

    if (result.equals(GradeSaveResponse.NO_CHANGE)) {
        target.add(page.updateLiveGradingMessage(page.getString("feedback.saved")));

        return new SaveGradeNoChangeResponse();
    }

    if (!result.equals(GradeSaveResponse.OK) && !result.equals(GradeSaveResponse.OVER_LIMIT)) {
        target.add(page.updateLiveGradingMessage(page.getString("feedback.error")));

        return new SaveGradeErrorResponse(result);
    }

    final CourseGrade studentCourseGrade = businessService.getCourseGrade(studentUuid);

    boolean isOverride = false;
    String grade = "-";
    String points = "0";

    if (studentCourseGrade != null) {
        final GradebookUiSettings uiSettings = page.getUiSettings();
        final Gradebook gradebook = businessService.getGradebook();
        final CourseGradeFormatter courseGradeFormatter = new CourseGradeFormatter(gradebook,
                page.getCurrentRole(),
                businessService.isCourseGradeVisible(businessService.getCurrentUser().getId()),
                uiSettings.getShowPoints(), true);

        grade = courseGradeFormatter.format(studentCourseGrade);
        if (studentCourseGrade.getPointsEarned() != null) {
            points = FormatHelper.formatDoubleToDecimal(studentCourseGrade.getPointsEarned());
        }
        if (studentCourseGrade.getEnteredGrade() != null) {
            isOverride = true;
        }
    }

    Optional<CategoryScoreData> catData = categoryId == null ? Optional.empty()
            : businessService.getCategoryScoreForStudent(Long.valueOf(categoryId), studentUuid, true);
    String categoryScore = catData.map(c -> String.valueOf(c.score)).orElse("-");
    List<Long> droppedItems = catData.map(c -> c.droppedItems).orElse(Collections.emptyList());

    target.add(page.updateLiveGradingMessage(page.getString("feedback.saved")));

    return new GradeUpdateResponse(result.equals(GradeSaveResponse.OVER_LIMIT), grade, points, isOverride,
            categoryScore, droppedItems);
}