Search in sources :

Example 16 with ClassAccessor

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"));
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) JavaClassAccessor(com.manydesigns.elements.reflection.JavaClassAccessor) ClassAccessor(com.manydesigns.elements.reflection.ClassAccessor) BigDecimal(java.math.BigDecimal)

Example 17 with ClassAccessor

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"));
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) JavaClassAccessor(com.manydesigns.elements.reflection.JavaClassAccessor) ClassAccessor(com.manydesigns.elements.reflection.ClassAccessor) BigDecimal(java.math.BigDecimal)

Example 18 with ClassAccessor

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;
}
Also used : ClassAccessor(com.manydesigns.elements.reflection.ClassAccessor) CrudAccessor(com.manydesigns.portofino.resourceactions.crud.reflection.CrudAccessor)

Aggregations

ClassAccessor (com.manydesigns.elements.reflection.ClassAccessor)18 JavaClassAccessor (com.manydesigns.elements.reflection.JavaClassAccessor)14 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)13 FilteredClassAccessor (com.manydesigns.elements.reflection.FilteredClassAccessor)2 BigDecimal (java.math.BigDecimal)2 FileObject (org.apache.commons.vfs2.FileObject)2 Session (org.hibernate.Session)2 JSONStringer (org.json.JSONStringer)2 FileBlob (com.manydesigns.elements.annotations.FileBlob)1 Blob (com.manydesigns.elements.blobs.Blob)1 HierarchicalBlobManager (com.manydesigns.elements.blobs.HierarchicalBlobManager)1 AbstractBlobField (com.manydesigns.elements.fields.AbstractBlobField)1 Field (com.manydesigns.elements.fields.Field)1 FileBlobField (com.manydesigns.elements.fields.FileBlobField)1 DateSearchField (com.manydesigns.elements.fields.search.DateSearchField)1 MutableHttpServletRequest (com.manydesigns.elements.servlet.MutableHttpServletRequest)1 ActionDescriptor (com.manydesigns.portofino.actions.ActionDescriptor)1 Annotation (com.manydesigns.portofino.model.Annotation)1 Model (com.manydesigns.portofino.model.Model)1 Property (com.manydesigns.portofino.model.Property)1