cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonas Ekstedt <>
Subject Re: [RFC] "Cocoon Templates": Name and Tag Interface
Date Mon, 29 Nov 2004 17:59:37 GMT
On Mon, 2004-11-29 at 08:33 -0800, Ralph Goers wrote:
> > Expressions
> > -----------
> >
> > This is somewhat OT in the current context but IMO expressions, (the
> > stuff inside ${}), should only have access to FOM and preferably just
> > read access. IMHO expressions should not have side effects.
> There should be a way to register objects for use by the template so that
> flow is not a requirement.  Of course, the template should also be able to
> access the request and response.

How about allowing a "context-populator" parameter to the template
generator. As an example, suppose we want to populate the context with a
query from a db. 

In sitemap:

<map:generate type="template" src="showQuery">
  <map:parameter name="context-populator" src="com.MyPopulator"/>

The populator:

package com;
public class MyPopulator implements Populator {

  public static Context getContext(ServiceManager manager, 
                                   Map objectModel) {
    Context context = new DefaultContext();    
    context.put("myQuery", selectFromDB(manager, "select * from ...");
    return context;

One could even have population implemented as a flow function:

<map:generate type="template" src="showQuery">
  <map:parameter name="context-populator" flow="getMyContext"/>

function getMyContext(manager, objectModel) {
  return {var: "value1", var2: "value2"};

Cheers Jonas

View raw message