use of org.apache.tapestry5.plastic.FieldHandle in project tapestry-5 by apache.
the class ActivationRequestParameterWorker method mapFieldToQueryParameter.
private void mapFieldToQueryParameter(PlasticField field, TransformationSupport support) {
ActivationRequestParameter annotation = field.getAnnotation(ActivationRequestParameter.class);
String parameterName = getParameterName(field, annotation);
// Assumption: the field type is not one that's loaded by the component class loader, so it's safe
// to convert to a hard type during class transformation.
Class fieldType = classCache.forName(field.getTypeName());
ValueEncoder encoder = valueEncoderSource.getValueEncoder(fieldType);
FieldHandle handle = field.getHandle();
String fieldName = String.format("%s.%s", field.getPlasticClass().getClassName(), field.getName());
setValueFromInitializeEventHandler(support, fieldName, annotation.required(), handle, parameterName, encoder, urlEncoder);
decorateLinks(support, fieldName, handle, parameterName, encoder, urlEncoder);
preallocateName(support, parameterName);
}
use of org.apache.tapestry5.plastic.FieldHandle in project tapestry-5 by apache.
the class PageActivationContextWorker method createPassivateHandler.
private static ComponentEventHandler createPassivateHandler(final FieldHandle[] handles) {
return new ComponentEventHandler() {
public void handleEvent(Component instance, ComponentEvent event) {
Object result;
if (handles.length == 1) {
// simple / common case for a single @PageActivationContext
result = handles[0].get(instance);
} else {
LinkedList<Object> list = CollectionFactory.newLinkedList();
// iterate backwards
for (int i = handles.length - 1; i > -1; i--) {
FieldHandle handle = handles[i];
Object value = handle.get(instance);
// ignore trailing nulls
if (value != null || !list.isEmpty()) {
list.addFirst(value);
}
}
result = list.isEmpty() ? null : list;
}
event.storeResult(result);
}
};
}
Aggregations