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.phenotypic.web.component.phenodataentry.ResultListPanel.java

License:Open Source License

public ResultListPanel initialisePanel() {
    final ResultListPanel panelToRepaint = this;
    AbstractDetailModalWindow modalWindow = new AbstractDetailModalWindow("detailModalWindow") {

        private static final long serialVersionUID = 1L;

        @Override//  w ww  .j  a va  2 s .  c  o  m
        protected void onCloseModalWindow(AjaxRequestTarget target) {
            target.add(panelToRepaint);
        }

    };
    listDetailForm = new PhenoCollectionListForm("PhenoDataSetCollectionListForm", feedbackPanel, modalWindow,
            cpModel);
    listDetailForm.initialiseForm();
    add(listDetailForm);
    return this;
}

From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep1.java

License:Open Source License

private void initQuestionnaireDdc() {
    Study study = null;/*  ww  w . j  a  va  2  s  .c  o m*/
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    if (sessionStudyId != null && sessionStudyId > 0) {
        study = iArkCommonService.getStudy(sessionStudyId);
    } else {
        log.error("\n\n\n can't have a null study and see pheno!");
    }
    // Get a list of questionnaires for the subject in context by default
    PhenoDataSetGroup pfgForStudyCriteria = new PhenoDataSetGroup();
    pfgForStudyCriteria.setStudy(study);
    ArkFunction arkFunction = iArkCommonService
            .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION);
    pfgForStudyCriteria.setArkFunction(arkFunction);
    pfgForStudyCriteria.setPublished(true); //make sure that we don't return non-published Questionnaires
    List<PhenoDataSetGroup> questionnaireList = iPhenotypicService.getPhenoDataSetGroups(pfgForStudyCriteria, 0,
            Integer.MAX_VALUE);
    ChoiceRenderer<PhenoDataSetGroup> choiceRenderer = new ChoiceRenderer<PhenoDataSetGroup>("name", "id");
    questionnaireDdc = new DropDownChoice<PhenoDataSetGroup>("phenoDataSetGroup",
            (List<PhenoDataSetGroup>) questionnaireList, choiceRenderer);
    questionnaireDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            List<PhenoDataSetField> phenoDataSetFields = iPhenotypicService
                    .getAllPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroup(questionnaireDdc.getModelObject());
            if (phenoDataSetFields.size() > 0) {
                downloadTemplateButton.setEnabled(true);
                for (PhenoDataSetField phenoDataSetField : phenoDataSetFields) {
                    PHENO_COLUMN_NAMES = (String[]) ArrayUtils.add(PHENO_COLUMN_NAMES,
                            phenoDataSetField.getName());
                    PHENO_COLUMN_DESC = (String[]) ArrayUtils.add(PHENO_COLUMN_DESC,
                            phenoDataSetField.getFieldType().getName().toLowerCase());
                }
                PHENO_TEMPLATE_CELLS2 = createPhenoTemplateCellArray(PHENO_COLUMN_NAMES, PHENO_COLUMN_DESC);
                PHENO_COLUMN_NAMES = null;
                PHENO_COLUMN_DESC = null;
                templatePanel.remove(downloadTemplateButton);
                initDownloadButton(PHENO_TEMPLATE_CELLS2, questionnaireDdc.getModelObject().getName());
                templatePanel.add(downloadTemplateButton);
                target.add(downloadTemplateButton);
                target.add(templatePanel);
            } else {
                error("The DataSet not having any fields specified.");
                getWizardForm().onError(target, null);
                downloadTemplateButton.setEnabled(false);
                target.add(downloadTemplateButton);
            }
        }
    });
}

From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep2.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    if (containerForm.getModelObject().getPreviousStepOutCompleted()) {
        try {/*from  w w  w.  jav a 2s .c o m*/
            FileUpload fileUpload = containerForm.getModelObject().getFileUpload();
            InputStream inputStream = fileUpload.getInputStream();//TODO : should something this big be thrown around model object in wicket?
            String filename = fileUpload.getClientFileName();
            String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();
            char delimChar = containerForm.getModelObject().getUpload().getDelimiterType()
                    .getDelimiterCharacter();

            // Only allow csv, txt or xls  TODO : if we are hardcoding things like this, why do we fetch file formats from db and store as a fk reference?
            if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT")
                    || fileFormat.equalsIgnoreCase("XLS"))) {
                throw new FileFormatException();
            }

            PhenoDataUploadValidator phenoDataUploadValidator = new PhenoDataUploadValidator(iArkCommonService,
                    iPhenotypicService);
            PhenoDataSetCollection phenoCollectionCriteria = containerForm.getModelObject()
                    .getPhenoCollection();
            PhenoDataSetGroup cfgSelected = containerForm.getModelObject().getPhenoDataSetGroup();
            try {
                validationMessages = phenoDataUploadValidator.validateCustomFieldFileFormat(
                        containerForm.getModelObject(), phenoCollectionCriteria, cfgSelected);
            } catch (ArkBaseException arkBaseException) {
                validationMessage = arkBaseException.getMessage();
            }

            ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView",
                    inputStream, fileFormat, delimChar, fileUpload, iArkCommonService
                            .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue(),
                    containerForm.getModelObject().getUpload().getUploadType());
            arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
            //WebMarkupContainer wizardDataGridKeyContainer = new WebMarkupContainer("wizardDataGridKeyContainer");
            //wizardDataGridKeyContainer.setVisible(false);
            //wizardDataGridKeyContainer.setOutputMarkupId(true);
            form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
            form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);
            form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
            //form.getWizardPanelFormContainer().addOrReplace(wizardDataGridKeyContainer);
            target.add(form.getWizardPanelFormContainer());

            containerForm.getModelObject().setValidationMessages(validationMessages);
            validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

            if (validationMessage != null && validationMessage.length() > 0) {

                this.containerForm.getModelObject().getUpload()
                        .setUploadStatus(iArkCommonService.getUploadStatusFor(
                                au.org.theark.phenotypic.web.Constants.UPLOAD_STATUS_OF_ERROR_IN_FILE_VALIDATION));
                this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes 
                iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload());

                log.warn("validation = " + validationMessage);
                form.getNextButton().setEnabled(false);
                target.add(form.getWizardButtonContainer());
                downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage",
                        validationMessage, "txt") {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onError(AjaxRequestTarget target, Form<?> form) {
                        this.error("Unexpected Error: Download request could not be processed");
                    }
                };
                addOrReplace(downloadValMsgButton);
                target.add(downloadValMsgButton);
            }

        } catch (IOException e) {
            validationMessage = "Error attempting to display the file. Please check the file and try again.";
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());
        } catch (FileFormatException ffe) {
            validationMessage = "Error uploading file. You can only upload files of type: CSV (comma separated values), TXT (text), or XLS (Microsoft Excel file)";
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());
        }
    } else {
        validationMessage = "Step 1 is not completed properly.";
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    }
    //TODO : finally?  close io?
}

From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep3.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    if (containerForm.getModelObject().getPreviousStepOutCompleted()) {
        HashSet<ArkGridCell> errorCells = new HashSet<ArkGridCell>();
        try {/*from  w w  w. j  a va  2  s  . c o m*/
            String filename = containerForm.getModelObject().getFileUpload().getClientFileName();
            String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();
            char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType()
                    .getDelimiterCharacter();
            InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream();
            HashSet<Integer> insertRows = new HashSet<Integer>();
            HashSet<Integer> updateRows = new HashSet<Integer>();
            HashSet<Integer> warningRows = new HashSet<Integer>();
            HashSet<ArkGridCell> insertCells = new HashSet<ArkGridCell>();

            //this is not the best way to do this fix TODO
            List<String> listOfUidsToUpdate = new ArrayList<String>(); //TODO remove hardcoding

            if (containerForm.getModelObject().getUpload().getUploadType().getName()
                    .equalsIgnoreCase(iArkCommonService.getCustomFieldDataUploadType().getName())) {//    "Custom Data Sets")){
                PhenoDataUploadValidator phenoDataUploadValidator = new PhenoDataUploadValidator(
                        iArkCommonService, iPhenotypicService);

                try {
                    validationMessages = phenoDataUploadValidator.validateCustomFieldFileData(
                            containerForm.getModelObject(), listOfUidsToUpdate,
                            containerForm.getModelObject().getPhenoDataSetGroup());
                } catch (ArkBaseException e) {
                    validationMessages.add(e.getMessage());
                }
                containerForm.getModelObject().setUidsToUpload(listOfUidsToUpdate);
                //TODO consider if we want alternative way to do this - and maybe a superclass of uploadvalidator which draws out commonalities
                insertRows = phenoDataUploadValidator.getInsertRows();
                updateRows = phenoDataUploadValidator.getUpdateRows();
                errorCells = phenoDataUploadValidator.getErrorCells();
                warningRows = phenoDataUploadValidator.getWarningRows();
                insertCells = phenoDataUploadValidator.getInsertCells();
            } else {
                //TODO : Throw error back to user
                log.error("unexpected upload type"
                        + containerForm.getModelObject().getUpload().getUploadType().getName());
            }

            this.containerForm.getModelObject().setValidationMessages(validationMessages);
            validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

            // Show file data (and key reference)
            ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView",
                    inputStream, fileFormat, delimiterChar, containerForm.getModelObject().getFileUpload(),
                    insertRows, updateRows, warningRows, insertCells, errorCells,
                    containerForm.getModelObject().getUpload().getUploadType());
            arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
            arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer().setVisible(true);
            form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
            form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);

            // Repaint
            target.add(arkExcelWorkSheetAsGrid.getWizardDataGridKeyContainer());
            target.add(form.getWizardPanelFormContainer());
            //TODO remove hardcoding
            if (updateRows.isEmpty() || containerForm.getModelObject().getUpload().getUploadType().getName()
                    .equalsIgnoreCase("Study-specific (custom) Data")) {
                updateExistingDataContainer.setVisible(false);
                target.add(updateExistingDataContainer);
            }

            if (!errorCells.isEmpty()) {
                updateExistingDataContainer.setVisible(false);
                target.add(updateExistingDataContainer);
                form.getNextButton().setEnabled(false);
                target.add(form.getWizardButtonContainer());
            }
        } catch (IOException e) {
            validationMessage = "Error attempting to display the file. Please check the file and try again.";
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
        }

        containerForm.getModelObject().setValidationMessages(validationMessages);
        validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));

        String filename = containerForm.getModelObject().getFileUpload().getClientFileName();

        if (validationMessage != null && validationMessage.length() > 0) {
            if (!errorCells.isEmpty()) {
                form.getNextButton().setEnabled(false);
            }
            target.add(form.getWizardButtonContainer());
            downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage",
                    validationMessage, "txt") {
                private static final long serialVersionUID = 8692319829915212732L;

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    this.error("Unexpected Error: Download request could not be processed");
                }
            };
            addOrReplace(downloadValMsgButton);
            target.add(downloadValMsgButton);
            this.containerForm.getModelObject().getUpload()
                    .setUploadStatus(iArkCommonService.getUploadStatusFor(
                            au.org.theark.phenotypic.web.Constants.UPLOAD_STATUS_OF_ERROR_IN_DATA_VALIDATION));
            this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes 
            iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload());
        } else {
            this.containerForm.getModelObject().getUpload().setUploadStatus(iArkCommonService
                    .getUploadStatusFor(au.org.theark.phenotypic.web.Constants.UPLOAD_STATUS_OF_VALIDATED));
            this.containerForm.getModelObject().getUpload().setFilename(filename);//have to reset this because the container has the file name...luckily it never changes 
            iArkCommonService.updateUpload(this.containerForm.getModelObject().getUpload());
        }
    } else {
        validationMessage = "Step 2 is not completed properly.";
        addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());

    }
}

From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep4.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    if (containerForm.getModelObject().getPreviousStepOutCompleted()) {
        form.getNextButton().setEnabled(true);
        target.add(form.getNextButton());
        form.getArkExcelWorkSheetAsGrid().setVisible(false);
        target.add(form.getArkExcelWorkSheetAsGrid());
    } else {/*  w  w w  .  j  av  a  2 s  .  c o  m*/
        addOrReplace(new MultiLineLabel("multiLineLabel", "Step 3 is not completed properly."));
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    }
}

From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep4.java

License:Open Source License

@Override
public void onStepOutNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    form.getNextButton().setEnabled(false);
    target.add(form.getNextButton());
    // Filename seems to be lost from model when moving between steps in wizard?  is this a symptom of something greater?
    containerForm.getModelObject().getUpload().setFilename(wizardForm.getFileName());
    String fileFormat = containerForm.getModelObject().getUpload().getFileFormat().getName();
    char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType().getDelimiterCharacter();
    try {//w  w w . j av  a2  s .  c  o  m
        List<String> uidsToUpload = containerForm.getModelObject().getUidsToUpload();
        log.info("________________________________________________________"
                + "about to try passing list of uids is of size " + uidsToUpload.size());
        InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream();
        long size = containerForm.getModelObject().getFileUpload().getSize();
        Long uploadId = containerForm.getModelObject().getUpload().getId();
        String report = generateInitialUploadReport();
        Subject currentUser = SecurityUtils.getSubject();
        Long studyId = (Long) currentUser.getSession()
                .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
        PhenoDataSetCollection phenoCollectionCriteria = containerForm.getModelObject().getPhenoCollection();
        PhenoDataSetGroup phenoDataSetGroup = containerForm.getModelObject().getPhenoDataSetGroup();
        PhenoDataUploadExecutor task = new PhenoDataUploadExecutor(iArkCommonService, iPhenoService,
                inputStream, uploadId, //null user
                studyId, fileFormat, delimiterChar, size, report, uidsToUpload, phenoCollectionCriteria,
                phenoDataSetGroup, containerForm.getModelObject().getUpdateChkBox());
        task.run();
    } catch (Exception e1) {
        addOrReplace(new MultiLineLabel("multiLineLabel", "There is an issue during the data upload process."));
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
        containerForm.getModelObject().setPreviousStepOutCompleted(false);
    }
}

From source file:au.org.theark.phenotypic.web.component.phenodataupload.PhenoDataUploadStep5.java

License:Open Source License

@Override
public void handleWizardState(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    if (this.containerForm.getModelObject().getValidationMessages() != null
            && containerForm.getModelObject().getPreviousStepOutCompleted()) {
        form.getNextButton().setEnabled(false);
        target.add(form.getWizardButtonContainer());
    }//from w w  w  . jav  a2  s.  c o  m
}

From source file:au.org.theark.phenotypic.web.component.phenofielduploader.form.SearchForm.java

License:Open Source License

@Override
protected void onNew(AjaxRequestTarget target) {
    // NB: Should not be possible to get here (GUI should be using Wizard for new)
    // Due to ARK-108 :: No longer reset the VO onNew(..)
    PhenoDataSetFieldUploadVO uploadVo = getModelObject();
    uploadVo.setMode(au.org.theark.core.Constants.MODE_NEW);
    uploadVo.getUpload().setId(null); // must ensure Id is blank onNew
    setModelObject(uploadVo);//  w w w .j a v  a2s.c  o  m

    arkCrudContainerVO.getSearchResultPanelContainer().setVisible(false);
    arkCrudContainerVO.getSearchPanelContainer().setVisible(false);

    // Explicitly Show Wizard panel
    arkCrudContainerVO.getWizardPanelContainer().setVisible(true);
    arkCrudContainerVO.getWizardPanelContainer().setEnabled(true);

    target.add(arkCrudContainerVO.getSearchResultPanelContainer());
    target.add(arkCrudContainerVO.getSearchPanelContainer());
    target.add(arkCrudContainerVO.getDetailPanelFormContainer());
    target.add(arkCrudContainerVO.getWizardPanelContainer());
}

From source file:au.org.theark.phenotypic.web.component.phenofielduploader.PhenoDataSetCategoryFieldUploadStep2.java

License:Open Source License

@Override
public void onStepInNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {

    File temp = containerForm.getModelObject().getTempFile();

    if (temp != null && temp.exists()) {
        InputStream inputStream = null;
        try {/*  w w w  .j  a v  a  2 s .  co  m*/
            String filename = containerForm.getModelObject().getFileUpload().getClientFileName();
            String fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();
            char delimChar = containerForm.getModelObject().getUpload().getDelimiterType()
                    .getDelimiterCharacter();

            // Only allow csv, txt or xls
            if (!(fileFormat.equalsIgnoreCase("CSV") || fileFormat.equalsIgnoreCase("TXT")
                    || fileFormat.equalsIgnoreCase("XLS"))) {
                throw new FileFormatException();
            }
            inputStream = new BufferedInputStream(new FileInputStream(temp));
            if (containerForm.getModelObject().getUpload().getUploadLevel().getName()
                    .equalsIgnoreCase(Constants.UPLOAD_LEVEL_FIELD)) {
                PhenoDataSetFieldImportValidator phenoDataSetFieldImportValidator = new PhenoDataSetFieldImportValidator(
                        iArkCommonService, iPhenotypicService, containerForm.getModelObject());
                validationMessages = phenoDataSetFieldImportValidator
                        .validateCustomDataMatrixFileFormat(inputStream, fileFormat, delimChar);

            }
            //Categoty upload
            else if (containerForm.getModelObject().getUpload().getUploadLevel().getName()
                    .equalsIgnoreCase(Constants.UPLOAD_LEVEL_CATEGORY)) {
                PhenoDataSetFieldCategoryImportValidator phenoDataSetFieldCategoryImportValidator = new PhenoDataSetFieldCategoryImportValidator(
                        iArkCommonService, iPhenotypicService, containerForm.getModelObject());
                validationMessages = phenoDataSetFieldCategoryImportValidator
                        .validateCustomDataMatrixFileFormat(inputStream, fileFormat, delimChar);

            }
            inputStream.close();
            inputStream = null;
            containerForm.getModelObject().setValidationMessages(validationMessages);
            validationMessage = containerForm.getModelObject().getValidationMessagesAsString();
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
            if (validationMessage != null && validationMessage.length() > 0) {
                form.getNextButton().setEnabled(false);
                target.add(form.getWizardButtonContainer());
                downloadValMsgButton = new ArkDownloadAjaxButton("downloadValMsg", "ValidationMessage",
                        validationMessage, "txt") {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onError(AjaxRequestTarget target, Form<?> form) {
                        this.error("Unexpected Error: Download request could not be processed");
                    }

                };
                addOrReplace(downloadValMsgButton);
                target.add(downloadValMsgButton);
            }
            // Show file data
            FileUpload fileUpload = containerForm.getModelObject().getFileUpload();
            inputStream = new BufferedInputStream(new FileInputStream(temp));
            ArkExcelWorkSheetAsGrid arkExcelWorkSheetAsGrid = new ArkExcelWorkSheetAsGrid("gridView",
                    inputStream, fileFormat, delimChar, fileUpload, iArkCommonService
                            .getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue());
            inputStream.close();
            inputStream = null;
            arkExcelWorkSheetAsGrid.setOutputMarkupId(true);
            form.setArkExcelWorkSheetAsGrid(arkExcelWorkSheetAsGrid);
            form.getWizardPanelFormContainer().addOrReplace(arkExcelWorkSheetAsGrid);
            target.add(form.getWizardPanelFormContainer());
        }
        // TODO: Shouldn't catch NPEs because we should be checking for NULL in the first place (inherited from old code)
        catch (NullPointerException npe) {
            log.error("NullPointer " + npe.getMessage());
            validationMessage = "Error attempting to display the file. Please check the file and try again.";
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());
        } catch (IOException ioe) {
            log.error("IOException " + ioe.getMessage());
            validationMessage = "Error attempting to display the file. Please check the file and try again.";
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());
        } catch (FileFormatException ffe) {
            log.error("FileFormatException " + ffe.getMessage());
            validationMessage = "Error uploading file. You can only upload files of type: CSV (comma separated values), TXT (text), or XLS (Microsoft Excel file)";
            addOrReplace(new MultiLineLabel("multiLineLabel", validationMessage));
            form.getNextButton().setEnabled(false);
            target.add(form.getWizardButtonContainer());
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    log.error("Unable to close inputStream: " + e.getMessage());
                }
            }
        }
    } else {
        // Stop progress because of missing temp file
        error("Unexpected erorr: Can not proceed due to missing temporary file.");
        form.getNextButton().setEnabled(false);
    }
}

From source file:au.org.theark.phenotypic.web.component.phenofielduploader.PhenoDataSetCategoryFieldUploadStep3.java

License:Open Source License

private void initialiseDetailForm() {
    setValidationMessage(containerForm.getModelObject().getValidationMessagesAsString());
    addOrReplace(new MultiLineLabel("multiLineLabel", getValidationMessage()));
    add(downloadValMsgButton);/*  w  ww.  j  a  v  a  2  s.  c  o  m*/
    updateExistingDataContainer = new WebMarkupContainer("updateExistingDataContainer");
    updateExistingDataContainer.setOutputMarkupId(true);
    updateChkBox = new CheckBox("updateChkBox");
    updateChkBox.setVisible(true);
    containerForm.getModelObject().setUpdateChkBox(false);
    updateChkBox.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        private static final long serialVersionUID = -4514605801401294450L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (containerForm.getModelObject().getUpdateChkBox()) {
                wizardForm.getNextButton().setEnabled(true);
            } else {
                wizardForm.getNextButton().setEnabled(false);
            }
            target.add(wizardForm.getWizardButtonContainer());
        }
    });
    updateExistingDataContainer.add(updateChkBox);
    add(updateExistingDataContainer);
}