Search in sources :

Example 16 with InternalComponentResources

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

the class AbstractField method putPropertyNameIntoBeanValidationContext.

protected void putPropertyNameIntoBeanValidationContext(String parameterName) {
    if (beanValidationDisabled) {
        return;
    }
    String propertyName = ((InternalComponentResources) resources).getPropertyName(parameterName);
    BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
    if (beanValidationContext == null)
        return;
    // If field is inside BeanEditForm, then property is already set
    if (beanValidationContext.getCurrentProperty() == null) {
        beanValidationContext.setCurrentProperty(propertyName);
    }
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) BeanValidationContext(org.apache.tapestry5.internal.BeanValidationContext)

Example 17 with InternalComponentResources

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

the class SelectTest method checkSubmittedOption.

/**
 * Utility for testing the "secure" option with various values and model
 * states. This avoids a lot of redundant test setup code.
 *
 * @param withModel whether there should be a model to test against
 * @param secureOption which "secure" option to test
 * @param expectedError the expected error message, nor null if no error
 * @throws ValidationException
 */
private void checkSubmittedOption(boolean withModel, SecureOption secureOption, String expectedError) throws ValidationException {
    ValueEncoder<Platform> encoder = getService(ValueEncoderSource.class).getValueEncoder(Platform.class);
    ValidationTracker tracker = mockValidationTracker();
    Request request = mockRequest();
    Messages messages = mockMessages();
    FieldValidationSupport fvs = mockFieldValidationSupport();
    TypeCoercer typeCoercer = mockTypeCoercer();
    InternalComponentResources resources = mockInternalComponentResources();
    Binding selectModelBinding = mockBinding();
    expect(request.getParameter("xyz")).andReturn("MAC");
    expect(messages.contains(EasyMock.anyObject(String.class))).andReturn(false).anyTimes();
    expect(resources.getBinding("model")).andReturn(selectModelBinding);
    final Holder<SelectModel> modelHolder = Holder.create();
    expect(typeCoercer.coerce(EasyMock.or(EasyMock.isA(SelectModel.class), EasyMock.isNull()), EasyMock.eq(SelectModel.class))).andAnswer(new IAnswer<SelectModel>() {

        @Override
        public SelectModel answer() throws Throwable {
            return modelHolder.get();
        }
    });
    expect(selectModelBinding.get()).andAnswer(new IAnswer<SelectModel>() {

        @Override
        public SelectModel answer() throws Throwable {
            return modelHolder.get();
        }
    });
    Select select = new Select();
    tracker.recordInput(select, "MAC");
    // when not failing we will expect to call the fvs.validate method
    if (expectedError == null) {
        fvs.validate(Platform.MAC, resources, null);
    } else {
        tracker.recordError(EasyMock.eq(select), EasyMock.contains(expectedError));
    }
    replay();
    if (withModel) {
        modelHolder.put(new EnumSelectModel(Platform.class, messages));
    }
    set(select, "encoder", encoder);
    set(select, "model", modelHolder.get());
    set(select, "request", request);
    set(select, "secure", secureOption);
    // Disable BeanValidationContextSupport
    set(select, "beanValidationDisabled", true);
    set(select, "tracker", tracker);
    set(select, "fieldValidationSupport", fvs);
    set(select, "typeCoercer", typeCoercer);
    set(select, "resources", resources);
    select.processSubmission("xyz");
    if (expectedError == null) {
        assertEquals(get(select, "value"), Platform.MAC);
    }
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) Platform(org.apache.tapestry5.corelib.components.SelectTest.Platform) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) Request(org.apache.tapestry5.http.services.Request) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) EnumSelectModel(org.apache.tapestry5.util.EnumSelectModel) EnumSelectModel(org.apache.tapestry5.util.EnumSelectModel)

Example 18 with InternalComponentResources

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

the class BindParameterWorker method createConduit.

private FieldConduit<Object> createConduit(final ComponentResources resources, final String fieldTypeName, final String fieldName, final String[] possibleNames) {
    if (!resources.isMixin())
        throw new TapestryException(String.format("@BindParameter was used on field '%s' of component class '%s', but @BindParameter should only be used in mixins.", fieldName, resources.getComponentModel().getComponentClassName()), null);
    InternalComponentResources containerResources = (InternalComponentResources) resources.getContainerResources();
    // Evaluate this early so that we get a fast fail.
    String containerParameterName = identifyParameterName(resources, InternalUtils.stripMemberName(fieldName), possibleNames);
    Class fieldType = componentClassCache.forName(fieldTypeName);
    return new BoundParameterFieldValueConduit(containerParameterName, containerResources, fieldType);
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 19 with InternalComponentResources

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

the class PersistWorker method makeFieldPersistent.

private void makeFieldPersistent(PlasticField field, MutableComponentModel model) {
    Persist annotation = field.getAnnotation(Persist.class);
    field.claim(annotation);
    final String logicalFieldName = model.setFieldPersistenceStrategy(field.getName(), annotation.value());
    final Object defaultValue = determineDefaultValueFromFieldType(field);
    ComputedValue<FieldConduit<Object>> computed = new ComputedValue<FieldConduit<Object>>() {

        public FieldConduit<Object> get(InstanceContext context) {
            InternalComponentResources resources = context.get(InternalComponentResources.class);
            return new PersistentFieldConduit(resources, logicalFieldName, defaultValue);
        }
    };
    field.setComputedConduit(computed);
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) Persist(org.apache.tapestry5.annotations.Persist)

Example 20 with InternalComponentResources

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

the class ComponentPageElementImpl method addUnboundParameterNames.

private void addUnboundParameterNames(String prefix, List<String> unbound, InternalComponentResources resource) {
    ComponentModel model = resource.getComponentModel();
    for (String name : model.getParameterNames()) {
        if (resource.isBound(name))
            continue;
        ParameterModel parameterModel = model.getParameterModel(name);
        if (parameterModel.isRequired()) {
            String fullName = prefix == null ? name : prefix + "." + name;
            unbound.add(fullName);
        }
    }
}
Also used : ParameterModel(org.apache.tapestry5.model.ParameterModel) ComponentModel(org.apache.tapestry5.model.ComponentModel)

Aggregations

InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)22 Test (org.testng.annotations.Test)10 ComponentModel (org.apache.tapestry5.model.ComponentModel)9 Component (org.apache.tapestry5.runtime.Component)8 Instantiator (org.apache.tapestry5.internal.services.Instantiator)7 Binding (org.apache.tapestry5.Binding)5 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)4 InternalPropBinding (org.apache.tapestry5.internal.bindings.InternalPropBinding)4 MarkupWriter (org.apache.tapestry5.MarkupWriter)3 Request (org.apache.tapestry5.http.services.Request)3 ValueEncoderSource (org.apache.tapestry5.services.ValueEncoderSource)3 Messages (org.apache.tapestry5.commons.Messages)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 Platform (org.apache.tapestry5.corelib.components.SelectTest.Platform)2 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)2 ParameterModel (org.apache.tapestry5.model.ParameterModel)2 EnumSelectModel (org.apache.tapestry5.util.EnumSelectModel)2 ComponentResources (org.apache.tapestry5.ComponentResources)1 EventContext (org.apache.tapestry5.EventContext)1 Persist (org.apache.tapestry5.annotations.Persist)1