You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by njko <nj...@gmail.com> on 2007/06/14 17:57:26 UTC

Show Formatted message

Hi 
I'm newbie in cocoon 

I have an Action that return a message.

I want show this message a the end of execution in a web page.

I find this solution

Action ....

public Map act(Redirector aRedirector, SourceResolver aResolver, Map
aObjectModel, String aSource, Parameters aParameters) throws Exception
  {
    HashMap result = new HashMap();
    result.put("message", "EXIST");
    return result;
  }

In Sitemap

      <map:match pattern="Test">
        <map:act type="testAction">
          <map:generate type="serverpages" src="ShowMessage.xsp">
            <map:parameter name="message" value="{message}" />
          </map:generate>
          <map:transform src="Message.xsl" />
          <map:transform type="encodeURL" />
          <map:serialize />
        </map:act>
      </map:match>
 

And  ShowMEssage.xps

<xsp:page language="java"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:esql="http://apache.org/cocoon/SQL/v2"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xsp-session="http://apache.org/xsp/session/2.0"
create-session="true"
    xmlns:util="http://apache.org/xsp/util/2.0"
    xmlns:infoutil="http://www.unifactor.com/infocomm/util/1.0">

<page xmlns:session="http://apache.org/cocoon/session/1.0">
   <content>
     <info>
       <message>
         <xsp:expr><util:get-sitemap-parameter name="message" /></xsp:expr>
       </message>
     </info>
   </content>
</page>
</xsp:page>

Is this a good way for do that?
Alternative?

If I want show this 
message = "aaa... \n bbb... \n ccc..."

like this 

aaa...
bbb...
ccc...

what I have to do ?


Thanks

njko
-- 
View this message in context: http://www.nabble.com/Show-Formatted-message-tf3922686.html#a11123171
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Show Formatted message

Posted by njko <nj...@gmail.com>.

Joerg Heinicke wrote:
> 
> On 14.06.2007 17:57, njko wrote:
> 
>> I'm newbie in cocoon 
> 
> Welcome :)
> 
> Thanks
> 
>> I have an Action that return a message.
>> I want show this message a the end of execution in a web page.
> 
>> If I want show this 
>> message = "aaa... \n bbb... \n ccc..."
>> 
>> like this 
>> 
>> aaa...
>> bbb...
>> ccc...
>> 
>> what I have to do ?
> 
> If it becomes HTML at the end you need to replace the encoded line break 
> characters with <br>. You can do that either with Java in XSP or with a 
> recursive template in XSLT.
> 
>> Is this a good way for do that? Alternative?
> 
> Adding I18nTransformer [1] to your setup is probably a good choice. Let 
> your action only return a message key and use this key to add an i18n 
> element in the appropriate namespace:
> 
> <i18n:text i18n:key="key_from_action">Default value</i18n:text>
> 
> The I18nTransformer will replace it with the actual message. Since it's 
> also markup aware you can add the <br>s directly into it. Externalizing 
> message to I18nTransformer is nearly always a good choice even if you 
> don't need to support multiple localizations.
> 
> As a general remark to your setup: Both actions and XSP are not 
> necessarily the recommended techniques in Cocoon. For actions it heavily 
> depends on what you actually want to do, there are still reasonable use 
> cases for them. But for "real" controllers in the MVC sense you should 
> consider flow [2].
> 
> And XSP is really near to deprecation (but not removal for sure). The 
> recommended technique here is the JXTemplateGenerator (or FileGenerator 
> + JXTemplateTransformer) [3, 4, 5]. But please take care of using the 
> most recent version of it in the template block, not from core.  The 
> functionality is the same, the linked documentation should still be 
> correct for nearly all cases. The difference between the two versions is 
> the package: org.apache.cocoon.generation.JXTemplateGenerator (old core 
> version) vs. org.apache.cocoon.template.JXTemplateGenerator (new 
> refactored version in template block).
> 
> Hope this helps,
> Joerg
> 
> [1] http://cocoon.apache.org/2.1/userdocs/i18nTransformer.html
> [2] http://cocoon.apache.org/2.1/userdocs/flow/index.html
> [3] http://cocoon.apache.org/2.1/userdocs/jx-generator.html
> [4] http://wiki.apache.org/cocoon/JXTemplateGenerator
> [5] http://cocoon.apache.org/2.1/userdocs/jx-template-transformer.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

Thanks for your very useful answer 
now my text i well formatted.

I start to work a cocoon project that already exist few mouth ago
and these are my first action with cocoon 

I have appreciated your answer on program flow

see you

njko 


-- 
View this message in context: http://www.nabble.com/Show-Formatted-message-tf3922686.html#a11135599
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Show Formatted message

Posted by Joerg Heinicke <jo...@gmx.de>.
On 14.06.2007 17:57, njko wrote:

> I'm newbie in cocoon 

Welcome :)

> I have an Action that return a message.
> I want show this message a the end of execution in a web page.

> If I want show this 
> message = "aaa... \n bbb... \n ccc..."
> 
> like this 
> 
> aaa...
> bbb...
> ccc...
> 
> what I have to do ?

If it becomes HTML at the end you need to replace the encoded line break 
characters with <br>. You can do that either with Java in XSP or with a 
recursive template in XSLT.

> Is this a good way for do that? Alternative?

Adding I18nTransformer [1] to your setup is probably a good choice. Let 
your action only return a message key and use this key to add an i18n 
element in the appropriate namespace:

<i18n:text i18n:key="key_from_action">Default value</i18n:text>

The I18nTransformer will replace it with the actual message. Since it's 
also markup aware you can add the <br>s directly into it. Externalizing 
message to I18nTransformer is nearly always a good choice even if you 
don't need to support multiple localizations.

As a general remark to your setup: Both actions and XSP are not 
necessarily the recommended techniques in Cocoon. For actions it heavily 
depends on what you actually want to do, there are still reasonable use 
cases for them. But for "real" controllers in the MVC sense you should 
consider flow [2].

And XSP is really near to deprecation (but not removal for sure). The 
recommended technique here is the JXTemplateGenerator (or FileGenerator 
+ JXTemplateTransformer) [3, 4, 5]. But please take care of using the 
most recent version of it in the template block, not from core.  The 
functionality is the same, the linked documentation should still be 
correct for nearly all cases. The difference between the two versions is 
the package: org.apache.cocoon.generation.JXTemplateGenerator (old core 
version) vs. org.apache.cocoon.template.JXTemplateGenerator (new 
refactored version in template block).

Hope this helps,
Joerg

[1] http://cocoon.apache.org/2.1/userdocs/i18nTransformer.html
[2] http://cocoon.apache.org/2.1/userdocs/flow/index.html
[3] http://cocoon.apache.org/2.1/userdocs/jx-generator.html
[4] http://wiki.apache.org/cocoon/JXTemplateGenerator
[5] http://cocoon.apache.org/2.1/userdocs/jx-template-transformer.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org