Search in sources :

Example 1 with BeanEditContextImpl

use of org.apache.tapestry5.internal.BeanEditContextImpl in project tapestry-5 by apache.

the class BeanEditor method doPrepare.

/**
 * Used to initialize the model if necessary, to instantiate the object being edited if necessary, and to push the
 * BeanEditContext into the environment.
 */
void doPrepare() {
    if (model == null) {
        Class type = resources.getBoundType("object");
        model = modelSource.createEditModel(type, overrides.getOverrideMessages());
        BeanModelUtils.modify(model, add, include, exclude, reorder);
    }
    if (object == null) {
        try {
            object = model.newInstance();
        } catch (Exception ex) {
            String message = String.format("Exception instantiating instance of %s (for component '%s'): %s", PlasticUtils.toTypeName(model.getBeanType()), resources.getCompleteId(), ex);
            throw new TapestryException(message, resources.getLocation(), ex);
        }
    }
    BeanEditContext context = new BeanEditContextImpl(model.getBeanType());
    cachedObject = object;
    environment.push(BeanEditContext.class, context);
    // TAP5-2101: Always provide a new BeanValidationContext
    environment.push(BeanValidationContext.class, new BeanValidationContextImpl(object));
}
Also used : BeanEditContextImpl(org.apache.tapestry5.internal.BeanEditContextImpl) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) BeanEditContext(org.apache.tapestry5.services.BeanEditContext) BeanValidationContextImpl(org.apache.tapestry5.internal.BeanValidationContextImpl)

Aggregations

TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)1 BeanEditContextImpl (org.apache.tapestry5.internal.BeanEditContextImpl)1 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)1 BeanEditContext (org.apache.tapestry5.services.BeanEditContext)1