You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Morgan Roderick <mo...@wingercom.net> on 2001/11/01 12:38:36 UTC

[C2] Actions - Request for example

Hi All

I am in the process of understanding how actions work in C2 and have found the "Action vs Request" thread started by Tobias Luikard on Mon, 17 Sep 2001 very useful, it has gotten me a lot closer to understanding Actions. 
http://mailman.real-time.com/pipermail/cocoon-users/2001-September/019125.html

I am, however, lacking that final piece of the puzzle that ties it all together. An example!

Has anyone got a SIMPLE working example of an action, that they would post to the list?
Preferably something that returns XML that can be used in XSL/serializer.

I have managed to create an action that:
- compiles
- does not generate a ClassNotFoundException (by deploying it to /WEB-INF/classes/)

I cannot seem to understand how to get any output from the action out on the screen, to a serializer, etc.

What really bugs me is that the hello_world.xsp does not really show up anywhere.

Sincerely
Morgan Roderick

*** Action ***
<map:actions>
    <map:action name="hello-world" src="test.HelloWorldAction"/>
</map:actions>


*** Pipeline ***
<map:match pattern="file">
    <map:act type="hello-world">
        <map:generate type="serverpages" src="{world}_world.xsp"/>
    </map:act>
    <map:serialize/>
</map:match>

*** HelloWorldAction.java ***
package test;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.Constants;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import java.util.*;
import org.apache.cocoon.environment.Request;
import org.xml.sax.EntityResolver;


public class HelloWorldAction extends AbstractAction {
  public Map act (Redirector redirector, 
                  SourceResolver resolver, 
                  Map objectModel, 
                  String source, 
                  Parameters params) {
	
    Map sitemapParams = new HashMap();
    sitemapParams.put("world", "hello");

    Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);

    request.setAttribute("hello", "world");

    return sitemapParams;
  }
}

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: [C2] Actions - Request for example

Posted by Henrik Hofmann <He...@creon-it.com>.
> I am, however, lacking that final piece of the puzzle that 
> ties it all together. An example!
> 
> Has anyone got a SIMPLE working example of an action, that 
> they would post to the list? Preferably something that 
> returns XML that can be used in XSL/serializer.

Normally Actions don't return anything. They aren't used for creating
XML Data tha shall be displayed on the screen. An action is itended to
do something, for example create (validate) a user session, or for
example od a database update or add an item to a shopping cart wich is
placed in the session. The return value (which is sitempa params) can
just be used in the sitemap.

If you really need to use the action to generate xml data, there's a way
to. You could generate an XMLFragment and put it into the Session or
request ob jetc by using setAttribute(). Late in your xsp page you can
retrieve this object an put it into your page.

Hope this helps.

bye


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>