Example usage for org.springframework.beans.propertyeditors StringTrimmerEditor StringTrimmerEditor

List of usage examples for org.springframework.beans.propertyeditors StringTrimmerEditor StringTrimmerEditor

Introduction

In this page you can find the example usage for org.springframework.beans.propertyeditors StringTrimmerEditor StringTrimmerEditor.

Prototype

public StringTrimmerEditor(boolean emptyAsNull) 

Source Link

Document

Create a new StringTrimmerEditor.

Usage

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:com.jaspersoft.jasperserver.war.action.ReportJobEditAction.java

protected void initBinder(RequestContext context, DataBinder binder) {
    super.initBinder(context, binder);

    binder.registerCustomEditor(List.class, "mailNotification.toAddresses", mailAddressesEditor);
    binder.registerCustomEditor(List.class, "mailNotification.ccAddresses", mailAddressesEditor);
    binder.registerCustomEditor(List.class, "mailNotification.bccAddresses", mailAddressesEditor);

    // create a fresh date editor so that is uses the current locale
    CustomDateEditor customDateEditor = new CustomDateEditor(
            JasperServerUtil.createCalendarDateTimeFormat(getMessageSource()), true);
    binder.registerCustomEditor(Date.class, customDateEditor);

    binder.registerCustomEditor(Integer.class, customNumberEditor);
    binder.registerCustomEditor(Set.class, "outputFormats", byteSetEditor);
    binder.registerCustomEditor(SortedSet.class, "trigger.weekDays", byteSortedSetEditor);
    binder.registerCustomEditor(SortedSet.class, "trigger.months", byteSortedSetEditor);
    binder.registerCustomEditor(String.class, "contentRepositoryDestination.timestampPattern",
            new StringTrimmerEditor(true));
}

From source file:com.jaspersoft.jasperserver.war.action.ReportDataSourceAction.java

protected void initBinder(RequestContext requestContext, DataBinder binder) {
    super.initBinder(requestContext, binder);

    binder.registerCustomEditor(String.class, "reportDataSource.beanMethod", new StringTrimmerEditor(true));
    binder.registerCustomEditor(String.class, "reportDataSource.timezone", new StringTrimmerEditor(true));
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testLargeMatchingPrimitiveArray() {
    if (LogFactory.getLog(BeanWrapperTests.class).isTraceEnabled()) {
        // Skip this test: Trace logging blows the time limit.
        return;//from   ww  w  .j  av  a  2 s. co m
    }

    PrimitiveArrayBean tb = new PrimitiveArrayBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    int[] input = new int[1024];
    StopWatch sw = new StopWatch();
    sw.start("array1");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    long time1 = sw.getLastTaskTimeMillis();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
    sw.start("array2");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

    bw.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
    sw.start("array4");
    for (int i = 0; i < 100; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testCollectionsWithStringValuesAndCustomEditor() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    bw.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
    bw.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

    bw.setPropertyValue("set", "set1 ");
    bw.setPropertyValue("sortedSet", "sortedSet1");
    bw.setPropertyValue("list", "list1 ");
    assertEquals(1, tb.getSet().size());
    assertTrue(tb.getSet().contains("set1"));
    assertEquals(1, tb.getSortedSet().size());
    assertTrue(tb.getSortedSet().contains("sortedSet1"));
    assertEquals(1, tb.getList().size());
    assertTrue(tb.getList().contains("list1"));

    bw.setPropertyValue("list", Arrays.asList(new String[] { "list1 " }));
    assertTrue(tb.getList().contains("list1"));
}

From source file:org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java

/**
 * Invoked on every request to provide the ability to register specific binders for Spring's binding process.
 * By default, we register a binder that treats empty Strings as null and a Boolean editor that supports either true
 * or false. If the value is passed in as null, it will treat it as false.
 * //from ww w .ja v  a  2s. co  m
 * @param binder
 */
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    binder.registerCustomEditor(Boolean.class, new NonNullBooleanEditor());
}

From source file:org.jtalks.jcommune.web.controller.TopicController.java

/**
 * This method turns the trim binder on. Trim binder
 * removes leading and trailing spaces from the submitted fields.
 * So, it ensures, that all validations will be applied to
 * trimmed field values only.//w ww  . ja  v  a2  s  . c om
 *
 * @param binder Binder object to be injected
 */
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    binder.registerCustomEditor(DateTime.class, new DateTimeEditor("dd-MM-yyyy"));
}

From source file:org.jtalks.jcommune.web.controller.UserController.java

/**
 * This method turns the trim binder on. Trim binder
 * removes leading and trailing spaces from the submitted fields.
 * So, it ensures, that all validations will be applied to
 * trimmed field values only./*w  w  w  .  j  a  va 2 s  . com*/
 * <p/> There is no need for trim edit password fields,
 * so they are processed with {@link DefaultStringEditor}
 *
 * @param binder Binder object to be injected
 */
@InitBinder({ "dto", "newUser" })
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    binder.registerCustomEditor(String.class, "userDto.username", new StringTrimmerEditor(false));
    binder.registerCustomEditor(String.class, "userDto.password", new DefaultStringEditor(false));
    binder.registerCustomEditor(String.class, "passwordConfirm", new DefaultStringEditor(false));
}

From source file:org.shept.org.springframework.web.bind.support.FilterBindingInitializer.java

public void initBinder(WebRequest request, ComponentDataBinder binder, String componentPath) {
    if (logger.isInfoEnabled()) {
        logger.info("Register custom binding initializers");
    }//w  w w . j a  va2  s  .c  o m

    // Locale dependent registry - we should improve that - use java.text.spi ?
    Locale locale = RequestContextUtils.getLocale(((ServletWebRequest) request).getRequest());

    String format = formatResolver.resolveProperty(locale, DateTimeLocaleConstants.DATETIME_FORMAT_LONG);

    // register 'nullable' bean editors for all Strings within filter  objects
    // This way empty fields will not be part of the search criteria

    Map<String, CommandWrapper> pathMap = Collections.emptyMap();
    if (binder.getTarget() instanceof SubCommandProvider) {
        pathMap = ComponentUtils.getComponentPathMap((SubCommandProvider) binder.getTarget());
        CommandWrapper wrapper = pathMap.get(componentPath);
        if (wrapper.getCommand() instanceof FilteredListHolder) {
            FilteredListHolder flh = (FilteredListHolder) wrapper.getCommand();
            FilterDefinition filterDef = flh.getFilter();
            String path = ComponentUtils.getPropertyPathPrefix(componentPath)
                    + FilteredListHolder.FILTER_BINDING_NAME + PropertyAccessor.NESTED_PROPERTY_SEPARATOR;

            for (Field field : filterDef.getClass().getDeclaredFields()) {
                String propPath = path + field.getName();
                if (field.getType().equals(String.class)) {
                    binder.registerCustomEditor(String.class, propPath, new StringTrimmerEditor(true));
                    if (logger.isInfoEnabled()) {
                        logger.info("Registered nullable StringEditor for " + propPath);
                    }
                } else if (field.getType().equals(Calendar.class)) {
                    format = formatResolver.resolveProperty(locale, DateTimeLocaleConstants.DATE_FORMAT_SHORT);
                    binder.registerCustomEditor(Calendar.class, propPath,
                            new CustomCalendarEditor(new SimpleDateFormat(format), true));
                    if (logger.isInfoEnabled()) {
                        logger.info("Registered Calendar Editor for " + propPath);
                    }
                } else {
                    registerDependendEntities(binder, field.getType(), path + field.getName());
                }
            }
        }
    }
}

From source file:org.shept.org.springframework.web.bind.support.FilterBindingInitializer.java

private void registerDependendEntities(ComponentDataBinder binder, Class clazz, String path) {
    Object ann = AnnotationUtils.findAnnotation(clazz, Entity.class);
    if (ann == null)
        return;//from w w w .jav  a2s  . co m
    for (Field field : clazz.getDeclaredFields()) {
        String propPath = path + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + field.getName();
        if (field.getType().equals(String.class)) {
            binder.registerCustomEditor(String.class, propPath, new StringTrimmerEditor(true));
            if (logger.isInfoEnabled()) {
                logger.info("Registered nullable StringEditor for " + propPath);
            }
        } else {
            // here we need to prevent infinte recursions for example if a user contains a user contains a user ...
            Integer depth = StringUtils.countOccurrencesOf(path, PropertyAccessor.NESTED_PROPERTY_SEPARATOR);
            if (depth <= maxDepth) {
                registerDependendEntities(binder, field.getType(), propPath);
            }
        }
    }
}