You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Chintalapaty, Sreedhar " <sc...@ptc.com> on 2002/11/06 22:49:47 UTC

Actions - Help

Hi,

I am trying to implement the following simple action: 
- The URL ...cocoon/learn/hello?language=english should invoke an action called HelloWorldAction. 
- HelloWorldAction plugs in the a new parameter "greeting", whose value is the word for 'Hello' in the language specified. 
- Upon success, the user is redirected to ...cocoon/xsp/helloWorld.xsp.
- helloWorld.xsp will print out something like 'The english greet you with a hello'.

The trouble is, the actions *seems* to get invoked (the success branch redirect is happening), but 
- none of the log statements get printed (I am looking at core.log)
- the parameters langauge and greet are not passed on to helloWorld.xsp.

Here are my sources:

1. Sitemap:

<map:components>
...
  <map:actions>
    <map:action name="hello-action" src="learn.HelloWorldAction"/>
  </map:actions>
</map:components>
...

<map:match pattern="hello*">
  <map:act type="hello-action">
    <map:parameter name="parameters" value="true"/>
    <map:parameter name="language" value="{language}"/>
    <map:redirect-to uri="xsp/helloWorld.xsp?language={language}&amp;greeting={greeting}"/>
  </map:act>
  <map:redirect-to uri="index.html"/>
</map:match>


2. act method in HelloWorldAction.java

public Map act (Redirector redirector, 
                    SourceResolver resolver, 
                    Map objectModel, 
                    String source, 
                    Parameters par) { 
                                
  String language = par.getParameter("language", "English");        
  this.getLogger().fatalError("************* GET LANGUAGE = " + language);
        
  String greet = null;
        
  if (language == null || language.equalsIgnoreCase("")) {
    language = "Tamil";
    greet = "vaNakkaM";
  } else {
    if (language.equalsIgnoreCase("ENGLISH")) {
      greet = "Hello";
    }
    if (language.equalsIgnoreCase("TELUGU")) {
      greet = "giDigiDi";
    }
    if (language.equalsIgnoreCase("HINDI")) {
      greet = "Namaste";
    }    
  }
        
  this.getLogger().fatalError("************* SET LANGUAGE = " + language);
  this.getLogger().fatalError("************* SET GREETING = " + greet);
        
  Map map = new HashMap(1);
  map.put("greeting", greet); 
  return map;  
}


3. helloWorld.xsp (I know this is fine, I can invoke it directly with the parameters and it shows up correctly)

<?xml version="1.0" encoding="UTF-8"?>
<xsp:page xmlns:xsp="http://apache.org/xsp" xmlns:request="http://apache.org/xsp/request/2.0">
  <page>
    <title>Language Primer</title>
    <content>
      <para>
       The <xsp:expr>request.getParameter("language")</xsp:expr> greet you with a <xsp:expr>request.getParameter("greeting")</xsp:expr>. 
      </para>
    </content>
  </page>
</xsp:page>

What am I doing wrong?

Thanks for any and all help,

Sreedhar