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

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

Introduction

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

Prototype

void add(Component... components);

Source Link

Document

Adds components to the list of components to be rendered.

Usage

From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java

License:Open Source License

@Override
protected void onSave(Form<ArkUserVO> containerForm, AjaxRequestTarget target) {

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(sessionStudyId);
    containerForm.getModelObject().setStudy(study);
    if (containerForm.getModelObject().getMode() == Constants.MODE_NEW) {

        /******************************************* Added for handle the current user in the system but not showing for the *********************************/
        ArkUser arkUser = getArkUserInDB(userNameTxtField.getModelObject());
        //Checking for the data base
        if (arkUser != null) {
            //getCurrentLdapUser(*) will only set the First Name,Last name,Email address,etc and some basic properties only refer the mapper class.
            ArkUserVO ldapuser = getCurrentLdapUser(userNameTxtField.getModelObject());
            ldapuser.setArkUserRoleList(containerForm.getModelObject().getArkUserRoleList());
            ldapuser.setArkUserEntity(arkUser);
            ldapuser.setArkUserConfigs(containerForm.getModelObject().getArkUserConfigs());
            ldapuser.setStudy(study);/*from  w ww .j  a  va  2 s. c  o m*/
            @SuppressWarnings("unchecked")
            List<ArkUserRole> arkUserRoleLst = iArkCommonService.getArkRoleListByUserAndStudy(ldapuser,
                    ldapuser.getStudy());
            //Check for existing user in ldap server.
            if (arkUserRoleLst.size() < 1) {
                //containerForm.getModelObject().setMode(Constants.MODE_EDIT_USER_ROLE_ONLY);
                containerForm.setModelObject(ldapuser);
                target.add(containerForm);
                //formComponentAjaxCall(target, false);
                confirmModal.show(target);
            } else {
                this.info(new StringResourceModel("user.exists", this, null).getString());
            }

        } else {
            /********************************************************** end **********************************************************************************/
            try {
                iUserService.createArkUser(containerForm.getModelObject());
                reNewArkUserRoleForChildStudies(containerForm);
                containerForm.getModelObject().setMode(Constants.MODE_EDIT);
                userNameTxtField.setEnabled(false);
                onSavePostProcess(target);
                this.info(new StringResourceModel("user.saved", this, null).getString());
                target.add(feedBackPanel);
            } catch (UserNameExistsException e) {
                this.error(new StringResourceModel("user.exists", this, null).getString());
            } catch (ArkSystemException e) {
                this.error(new StringResourceModel("ark.system.error", this, null).getString());
            } catch (Exception e) {
                this.error(new StringResourceModel("severe.system.error", this, null).getString());
            }
        }
    } else if (containerForm.getModelObject().getMode() == Constants.MODE_EDIT) {
        try {
            // Update ArkUser for study in context
            iUserService.updateArkUser(containerForm.getModelObject());
            reNewArkUserRoleForChildStudies(containerForm);
            onSavePostProcess(target);
            this.info(new StringResourceModel("user.updated", this, null).getString());

        } catch (EntityNotFoundException e) {
            this.error(new StringResourceModel("user.notFound", this, null).getString());
        } catch (ArkSystemException e) {
            this.error(new StringResourceModel("ark.system.error", this, null).getString());
        }
    }

    target.add(this);
    target.add(feedBackPanel);
}

From source file:au.org.theark.study.web.component.manageuser.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {
    try {//w ww .j  a va  2 s. co  m
        // Look up a Ark User's based on the filter specified by the user.
        List<ArkUserVO> userResultList = userService.searchUser(containerForm.getModelObject());

        if (userResultList != null && userResultList.size() == 0) {
            this.info(
                    "User(s) with the specified criteria does not exist in the system. Please refine your search filter.");
            target.add(feedbackPanel);
        }

        pageableListView.removeAll();
        arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);
        target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    } catch (ArkSystemException e) {
        this.error("A System Error has occured. Please contact support");
    }
}

From source file:au.org.theark.study.web.component.manageuser.form.SearchForm.java

License:Open Source License

@Override
protected void onNew(AjaxRequestTarget target) {
    containerForm.getModelObject().setMode(Constants.MODE_NEW);
    prePopulateArkUserRoleList();//from  ww w  . j  a va2  s .  c o m
    arkCrudContainerVO.getWmcForarkUserAccountPanel().setVisible(true);
    // This should re-render the list again
    ListView listView = (ListView) arkCrudContainerVO.getWmcForarkUserAccountPanel().get("arkUserRoleList");
    listView.removeAll();
    preProcessDetailPanel(target);
    target.add(arkCrudContainerVO.getEditButtonContainer());
    target.add(arkCrudContainerVO.getWmcForarkUserAccountPanel());
}

From source file:au.org.theark.study.web.component.manageuser.form.SearchForm.java

License:Open Source License

protected void initialiseSearchForm() {

    newButton = new ArkBusyAjaxButton(Constants.NEW) {

        private static final long serialVersionUID = 1666656098281624401L;

        @Override/*from w w  w.j  a va2 s.c o m*/
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // Make the details panel visible, disabling delete button (if found)
            AjaxButton ajaxButton = (AjaxButton) arkCrudContainerVO.getEditButtonContainer().get("remove");
            if (ajaxButton != null) {
                ajaxButton.setEnabled(false);
                target.add(ajaxButton);
            }
            // Call abstract method
            onNew(target);
        }

        @Override
        public boolean isVisible() {
            return ArkPermissionHelper.isActionPermitted(Constants.NEW);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }
    };

    userNameTxtField = new TextField<String>(Constants.USER_NAME);
    firstNameTxtField = new TextField<String>(Constants.FIRST_NAME);
    lastNameTxtField = new TextField<String>(Constants.LAST_NAME);
    emailTxtField = new TextField<String>(Constants.EMAIL);
}

From source file:au.org.theark.study.web.component.manageuser.SearchResultListPanel.java

License:Open Source License

private AjaxLink buildLink(final ArkUserVO arkUserVo, final WebMarkupContainer searchResultsContainer) {

    AjaxLink link = new AjaxLink("userName") {

        private static final long serialVersionUID = 1L;

        @Override//from   w  w  w. j a  v  a2 s  . c  o m
        public void onClick(AjaxRequestTarget target) {
            try {
                // Fetch the user and related details from backend
                Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                        .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                Study study = iArkCommonService.getStudy(sessionStudyId);

                ArkUserVO arkUserVOFromBackend = iUserService.lookupArkUser(arkUserVo.getUserName(), study);
                if (!arkUserVOFromBackend.isArkUserPresentInDatabase()) {
                    containerForm
                            .info(new StringResourceModel("user.not.linked.to.study", this, null).getString());
                    target.add(feedbackPanel);
                    arkUserVOFromBackend.setChangePassword(true);
                    arkUserVOFromBackend.getArkUserEntity().setLdapUserName(arkUserVo.getUserName());
                    arkUserVOFromBackend.setStudy(new Study());
                    prePopulateForNewUser(arkUserVOFromBackend);
                } else {
                    arkUserVOFromBackend.setStudy(study);
                    prePopulateArkUserRoleList(arkUserVOFromBackend);
                }

                containerForm.getModelObject().setArkUserRoleList(arkUserVOFromBackend.getArkUserRoleList());

                containerForm.setModelObject(arkUserVOFromBackend);

                // This triggers the call to populateItem() of the ListView
                ListView listView = (ListView) arkCrudContainerVO.getWmcForarkUserAccountPanel()
                        .get("arkUserRoleList");
                if (listView != null) {
                    listView.removeAll();
                }

                arkCrudContainerVO.getWmcForarkUserAccountPanel().setVisible(true);
                ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO);
                target.add(feedbackPanel);
                // Set the MODE here.Since the User Details are from LDAP we don't have a entity that we can use to check for a mode
                containerForm.getModelObject().setMode(Constants.MODE_EDIT);

                // Available/assigned child studies
                List<Study> availableChildStudies = new ArrayList<Study>(0);
                List<Study> selectedChildStudies = new ArrayList<Study>(0);

                if (study.getParentStudy() != null && study.getParentStudy() == study) {
                    availableChildStudies = iStudyService.getChildStudyListOfParent(study);

                    // Only assign selected child studies if/when user actually assigned study in context
                    if (arkUserVOFromBackend.getStudy().getId() != null) {
                        selectedChildStudies = iArkCommonService
                                .getAssignedChildStudyListForUser(arkUserVOFromBackend);
                    }
                }

                containerForm.getModelObject().setAvailableChildStudies(availableChildStudies);
                containerForm.getModelObject().setSelectedChildStudies(selectedChildStudies);
            } catch (ArkSystemException e) {
                containerForm.error(new StringResourceModel("ark.system.error", this, null).getString());
                target.add(feedbackPanel);
            }
        }
    };
    // Add the label for the link
    Label userNameLinkLabel = new Label("userNameLink", arkUserVo.getUserName());
    link.add(userNameLinkLabel);
    return link;
}

From source file:au.org.theark.study.web.component.mydetails.form.MyDetailsForm.java

License:Open Source License

private void initStudyDdc(ArkUserVO arkUserVO) {
    List<Study> studyListForUser = iArkCommonService.getStudyListForUser(arkUserVO);
    ChoiceRenderer<Study> choiceRenderer = new ChoiceRenderer<Study>(Constants.NAME, Constants.ID);
    //Set to selected study.
    defaultValue = arkUserVO.getStudy();
    studyDdc = new DropDownChoice<Study>("studyLst", new PropertyModel<Study>(this, "defaultValue"),
            studyListForUser, choiceRenderer);
    studyDdc.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        private static final long serialVersionUID = -4514605801401294450L;

        @Override/*ww w. ja  va2  s.  co  m*/
        protected void onUpdate(AjaxRequestTarget target) {
            listViewPanel.remove(pageableListView);
            listViewPanel.remove(pageNavigator);
            List<ArkUserRole> arkUserRoleList = iArkCommonService.getArkRoleListByUserAndStudy(arkUserVO,
                    studyDdc.getModelObject());
            arkUserVO.setArkUserRoleList(arkUserRoleList);
            getModelObject().setArkUserRoleList(arkUserRoleList);
            //Add Ark Role Policy Templates
            List<ArkRolePolicyTemplate> arkRolePolicyTemplatesLst = iArkCommonService
                    .getArkRolePolicytemplateList(arkUserVO);
            getModelObject().setArkRolePolicyTemplatesList(arkRolePolicyTemplatesLst);
            log.info("List:" + arkRolePolicyTemplatesLst.size());
            createPageListView(iModel);
            listViewPanel.add(pageableListView);
            listViewPanel.add(pageNavigator);
            target.add(listViewPanel);
        }
    });
    initiPageListViewWithSelectedStudy(arkUserVO);
}

From source file:au.org.theark.study.web.component.mydetails.MyDetails.java

License:Open Source License

public MyDetails(String id, ArkUserVO arkUserVO, final FeedbackPanel feedBackPanel, ModalWindow modalWindow) {
    super(id);/*from w  ww. j a  v a2s .c  o  m*/
    /* Initialise the CPM */
    arkUserModelCpm = new CompoundPropertyModel<ArkUserVO>(arkUserVO);
    MyDetailsForm myDetailForm = new MyDetailsForm(Constants.USER_DETAILS_FORM, arkUserModelCpm, feedBackPanel,
            modalWindow) {

        private static final long serialVersionUID = -8858977824290273852L;

        protected void onSave(AjaxRequestTarget target) {
            ArkUserVO arkUser = getModelObject();

            if ((arkUser.getPassword() != null && arkUser.getConfirmPassword() != null)
                    && (!arkUser.getPassword().isEmpty() && !arkUser.getConfirmPassword().isEmpty())) {
                // Temporary allow the user to select if he wants to change it
                arkUser.setChangePassword(true);
            }

            boolean invalid = false;
            for (UserConfig config : arkUser.getArkUserConfigs()) {
                String value = config.getValue();
                System.out.println("value: " + value);
                switch (config.getConfigField().getType().getName()) {
                case "NUMBER":
                    if (!isNumeric(value)) {
                        System.out.println(
                                "Field '" + config.getConfigField().getDescription() + "' should be a number");
                        this.error(
                                "Field '" + config.getConfigField().getDescription() + "' should be a number");
                        invalid = true;
                    }
                    break;
                case "CHARACTER":
                    break;
                case "DATE":
                    if (!isDate(value)) {
                        System.out.println("Field '" + config.getConfigField().getDescription()
                                + "' should be a date (DD/MM/YYYY)");
                        this.error("Field '" + config.getConfigField().getDescription()
                                + "' should be a date (DD/MM/YYYY)");
                        invalid = true;
                    }
                    break;
                default:
                    break;
                }
            }

            if (invalid) {
                System.out.println("===== INVALID ======");
                processFeedback(target, feedBackPanel);
                return;
            }

            try {
                userService.updateArkUser(arkUser);
                this.info("Details for user: " + arkUser.getUserName() + " updated");
                processFeedback(target, feedBackPanel);
            } catch (ArkSystemException arkSystemException) {
                log.error("Exception occured while performing an update on the user details in LDAP "
                        + arkSystemException.getMessage());
                this.error("An error has occured, cannot update user details. Please contact support.");
                processFeedback(target, feedBackPanel);
                // add custom error message to feedback panel.
            } catch (Exception ex) {
                // Handle all other type of exceptions
                this.error("An error has occured while saving user details. Please contact support.");
                processFeedback(target, feedBackPanel);
                log.error("Exception occured when saving user details " + ex.getMessage());
            }
        }

        protected void processFeedback(AjaxRequestTarget target, FeedbackPanel feedbackPanel) {
            target.add(feedbackPanel);
        }

        protected void onCancel(AjaxRequestTarget target) {
            this.setVisible(false);
        }
    };
    myDetailForm.initialiseForm();
    if (arkUserVO.getMode() == Constants.MODE_EDIT) {
        myDetailForm.getUserNameTxtField().setEnabled(false);
    }
    add(myDetailForm);
}

From source file:au.org.theark.study.web.component.phone.form.SearchForm.java

License:Open Source License

@Override
protected void onSearch(AjaxRequestTarget target) {
    target.add(feedbackPanel);

    Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID);
    try {//from   w  w  w .  j  a va  2 s  .  c  o  m
        Phone phone = getModelObject().getPhone();
        phone.setPerson(studyService.getPerson(sessionPersonId));

        Collection<Phone> phones = studyService.getPersonPhoneList(sessionPersonId,
                getModelObject().getPhone());
        if (phones != null && phones.size() == 0) {
            this.info("No records match the specified criteria.");
            target.add(feedbackPanel);
        }

        getModelObject().setPhoneList(phones);
        pageableListView.removeAll();
        arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true);
        target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    } catch (EntityNotFoundException entityNotFoundException) {
        this.warn("There are no phone items available for the specified criteria.");
        target.add(feedbackPanel);

    } catch (ArkSystemException arkException) {
        this.error("The Ark Application has encountered a system error.");
        target.add(feedbackPanel);
    }
}

From source file:au.org.theark.study.web.component.phone.form.SearchForm.java

License:Open Source License

@Override
protected void onNew(AjaxRequestTarget target) {
    // ARK-108:: no longer do full reset to VO
    getModelObject().getPhone().setId(null); // only reset ID (not user definable)
    preProcessDetailPanel(target);//from ww  w.j a v a 2 s .c o  m
    target.add(feedbackPanel);
}

From source file:au.org.theark.study.web.component.studycomponent.form.DetailForm.java

License:Open Source License

@Override
protected void onSave(Form<StudyCompVo> containerForm, AjaxRequestTarget target) {

    target.add(arkCrudContainerVO.getDetailPanelContainer());
    try {//from   ww w  .  j a  v  a  2  s. co  m

        Long studyId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
        study = iArkCommonService.getStudy(studyId);
        containerForm.getModelObject().getStudyComponent().setStudy(study);

        if (containerForm.getModelObject().getStudyComponent().getId() == null) {

            iStudyService.create(containerForm.getModelObject().getStudyComponent());
            this.info("Study Component " + containerForm.getModelObject().getStudyComponent().getName()
                    + " was created successfully");
            processErrors(target);

        } else {

            iStudyService.update(containerForm.getModelObject().getStudyComponent());
            this.info("Study Component " + containerForm.getModelObject().getStudyComponent().getName()
                    + " was updated successfully");
            processErrors(target);

        }

        onSavePostProcess(target);

    } catch (EntityExistsException e) {
        this.error("A Study Component with the same name already exists for this study.");
        processErrors(target);
    } catch (UnAuthorizedOperation e) {
        this.error("You are not authorised to manage study components for the given study " + study.getName());
        processErrors(target);
    } catch (ArkSystemException e) {
        this.error("A System error occured, we will have someone contact you.");
        processErrors(target);
    }

}