You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Hoofe <ko...@hoofe.de> on 2002/07/25 18:46:59 UTC

How to use map:redirect-to combined with serverpages

I tried the following code in the sitemap to redirect to a page after saving values to the 
database using art_grp_chg.xsp and receive an sitemap error. 

   <map:match pattern="art_grp_chg.xsp">
    <map:act type="request">
      <map:parameter name="parameters" value="true"/>
      <map:select type="request-parameter">
      <map:parameter name="parameter-name" value="next"/>
         <map:when test="">
         </map:when>
         <map:otherwise>
            <map:generate type="serverpages" src="xdocs/db/art_grp_chg.xsp"/>
            <map:serialize/>
            <map:redirect-to uri="../{next}"/>
         </map:otherwise>
      </map:select>         
    </map:act>    
   </map:match>

I am looking for a simple way to do something similar to the response.sendRedirect(""); I 
used in my Cocoon 1.8.2. code. 

Configuration:
Cocoon 2.0.3
Tomcat 4.1.7
Win98

Thanks
Christian

________________________

  Christian Hoofe
  Email  kontakt@hoofe.de
________________________


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

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


RE: How to use map:redirect-to combined with serverpages

Posted by Christian Hoofe <ko...@hoofe.de>.
This is my solution for a serverpage redirect combined with an action:

1. Sitemaps needs ServerPagesAction

  <map:actions>

   <map:action logger="sitemap.action.xsp-action" name="xsp-action" src="org.apache.cocoon.acting.ServerPagesAction"/>
   </map:actions>

2. Site matcher

   <map:match pattern="db/*.xsp">
    <map:act type="xsp-action" src="xdocs/db/{1}.xsp">
      <map:match type="request-parameter" pattern="next">
         <map:redirect-to session="false" uri="{1}"/>
      </map:match>

    </map:act>
    <!-- Portion of the sitemap executed if xsp failed 	-->
   ...

   </map:match>

3. Call of the matcher

   <form action="../db/art_grp_chg.xsp" method="POST">
    	<input name="next" type="hidden" value="../admin/art_grp.xsp.html"/>
   ...

   </form> 

The "next" parameter tells the sitemap the next page to call. In this case the itself.

4. The xsp page with the database logic 'db/art_grp_chg.xsp'

<?xml version="1.0" encoding="ISO-8859-1"?>

<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:action="http://apache.org/cocoon/action/1.0"
>

  <page>
   <title>A Database Driven XSP Page</title>

   <content>
 
<xsp:logic>
   String process = null;
   String id_str = null;
   int    id = -1;
   String ord_str = null;
   int    ordnr = -1;
   String name = null;

   process  = <xsp-request:get-parameter name="process"/>;
   id_str   = <xsp-request:get-parameter name="id"/>;
   id       = Integer.parseInt(id_str); 
   ord_str   = <xsp-request:get-parameter name="ordnr"/>;
   ordnr = Integer.parseInt(ord_str); 
   name     = <xsp-request:get-parameter name="name"/>;
</xsp:logic>

   <esql:connection>
      <esql:pool>db</esql:pool>
        <transactions>
         <esql:execute-query>
            <esql:query>
               UPDATE artikel_gruppen
   SET   gruppe_ordnung   = 							
   <esql:parameter><xsp:expr>ordnr</xsp:expr></esql:parameter>,
   gruppe_name       = 							
   <esql:parameter><xsp:expr>name</xsp:expr></esql:parameter>,
   WHERE gruppen_id = 					<esql:parameter><xsp:expr>id</xsp:expr></esql:parameter>;
            </esql:query>
         </esql:execute-query>
        </transactions> 
        <action:set-success/> 
   </esql:connection>  

   </content>
  </page> 

</xsp:page>
  
Important is the <action:set-success/>, which signals the sitemap matcher the success. This can be enhanced with an additional <action:set-
failure/> in case of an esql exception 

Christian Hoofe

> > From: Christian Hoofe [mailto:kontakt@hoofe.de]
> > 
> > I tried the following code in the sitemap to redirect to a page after
> saving
> > values to the
> > database using art_grp_chg.xsp and receive an sitemap error.
> 
> You actually want to write not XSP page but action.
> 
> 
> >    <map:match pattern="art_grp_chg.xsp">
> >     <map:act type="request">
> >       <map:parameter name="parameters" value="true"/>
> >       <map:select type="request-parameter">
> >       <map:parameter name="parameter-name" value="next"/>
> >          <map:when test="">
> >          </map:when>
> >          <map:otherwise>
> >             <map:generate type="serverpages"
> src="xdocs/db/art_grp_chg.xsp"/>
> >             <map:serialize/>
> 
> These two lines mean: "SEND PAGE TO CLIENT"
> 
> >             <map:redirect-to uri="../{next}"/>
> 
> This line means: "DON'T SEND PAGE TO CLIENT, SEND HIM TO ANOTHER URL".
> 
> These are *not* compatible with each other. Choose one of them.
> 
> 
> Vadim
> 
> 
> >          </map:otherwise>
> >       </map:select>
> >     </map:act>
> >    </map:match>
> > 
> > I am looking for a simple way to do something similar to the
> > response.sendRedirect(""); I used in my Cocoon 1.8.2. code.
> > 
> > Configuration:
> > Cocoon 2.0.3
> > Tomcat 4.1.7
> > Win98
> > 
> > Thanks
> > Christian
> > 
> > ________________________
> > 
> >   Christian Hoofe
> >   Email  kontakt@hoofe.de
> > ________________________
> 


________________________

  Christian Hoofe
  Wittelsbacherstr. 3
  D 10707 Berlin

  Tel	 +49 30 887 290 33
  Fax	 +49 30 887 290 32
  Mobil  +49 179 12 98 470
  Email  kontakt@hoofe.de
________________________








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

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


RE: How to use map:redirect-to combined with serverpages

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Christian Hoofe [mailto:kontakt@hoofe.de]
> 
> I tried the following code in the sitemap to redirect to a page after
saving
> values to the
> database using art_grp_chg.xsp and receive an sitemap error.

You actually want to write not XSP page but action.


>    <map:match pattern="art_grp_chg.xsp">
>     <map:act type="request">
>       <map:parameter name="parameters" value="true"/>
>       <map:select type="request-parameter">
>       <map:parameter name="parameter-name" value="next"/>
>          <map:when test="">
>          </map:when>
>          <map:otherwise>
>             <map:generate type="serverpages"
src="xdocs/db/art_grp_chg.xsp"/>
>             <map:serialize/>

These two lines mean: "SEND PAGE TO CLIENT"

>             <map:redirect-to uri="../{next}"/>

This line means: "DON'T SEND PAGE TO CLIENT, SEND HIM TO ANOTHER URL".

These are *not* compatible with each other. Choose one of them.


Vadim


>          </map:otherwise>
>       </map:select>
>     </map:act>
>    </map:match>
> 
> I am looking for a simple way to do something similar to the
> response.sendRedirect(""); I used in my Cocoon 1.8.2. code.
> 
> Configuration:
> Cocoon 2.0.3
> Tomcat 4.1.7
> Win98
> 
> Thanks
> Christian
> 
> ________________________
> 
>   Christian Hoofe
>   Email  kontakt@hoofe.de
> ________________________


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

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