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);
}
}
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();
}
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);
}
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);
}
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);
}
}
}
Aggregations