cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <>
Subject Re: quick question on logging and actions
Date Tue, 13 Mar 2001 15:27:32 GMT
Donald Ball wrote:
> On Mon, 12 Mar 2001, Berin Loritsch wrote:
> > > while mine is simply:
> > >
> > >    <map:match pattern="forms/mail">
> > >      <map:act action="send-mail">
> > >        <parameter name="smtphost" value=""/>
> > >        <map:generate src="docs/samples/forms/mail.xhtml"/>
> > >        <map:serialize/>
> > >      </map:act>
> > >    </map:match>
> > >
> > > why would that not work?
> >
> > The way yours is set up, it is _supposed_ to be executed every time
> > the URL is accessed.  Try deleting your sitemap, so that it gets
> > compiled fresh.  Also make sure the class is in the classpath.
> i have a script which deletes everything related to cocoon in my catalina
> installation whenever i rebuild cocoon. :) so yes, the sitemap has been
> recompiled and the SendmailAction class is in the cocoon jar file
> > There is some rudimentary documentation on actions in the
> > C2 CVS.  Let me know what helps, what confuses the matter, and
> > what needs further explanation.
> i've of course read it backwards and forwards - some comments are:
> 1. what's up with this file?

Ignore that comment.  The README is OLD, and represents draft info
regarding the initial discussions of Actions.

> 2. what's in the objectModel?

Your Request, Response, Context, Link objects, plus anything defined from
a parent Action.  In other words, you can have:

<map:act type="foo">
  <map:act type="bar"/>

Where foo creates an object and maps it to "my-object".  The "bar" Action
can do a objectModel.get("my-object") to get at the object from the
parent.  It can also do a objectModel.get(Constants.REQUEST_OBJECT)
to get the request object.

So, the Action receives the following objects:

EntityResolver resolver (the need for this is dubious, I am not sure why
                         it is here--unless you are populating request
                         attributes from an XML file).
Map objectModel (Your method of accessing Request (and Session), Response,
                 Context, and user defined objects).
String source (The value of the source="{1}" attribute you can use in
               the action)
Parameters param (the child parameter elements to pass runtime info for
                  configuring special cases for a URI).

The objectModel and the resolver are provided automatically by the sitemap,
and there is little you can do to influence them (except use nested actions).
The source and param values are directly modifiable:

<map:match pattern="**.form">
  <map:act type="is-ok" src="{1}">
    <map:redirect-to uri="{dest}.html"/>

Using this construct it allows us to do a Form Validator action that is called
"is-ok", and is passed the path to the handler.  The purpose of the action is
to direct the user to the requested page if all is ok, or return to the calling
page if not.  The action would be something like this:

public class MyAction extends AbstractAction {
    public Map act(EntityResolver r, Map objectModel, String source, Parameters param) {
        // We ignore EntityResolver and Parameters for now
        String destination = source;
        Map actionMap = new HashMap();
        HttpRequest request = objectModel.get(Constants.REQUEST_OBJECT);

        if (this.hasError(request)) {
            destination = request.getParameter("source-uri");

        actionMap.put("dest", destination);
        return Collections.unmodifiableMap(actionMap);

    private boolean hasError(HttpRequest request) {
        // Put your validation stuff here.
        // This implimentation says that there is never an error.
        return false;

Please note that I use an unmodifiableMap because the Sitemap copies the contents
when necessary, and because they are threadsafe without the overhead of synchronization

> 3. the sitemap action syntax "documented" in the README seems to be old

It is.

> all in all, i think c2 just needs a few more actions and examples in the
> sample webapp - a deficiency i'm attempting to rectify. :)

Kool Beans!

> note i'm going to be visiting my new nephew (!) over the next few days so
> will only be on email sporadically. i hope to have some time to spend
> working on c2 off-line, so any help you can give me debugging this would
> be helpful. :)

Take your time.

To unsubscribe, e-mail:
For additional commands, email:

View raw message