You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Carter, Zach N" <Za...@Metasystems.com> on 2002/09/09 19:40:26 UTC

Tiles without struts

I have a large existing application that uses a common page layout and would
like to use struts tiles.  I do not want to use struts actions and such
because there is already a controller in the application, we would like to
just use the Tiles template mechanism.

>From what I've read it seems that we should be able to have the current
forwards, which are mapped in web.xml using url-mappings.  The current pages
were mapped using the extension view.  I am using the latest struts binary
build and tomcat 4.0.  Documentation alludes that you can map urls onto
tiles-defs with the latest release.  At the bottom is the request url I
tried and there was no output given in the console, just and error in the
browser "The specified HTTP method is not allowed for the requested resource
(HTTP method GET is not supported by this URL)."  Hopefully someone with
more experience in Tiles could point me in the right direction; all I want
is to move our current "view" url mappings from web.xml into
tiles-definitions.xml and have tiles assemble the pages using a standard
presentation layout.  Thank you for any help you provide.


<!-- web.xml -->
  <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.tiles.TilesServlet</servlet-class> 
    <init-param>
      <param-name>definitions-config</param-name>
      <param-value>/WEB-INF/tiles-definitions.xml</param-value>
    </init-param>	
    <init-param>
      <param-name>definitions-debug</param-name>
      <param-value>2</param-value>
    </init-param>	
    <init-param>
      <param-name>definitions-parser-details</param-name>
      <param-value>2</param-value>
    </init-param>	
    <init-param>
      <param-name>definitions-parser-validate</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>validate</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>	
    <load-on-startup>2</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.view</url-pattern>
  </servlet-mapping>
  
<!-- struts-config.xml -->
  <struts-config>
    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
      <set-property property="definitions-config"
value="/WEB-INF/tiles-definitions.xml" />
      <set-property property="definitions-debug"  value="2" />
      <set-property property="definitions-parser-details"  value="2" />
      <set-property property="definitions-parser-validate" value="true" />
    </plug-in>  
  </struts-config>

<!-- tiles-definitions.xml -->
  <tiles-definitions>
    <definition name="mainLayout" path="/layout.jsp" >
        <put name="title" value="Login" />
        <put name="body"  value="/Login.jsp" />
    </definition>
    <definition name="Login" extends="mainLayout" >
        <put name="title" value="Login" />
        <put name="body"  value="/Login.jsp" />
    </definition>
    <definition name="LoginConfirm" extends="mainLayout" >
        <put name="title" value="Main" />
        <put name="body"  value="/LoginConfirm.jsp" />
    </definition>
  </tiles-definitions>


<!-- output from tomcat upon requesting http://localhost/app/Login.view -->
Start Tiles initialization
Try to load Tiles factory
factory loaded : {Login={name=Login, path=/layout.jsp, role=null,
controller=null, controllerType=null, controllerInstance=null,
attributes={title=Login, body=/Login.jsp}}
, LoginConfirm={name=LoginConfirm, path=/layout.jsp, role=null,
controller=null, controllerType=null, controllerInstance=null,
attributes={title=Main, body=/LoginConfirm.jsp}}
, mainLayout={name=mainLayout, path=/layout.jsp, role=null, controller=null,
controllerType=null, controllerInstance=null, attributes={title=Login,
body=/Login.jsp}}
}
Factory initialized from file '/WEB-INF/tiles-definitions.xml'.
Starting service Tomcat-Apache
Apache Tomcat/4.0.4

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


Re: Tiles without struts

Posted by Cedric Dumoulin <ce...@apache.org>.
  Hi,

  You can use Tiles without Struts. If you want also the definition 
capability, you need to initialize the Tiles factory. This can be done 
by using the TilesServlet (as you do). In this case, Tiles factory 
config is specified in web.xml. You don't need the TilesPlugin because 
you don't use Struts.

  Tiles don't support direct forward to a definition name. Definition 
names are logical names. You need to map URLs to definition names. This 
can be done in the servlet associated to the mapping mechanism. Map an 
extension to your servlet, and in the process() method of the servlet, 
do the following:
    // Catch the definition name
  String definitionName = ???;
    // Get the definition (add appropriate catch)
  ComponentDefinition definition 
= DefinitionsUtil.getDefinition(definitionName, request, 
getServletContext());
    // Create new Tiles context, initialized with the definition
  ComponentContext context = new ComponentContext( 
definition.getAttributes() );
    // Save context where the tiles will find it
  ComponentContext.setContext( tileContext, request);
     // Include the tiles
  String uri = definition.getPath();
  RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
  rd.include(request, response);
 
Check the TilesRequestProcessor class to know how it is done with Struts.
  If you have an interesting "forward" method that can be added to 
TilesServlet and you agree to share it, let us know ...

        Hope this help,

               Cedric

Carter, Zach N wrote:

>I have a large existing application that uses a common page layout and would
>like to use struts tiles.  I do not want to use struts actions and such
>because there is already a controller in the application, we would like to
>just use the Tiles template mechanism.
>
>>>From what I've read it seems that we should be able to have the current
>forwards, which are mapped in web.xml using url-mappings.  The current pages
>were mapped using the extension view.  I am using the latest struts binary
>build and tomcat 4.0.  Documentation alludes that you can map urls onto
>tiles-defs with the latest release.  At the bottom is the request url I
>tried and there was no output given in the console, just and error in the
>browser "The specified HTTP method is not allowed for the requested resource
>(HTTP method GET is not supported by this URL)."  Hopefully someone with
>more experience in Tiles could point me in the right direction; all I want
>is to move our current "view" url mappings from web.xml into
>tiles-definitions.xml and have tiles assemble the pages using a standard
>presentation layout.  Thank you for any help you provide.
>
>
><!-- web.xml -->
>  <servlet-name>action</servlet-name>
>    <servlet-class>org.apache.struts.tiles.TilesServlet</servlet-class> 
>    <init-param>
>      <param-name>definitions-config</param-name>
>      <param-value>/WEB-INF/tiles-definitions.xml</param-value>
>    </init-param>	
>    <init-param>
>      <param-name>definitions-debug</param-name>
>      <param-value>2</param-value>
>    </init-param>	
>    <init-param>
>      <param-name>definitions-parser-details</param-name>
>      <param-value>2</param-value>
>    </init-param>	
>    <init-param>
>      <param-name>definitions-parser-validate</param-name>
>      <param-value>true</param-value>
>    </init-param>
>    <init-param>
>      <param-name>config</param-name>
>      <param-value>/WEB-INF/struts-config.xml</param-value>
>    </init-param>
>    <init-param>
>      <param-name>validate</param-name>
>      <param-value>true</param-value>
>    </init-param>
>    <init-param>
>      <param-name>debug</param-name>
>      <param-value>2</param-value>
>    </init-param>
>    <init-param>
>      <param-name>detail</param-name>
>      <param-value>2</param-value>
>    </init-param>	
>    <load-on-startup>2</load-on-startup>
>  </servlet>
>
>  <servlet-mapping>
>    <servlet-name>action</servlet-name>
>    <url-pattern>*.view</url-pattern>
>  </servlet-mapping>
>  
><!-- struts-config.xml -->
>  <struts-config>
>    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
>      <set-property property="definitions-config"
>value="/WEB-INF/tiles-definitions.xml" />
>      <set-property property="definitions-debug"  value="2" />
>      <set-property property="definitions-parser-details"  value="2" />
>      <set-property property="definitions-parser-validate" value="true" />
>    </plug-in>  
>  </struts-config>
>
><!-- tiles-definitions.xml -->
>  <tiles-definitions>
>    <definition name="mainLayout" path="/layout.jsp" >
>        <put name="title" value="Login" />
>        <put name="body"  value="/Login.jsp" />
>    </definition>
>    <definition name="Login" extends="mainLayout" >
>        <put name="title" value="Login" />
>        <put name="body"  value="/Login.jsp" />
>    </definition>
>    <definition name="LoginConfirm" extends="mainLayout" >
>        <put name="title" value="Main" />
>        <put name="body"  value="/LoginConfirm.jsp" />
>    </definition>
>  </tiles-definitions>
>
>
><!-- output from tomcat upon requesting http://localhost/app/Login.view -->
>Start Tiles initialization
>Try to load Tiles factory
>factory loaded : {Login={name=Login, path=/layout.jsp, role=null,
>controller=null, controllerType=null, controllerInstance=null,
>attributes={title=Login, body=/Login.jsp}}
>, LoginConfirm={name=LoginConfirm, path=/layout.jsp, role=null,
>controller=null, controllerType=null, controllerInstance=null,
>attributes={title=Main, body=/LoginConfirm.jsp}}
>, mainLayout={name=mainLayout, path=/layout.jsp, role=null, controller=null,
>controllerType=null, controllerInstance=null, attributes={title=Login,
>body=/Login.jsp}}
>}
>Factory initialized from file '/WEB-INF/tiles-definitions.xml'.
>Starting service Tomcat-Apache
>Apache Tomcat/4.0.4
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>



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