Search in sources :

Example 6 with FieldHandle

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);
}
Also used : ActivationRequestParameter(org.apache.tapestry5.annotations.ActivationRequestParameter) ValueEncoder(org.apache.tapestry5.ValueEncoder) PlasticClass(org.apache.tapestry5.plastic.PlasticClass) FieldHandle(org.apache.tapestry5.plastic.FieldHandle)

Example 7 with FieldHandle

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);
        }
    };
}
Also used : ComponentEventHandler(org.apache.tapestry5.services.ComponentEventHandler) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Component(org.apache.tapestry5.runtime.Component) FieldHandle(org.apache.tapestry5.plastic.FieldHandle)

Aggregations

FieldHandle (org.apache.tapestry5.plastic.FieldHandle)4 Component (org.apache.tapestry5.runtime.Component)4 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)4 ComponentEventHandler (org.apache.tapestry5.services.ComponentEventHandler)4 Binding (org.apache.tapestry5.Binding)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 ValueEncoder (org.apache.tapestry5.ValueEncoder)1 ActivationRequestParameter (org.apache.tapestry5.annotations.ActivationRequestParameter)1 PageActivationContext (org.apache.tapestry5.annotations.PageActivationContext)1 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)1 Link (org.apache.tapestry5.http.Link)1 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)1 PlasticField (org.apache.tapestry5.plastic.PlasticField)1