cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hunsberger, Peter" <>
Subject Accessing flow context attributes
Date Fri, 02 Jan 2004 23:08:00 GMT
As per my previous post I'm having problems accessing a request
parameter if it was previously set via the query string.  Assuming that
the query string always overrides the request parameters I figured a
good alternative would be to move the management of this particular
variable out of the front end requesting frame and into the back end
flow script; in this particular case it helps determine what screen to
show and makes perfect sense in the flow script.  So I coded a flow
script with statements like:

    cocoon.sendPage( "run/_page/" + collection, {
"layout_type_preference" : "list" } );

However, this particular parameter is actually needed in a generator.
I'll end up setting a request attribute and managing things that way.
However, while figuring this all out I took an interesting tour through
the guts of Cocoon and discovered what looks like the same code cut and
pasted about a dozen times through out the Cocoon source.  In
particular, everyone uses almost the same code (right down to the "Hack"
comment) to set the parameters in their generators.  The following
sample is from  JXTemplateGenerator:

    private void fillContext(Object contextObject, Map map) {
        if (contextObject == null) return;
        // Hack: I use jxpath to populate the context object's
        // in the jexl context
        final JXPathBeanInfo bi =
        if (bi.isDynamic()) {
            Class cl = bi.getDynamicPropertyHandlerClass();
            try {
                DynamicPropertyHandler h = (DynamicPropertyHandler)
                String[] result = h.getPropertyNames(contextObject);
                for (int i = 0; i < result.length; i++) {
                    try {
                        map.put(result[i], h.getProperty(contextObject,
                    } catch (Exception exc) {
            } catch (Exception ignored) {
        } else {
            PropertyDescriptor[] props =  bi.getPropertyDescriptors();
            for (int i = 0; i < props.length; i++) {
                try {
                    Method read = props[i].getReadMethod();
                    if (read != null) {
                                read.invoke(contextObject, null));
                } catch (Exception ignored) {

It seems to me that this really needs to be refactored into some helper
class, though I'm not sure where?

Peter Hunsberger

View raw message