Example usage for org.springframework.web.bind ServletRequestDataBinder getTarget

List of usage examples for org.springframework.web.bind ServletRequestDataBinder getTarget

Introduction

In this page you can find the example usage for org.springframework.web.bind ServletRequestDataBinder getTarget.

Prototype

@Nullable
public Object getTarget() 

Source Link

Document

Return the wrapped target object.

Usage

From source file:org.openmrs.web.controller.program.ProgramFormController.java

protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    super.initBinder(request, binder);

    // this depends on this form being a "session-form" (defined in openrms-servlet.xml)
    Program program = (Program) binder.getTarget();

    binder.registerCustomEditor(Concept.class, new ConceptEditor());
    binder.registerCustomEditor(java.util.Collection.class, "allWorkflows",
            new WorkflowCollectionEditor(program));
}

From source file:org.openmrs.web.controller.ConceptFormController.java

/**
 * Allows for other Objects to be used as values in input tags. Normally, only strings and lists
 * are expected/*from w ww.  j  a  v  a2s .co  m*/
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 *      org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    super.initBinder(request, binder);

    ConceptFormBackingObject commandObject = (ConceptFormBackingObject) binder.getTarget();

    NumberFormat nf = NumberFormat.getInstance(Context.getLocale());
    binder.registerCustomEditor(java.lang.Integer.class,
            new CustomNumberEditor(java.lang.Integer.class, nf, true));
    binder.registerCustomEditor(java.lang.Double.class,
            new CustomNumberEditor(java.lang.Double.class, nf, true));
    binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(
            SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Context.getLocale()), true));
    binder.registerCustomEditor(org.openmrs.ConceptClass.class, new ConceptClassEditor());
    binder.registerCustomEditor(org.openmrs.ConceptDatatype.class, new ConceptDatatypeEditor());
    binder.registerCustomEditor(java.util.Collection.class, "concept.conceptSets",
            new ConceptSetsEditor(commandObject.getConcept().getConceptSets()));
    binder.registerCustomEditor(java.util.Collection.class, "concept.answers",
            new ConceptAnswersEditor(commandObject.getConcept().getAnswers(true)));
    binder.registerCustomEditor(org.openmrs.ConceptSource.class, new ConceptSourceEditor());
    binder.registerCustomEditor(ConceptMapType.class, new ConceptMapTypeEditor());
    binder.registerCustomEditor(ConceptReferenceTerm.class, new ConceptReferenceTermEditor());
}

From source file:edu.duke.cabig.c3pr.web.registration.RegistrationController.java

@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.setAutoGrowNestedPaths(Boolean.FALSE);
    super.initBinder(request, binder);
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, true));
    binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true));
    binder.registerCustomEditor(HealthcareSite.class, new CustomDaoEditor(healthcareSiteDao));
    binder.registerCustomEditor(EligibilityCriteria.class, new CustomDaoEditor(studySiteDao));
    binder.registerCustomEditor(Participant.class, new CustomDaoEditor(participantDao));
    binder.registerCustomEditor(ICD9DiseaseSite.class, new CustomDaoEditor(icd9DiseaseSiteDao));
    binder.registerCustomEditor(Arm.class, new CustomDaoEditor(armDao));
    binder.registerCustomEditor(Epoch.class, new CustomDaoEditor(epochDao));
    binder.registerCustomEditor(Consent.class, new CustomDaoEditor(consentDao));
    binder.registerCustomEditor(PersonUser.class, new CustomDaoEditor(personUserDao));
    binder.registerCustomEditor(StratificationCriterionPermissibleAnswer.class,
            new CustomDaoEditor(stratificationAnswerDao));
    Object command = binder.getTarget();
    binder.registerCustomEditor(StudyDisease.class,
            new ObjectGraphBasedEditor(command, "studySubject.studySite.study.studyDiseases"));
    binder.registerCustomEditor(StudyInvestigator.class, new CustomDaoEditor(studyInvestigatorDao));
    binder.registerCustomEditor(ScheduledEpoch.class, new CustomDaoEditor(scheduledEpochDao));
    binder.registerCustomEditor(RandomizationType.class, new EnumByNameEditor(RandomizationType.class));
    binder.registerCustomEditor(RegistrationDataEntryStatus.class,
            new EnumByNameEditor(RegistrationDataEntryStatus.class));
    binder.registerCustomEditor(RegistrationWorkFlowStatus.class,
            new EnumByNameEditor(RegistrationWorkFlowStatus.class));
    binder.registerCustomEditor(ScheduledEpochDataEntryStatus.class,
            new EnumByNameEditor(ScheduledEpochDataEntryStatus.class));
    binder.registerCustomEditor(ScheduledEpochWorkFlowStatus.class,
            new EnumByNameEditor(ScheduledEpochWorkFlowStatus.class));
    binder.registerCustomEditor(ICD9DiseaseSiteCodeDepth.class,
            new EnumByNameEditor(ICD9DiseaseSiteCodeDepth.class));
    binder.registerCustomEditor(OrganizationIdentifierTypeEnum.class,
            new EnumByNameEditor(OrganizationIdentifierTypeEnum.class));
    binder.registerCustomEditor(ConsentingMethod.class, new EnumByNameEditor(ConsentingMethod.class));
    binder.registerCustomEditor(Reason.class, new CustomDaoEditor(reasonDao));
    binder.registerCustomEditor(ConsentingMethod.class, new EnumByNameEditor(ConsentingMethod.class));
    binder.registerCustomEditor(AMPMEnum.class, new EnumByNameEditor(AMPMEnum.class));
    binder.registerCustomEditor(TimeZoneEnum.class, new EnumByNameEditor(TimeZoneEnum.class));
}

From source file:org.gbif.portal.web.controller.registration.RegistrationController.java

/**
 * Because the page can dynamically add more Secondary contacts, ensure that the contacts list in the command object
 * is of sufficient size to handle it.//from   w  w  w. j av a  2  s  .c o  m
 * 
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 *      org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    if (binder.getTarget() instanceof ProviderDetail) {
        initProviderBinder(request, binder);
    } else if (binder.getTarget() instanceof ResourceDetail) {
        initResourceDetailBinder(request, binder);
    }
}

From source file:org.gbif.portal.web.controller.registration.RegistrationController.java

/**
 * Initialises the binder for a provider
 * This handles the resizing of the secondary contacts and resources
 *//*from   ww w. ja  va 2  s.  c  o  m*/
protected void initProviderBinder(HttpServletRequest request, ServletRequestDataBinder binder)
        throws Exception {
    ProviderDetail providerDetail = (ProviderDetail) binder.getTarget();
    logger.info("Checking to see if the contacts list needs padded");
    int maxSecondaryIndex = getMaxIndex(request, "businessSecondaryContacts");
    logger.info("maxSecondaryIndex: " + maxSecondaryIndex);
    int currentSize = providerDetail.getBusinessSecondaryContacts().size();
    logger.info("currentSize: " + currentSize);
    if (maxSecondaryIndex + 1 > currentSize) {
        for (int i = 0; i < (maxSecondaryIndex + 1 - currentSize); i++) {
            logger.info("creating a padded contact");
            providerDetail.getBusinessSecondaryContacts().add(providerDetail.new Contact());
        }
    } else if (maxSecondaryIndex + 1 < currentSize) {
        // shrink it if it's a submit - e.g contacts deleted
        if (isFormSubmission(request)) {
            logger.info("shrinking");
            providerDetail.setBusinessSecondaryContacts(
                    providerDetail.getBusinessSecondaryContacts().subList(0, maxSecondaryIndex + 1));
        }
    }

    logger.info("Checking to see if the resource list needs padded");
    int maxResourceIndex = getMaxIndex(request, "businessResources");
    logger.info("maxResourceIndex: " + maxResourceIndex);
    currentSize = providerDetail.getBusinessResources().size();
    logger.info("currentSize: " + currentSize);
    if (maxResourceIndex + 1 > currentSize) {
        for (int i = 0; i < (maxResourceIndex + 1 - currentSize); i++) {
            logger.info("creating a padded resource");
            providerDetail.getBusinessResources().add(new ResourceDetail());
        }
    } else if (maxResourceIndex + 1 < currentSize) {
        // shrink it if it's a submit - e.g contacts deleted
        if (isFormSubmission(request)) {
            logger.info("shrinking");
            providerDetail.setBusinessResources(
                    providerDetail.getBusinessResources().subList(0, maxResourceIndex + 1));
        }
    }
}

From source file:org.gbif.portal.web.controller.registration.RegistrationController.java

/**
 * Initialises the binder for a provider
 * This handles the resizing of the secondary contacts and resources
 *//*w ww  .j  a  v  a2  s .  c o  m*/
protected void initResourceDetailBinder(HttpServletRequest request, ServletRequestDataBinder binder)
        throws Exception {
    ResourceDetail resourceDetail = (ResourceDetail) binder.getTarget();
    String relatesToCountries = request.getParameter("relatesToCountries");
    if (StringUtils.isNotEmpty(relatesToCountries)) {
        ArrayList<String> relatesToCountriesList = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(relatesToCountries, ",");
        while (st.hasMoreTokens()) {
            String iso = st.nextToken();
            if (iso != null && iso.length() > 0)
                relatesToCountriesList.add(iso);
        }
        resourceDetail.setRelatesToCountries(relatesToCountriesList);
    }

    // check for N/A values
    Date startDate = DateUtil.getDateFromRequest(request, "startDate");
    Date endDate = DateUtil.getDateFromRequest(request, "endDate");
    resourceDetail.setStartDate(startDate);
    resourceDetail.setEndDate(endDate);

    // set N/A values to null
    if ("N/A".equals(resourceDetail.getRecordBasis()))
        resourceDetail.setRecordBasis(null);
    if ("N/A".equals(resourceDetail.getOwnerCountry()))
        resourceDetail.setOwnerCountry(null);
    if ("N/A".equals(resourceDetail.getIndexingStartTime()))
        resourceDetail.setIndexingStartTime(null);
    if ("N/A".equals(resourceDetail.getIndexingFrequency()))
        resourceDetail.setIndexingFrequency(null);
    if ("N/A".equals(resourceDetail.getIndexingMaxDuration()))
        resourceDetail.setIndexingMaxDuration(null);
}