Package org.springframework.binding.value

Examples of org.springframework.binding.value.ValueModel


  protected AbstractFormModel(ValueModel domainObjectHolder, boolean buffered) {
    this(new BeanPropertyAccessStrategy(domainObjectHolder), buffered);
  }

  protected AbstractFormModel(MutablePropertyAccessStrategy propertyAccessStrategy, boolean buffered) {
    ValueModel domainObjectHolder = propertyAccessStrategy.getDomainObjectHolder();
    prepareValueModel(domainObjectHolder);
    this.formObjectHolder = new FormModelMediatingValueModel(domainObjectHolder, false);
    this.propertyAccessStrategy = propertyAccessStrategy;
    this.buffered = buffered;
    if (domainObjectHolder.getValue() != null)
      this.defaultInstanceClass = domainObjectHolder.getValue().getClass();
  }
View Full Code Here


  public boolean hasValueModel(String formProperty) {
    return propertyValueModels.containsKey(formProperty);
  }

  public ValueModel getValueModel(String formProperty) {
    ValueModel propertyValueModel = (ValueModel) propertyValueModels.get(formProperty);
    if (propertyValueModel == null) {
      propertyValueModel = add(formProperty);
    }
    return propertyValueModel;
  }
View Full Code Here

    return propertyValueModel;
  }

  public ValueModel getValueModel(String formProperty, Class targetClass) {
    final ConvertingValueModelKey key = new ConvertingValueModelKey(formProperty, targetClass);
    ValueModel convertingValueModel = (ValueModel) convertingValueModels.get(key);
    if (convertingValueModel == null) {
      convertingValueModel = createConvertingValueModel(formProperty, targetClass);
      convertingValueModels.put(key, convertingValueModel);
    }
    return convertingValueModel;
View Full Code Here

  protected ValueModel createConvertingValueModel(String formProperty, Class targetClass) {
    if (logger.isDebugEnabled()) {
      logger.debug("Creating converting value model for form property '" + formProperty
          + "' converting to type '" + targetClass + "'.");
    }
    final ValueModel sourceValueModel = getValueModel(formProperty);
    Assert.notNull(sourceValueModel, "Form does not have a property called '" + formProperty + "'.");
    final Class sourceClass = ClassUtils
        .convertPrimitiveToWrapper(getFieldMetadata(formProperty).getPropertyType());
    // sourceClass can be null when using eg Map, assume that given
    // targetClass is the correct one
    if ((sourceClass == null) || (sourceClass == targetClass)) {
      return sourceValueModel;
    }

    final ConversionService conversionService = getConversionService();
    ConversionExecutor convertTo = null;
    ConversionExecutor convertFrom = null;

    // Check for locally registered property converters
    if (propertyConversionServices.containsKey(formProperty)) {
      // TODO - extract ConfigurableConversionService interface...
      final GenericConversionService propertyConversionService = (GenericConversionService) propertyConversionServices
          .get(formProperty);

      if (propertyConversionService != null) {
        convertTo = propertyConversionService.getConversionExecutor(sourceClass, targetClass);
        convertFrom = propertyConversionService.getConversionExecutor(targetClass, sourceClass);
      }
    }

    // If we have nothing from the property level, then try the conversion
    // service
    if (convertTo == null) {
      convertTo = conversionService.getConversionExecutor(sourceClass, targetClass);
    }
    Assert.notNull(convertTo, "conversionService returned null ConversionExecutor");

    if (convertFrom == null) {
      convertFrom = conversionService.getConversionExecutor(targetClass, sourceClass);
    }
    Assert.notNull(convertFrom, "conversionService returned null ConversionExecutor");

    ValueModel convertingValueModel = preProcessNewConvertingValueModel(formProperty, targetClass,
        new TypeConverter(sourceValueModel, convertTo, convertFrom));
    preProcessNewConvertingValueModel(formProperty, targetClass, convertingValueModel);
    return convertingValueModel;
  }
View Full Code Here

  public ValueModel addMethod(String propertyMethodName, String[] derivedFromProperties) {
    ValueModel[] propertyValueModels = new ValueModel[derivedFromProperties.length];
    for (int i = 0; i < propertyValueModels.length; i++) {
      propertyValueModels[i] = getValueModel(derivedFromProperties[i]);
    }
    ValueModel valueModel = new MethodInvokingDerivedValueModel(this, propertyMethodName, propertyValueModels);
    return add(propertyMethodName, valueModel);
  }
View Full Code Here

        BufferedValueModel buffer = createDefaultBufferedValueModel();
       
        assertSame(wrapped, buffer.getWrappedValueModel());
        assertSame(wrapped, buffer.getInnerMostWrappedValueModel());
       
        ValueModel nestedValueModel = new AbstractValueModelWrapper(wrapped) {};
        buffer = new BufferedValueModel(nestedValueModel);
        assertSame(nestedValueModel, buffer.getWrappedValueModel());
        assertSame(wrapped, buffer.getInnerMostWrappedValueModel());
    }
View Full Code Here

    /**
     * Tests read actions on a read-only model.
     */
    public void testReadOnly() {
        TestBean bean = new TestBean();
        ValueModel readOnlyModel = new BeanPropertyAccessStrategy(bean).getPropertyValueModel("readOnly");
        BufferedValueModel buffer = new BufferedValueModel(readOnlyModel, commitTrigger);
       
        assertSame(
            "Can read values from a read-only model.",
            buffer.getValue(),
            readOnlyModel.getValue());
       
        Object newValue1 = "new value";
        buffer.setValue(newValue1);
        assertSame(
            "Can read values from a read-only model when buffering.",
View Full Code Here

  public Object getValue(String formProperty) {
    return formModel.getValueModel(formProperty).getValue();
  }

  public ValueModel getValueModel(String formProperty) {
    ValueModel valueModel = formModel.getValueModel(formProperty);
    if (valueModel == null) {
      logger.warn("A value model for property '" + formProperty + "' could not be found.  Typo?");
    }
    return valueModel;
  }
View Full Code Here

        return getBufferedCollectionValueModel(backingCollecton, backingCollecton.getClass());
    }

    private BufferedCollectionValueModel getBufferedCollectionValueModel(Object backingCollecton,
            Class backingCollectionClass) {
        ValueModel vm = new ValueHolder(backingCollecton);
        return new BufferedCollectionValueModel(vm, backingCollectionClass);
    }
View Full Code Here

  public void testGetValueModelFromPAS() {
    TestBean p = new TestBean();
    TestPropertyAccessStrategy tpas = new TestPropertyAccessStrategy(p);
    AbstractFormModel fm = getFormModel(tpas, true);
    ValueModel vm1 = fm.getValueModel("simpleProperty");
    assertEquals(1, tpas.numValueModelRequests());
    assertEquals("simpleProperty", tpas.lastRequestedValueModel());
    ValueModel vm2 = fm.getValueModel("simpleProperty");
    assertEquals(vm1, vm2);
    assertEquals(1, tpas.numValueModelRequests());

    try {
      fm.getValueModel("iDontExist");
View Full Code Here

TOP

Related Classes of org.springframework.binding.value.ValueModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.