use of com.manydesigns.elements.reflection.ClassAccessor in project Portofino by ManyDesigns.
the class NumericFieldTest method testFormattedWithModifiers.
public void testFormattedWithModifiers() throws NoSuchFieldException {
ClassAccessor classAccessor = JavaClassAccessor.getClassAccessor(this.getClass());
PropertyAccessor myPropertyAccessor = classAccessor.getProperty("myFormattedDecimalWithModifiers");
decimalField = new NumericField(myPropertyAccessor, Mode.EDIT, null);
decimalField.setStringValue("aaa1,234.5bbb");
assertTrue(decimalField.validate());
assertEquals(decimalField.getValue(), new BigDecimal("123.4"));
decimalField.setStringValue("aaa1.234,5bbb");
assertFalse(decimalField.validate());
// Out of range, max is 10^precision
decimalField.setStringValue("aaa1,234,567.8bbb");
assertFalse(decimalField.validate());
// Leave only Italian locale
req.locales.remove(0);
decimalField = new NumericField(myPropertyAccessor, Mode.EDIT, null);
decimalField.setStringValue("aaa1,234.5bbb");
assertFalse(decimalField.validate());
decimalField.setStringValue("aaa1.234,5bbb");
assertTrue(decimalField.validate());
assertEquals(decimalField.getValue(), new BigDecimal("123.4"));
}
use of com.manydesigns.elements.reflection.ClassAccessor in project Portofino by ManyDesigns.
the class NumericFieldTest method testFormatted.
public void testFormatted() throws NoSuchFieldException {
ClassAccessor classAccessor = JavaClassAccessor.getClassAccessor(this.getClass());
PropertyAccessor myPropertyAccessor = classAccessor.getProperty("myFormattedDecimal");
decimalField = new NumericField(myPropertyAccessor, Mode.EDIT, null);
decimalField.setStringValue("aaa1,234.5bbb");
assertEquals(decimalField.getValue(), new BigDecimal("1234"));
assertTrue(decimalField.validate());
decimalField.setStringValue("aaa1.234,5bbb");
assertFalse(decimalField.validate());
// Leave only Italian locale
req.locales.remove(0);
decimalField = new NumericField(myPropertyAccessor, Mode.EDIT, null);
decimalField.setStringValue("aaa1,234.5bbb");
assertFalse(decimalField.validate());
decimalField.setStringValue("aaa1.234,5bbb");
assertTrue(decimalField.validate());
assertEquals(decimalField.getValue(), new BigDecimal("1234"));
}
use of com.manydesigns.elements.reflection.ClassAccessor in project Portofino by ManyDesigns.
the class AbstractCrudAction method setActionInstance.
// --------------------------------------------------------------------------
// Setup
// --------------------------------------------------------------------------
@Override
public void setActionInstance(ActionInstance actionInstance) {
super.setActionInstance(actionInstance);
this.crudConfiguration = (CrudConfiguration) actionInstance.getConfiguration();
if (crudConfiguration == null) {
logger.warn("Crud is not configured: " + actionInstance.getPath());
return;
}
ClassAccessor innerAccessor = prepare(actionInstance);
if (innerAccessor == null) {
return;
}
classAccessor = filterAccordingToPermissions(new CrudAccessor(crudConfiguration, innerAccessor));
idStrategy = getIdStrategy(classAccessor, innerAccessor);
maxParameters = classAccessor.getKeyProperties().length;
}
Aggregations