struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cedric Dumoulin <ced...@apache.org>
Subject Re: Anyone using tiles with pager tag lib?
Date Wed, 12 Mar 2003 13:27:17 GMT

  Hi,

  When you hit a page through a struts action, the action is executed, 
then the request is forwarded to the associated page or tiles. The jsp 
spec specify that when you do a forward, the requestURI is change 
accordingly. This is why you get the URL of the tiles layout instead of 
the action URL.

  In fact, Tiles framework try to respect the struts way by doing 
forward (instead of include) as long as it is possible.
  A trick is to let think the tiles request processor that it should do 
an include instead of a forward. For that, you should put an empty 
tileContext in the request.
  I join an action that do exactly that. You should use this action with 
the struts action used to associate an URL to a tiles definition 
defining a page. You should avoid to use it with action used as included 
tiles.

  <action     path="/showRequestURI"
                 type="org.apache.struts.webapp.tiles.test.NoForward">
      <forward  name="success"        path="test.action.noforward"/>
  </action>

  Hope this help,

       Cedric
-------------------------------
package org.apache.struts.webapp.tiles.test;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.ComponentDefinition;


/**
 * Implementation of <strong>Action</strong> that create a TileContext 
in order
 * to force the TilesRequestProcessor to do an include instead of a forward.
 * The side effect is that request.getRequestURI will return the URL of the
 * calling struts action instead of the URL of the tiles layout.
 * See the jsp documentation to understand why.
 * Usage:
 * use this action in conjunction with an action declaration in struts 
config.
 * The action declaration should have one "success" forward to a Tile.
 * <pre>
 *   <action     path="/showRequestURI"
 *                    type="org.apache.struts.webapp.tiles.test.NoForward">
 *    <forward  name="success"        path="test.action.noforward"/>
 *  </action>
 * </pre>
 * @author Cedric Dumoulin
 * @version $Revision: 1.2 $ $Date: 2002/11/16 04:58:47 $
 */

public final class NoForward extends Action {



    // --------------------------------------------------------- Public 
Methods


    /**
     *
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     *
     * @exception Exception if the application business logic throws
     *  an exception
     * @since Struts 1.1
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
      // Try to retrieve tile context
    ComponentContext context = ComponentContext.getContext( request );
    if( context == null )
      { // Not found, create a context
        // This context will be detected by the TilesRequestProcessor 
which will do an include
        // instead of a forward.
      ComponentContext tileContext = new ComponentContext( );
      ComponentContext.setContext( tileContext, request);
      }
      return (mapping.findForward("success"));
    }


}
---------------------

Laker Shen wrote:

> The reason is that tiles mess up with the request url. Pager rely on
> <%= request.getRequestURI() %> to build the url for next page. Tiles 
> always point the request URI to be the layout.jsp.
>
> Before the url for next page is: SearchResult.jsp?pager.offset=10,
> now it is: tiles/layout/mainLayout.jsp?pager.offset=10
>
> That's why it's not working. What should I do?
>
> Tiles is nice, but did cause so many troubles.
>
>> From: "Laker Shen" <lakerprince@hotmail.com>
>> Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>> To: struts-user@jakarta.apache.org
>> Subject: Anyone using tiles with pager tag lib?
>> Date: Tue, 11 Mar 2003 22:14:36 +0000
>>
>> Have trouble to use tiles with pager tag lib (from jsptags.com). 
>> Anyone uses this two together? Is there a way to fix it? Thanks.
>>
>> When I clicked the "next" on my search result page:
>> org.apache.jasper.JasperException: Error - tag.getAsString : 
>> component context is not defined. Check tag syntax
>>     at 
>> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248) 
>>
>>     at 
>> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
>>     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
>>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>>     at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

>>
>>     at 
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

>>
>>     at 
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)

>>
>>     at 
>> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

>>
>>     at 
>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) 
>>
>>     at 
>> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>>     at 
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

>>
>>     at 
>> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

>>
>>     at 
>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) 
>>
>>     at 
>> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>>     at 
>> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415) 
>>
>>     at 
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) 
>>
>>     at 
>> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

>>
>>     at 
>> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

>>
>>     at 
>> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

>>
>>
>> The same code is working inside a jsp page.
>>
>>
>> _________________________________________________________________
>> The new MSN 8: smart spam protection and 2 months FREE*  
>> http://join.msn.com/?page=features/junkmail
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message