You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Stone, Sam" <ss...@constantcontact.com> on 2006/12/04 23:30:50 UTC
Tiles 2 - How to dispatch to tiles servlet????
I am using tiles-core-2.0-SNAPSHOT.jar from Sep 2006.
I have a servlet MyServlet and also a servlet named tiles in the same
war file. Everything works if I do launch a jsp page that has a
tiles:insert in it. However, I'd like to dispatch directlry from
MyServlet to a tiles definition.
I can instantiate the DefinitionsFactory. I can get a
ComponentDefinition OK. I cannot figure out how to forward the request
from MyServlet to dispatch to my tiles servlet. Any help is greatly
appreciated.
All the following ocde seems to work. The printlns dump out the expected
information. I just can't figure out how to transfer control to my tiles
servlet.
DefinitionsFactory definitionsFactory = null;
DefinitionsFactoryConfig definitionsConfig;
definitionsConfig = new DefinitionsFactoryConfig();
TilesContext stc = new
ServletTilesContext(s.getServletContext());
/* load the tiles definitions */
definitionsConfig.setDefinitionConfigFiles("WEB-INF/tiles-defs-base.xml,
WEB-INF/tiles-defs-site.xml");
try {
definitionsFactory =
TilesUtil.createDefinitionsFactory(stc, definitionsConfig);
System.out.println("Tiles Definitions loaded!");
} catch (DefinitionsFactoryException dfe) {
System.out.println("Error reading tiles definitions
file: " +
dfe.getMessage());
}
try
{
ComponentDefinition definition =
definitionsFactory.readDefinitions().getDefinition("site.home");
System.out.println("definition=" + definition);
}
catch (Exception de)
{
System.out.println(de);
}
Following is from my web.xml:
<servlet id="Servlet_1159386011442">
<servlet-name>tiles</servlet-name>
<servlet-class>org.apache.tiles.servlet.TilesServlet</servlet-class>
<init-param id="InitParam_1159386019739">
<param-name>definitions-config</param-name>
<param-value>
/WEB-INF/tiles-defs-base.xml,
/WEB-INF/tiles-defs-site.xml
</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
[OT] Re: Tiles 2 - How to dispatch to tiles servlet????
Posted by Antonio Petrelli <ap...@apache.org>.
David H. DeWolf ha scritto:
> Just to avoid confusion, I don't think Antonio meant to imply that the
> Container.render returns a ComponentContext.
Err... right, my confusion was due to wrong cut'n'paste :-)
And the confusion continues, since I posted the same email to Struts
Developers list...
AND IT'S ONLY TUESDAY! :-P
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Tiles 2 - How to dispatch to tiles servlet????
Posted by Antonio Petrelli <ap...@apache.org>.
David H. DeWolf ha scritto:
> Just to avoid confusion, I don't think Antonio meant to imply that the
> Container.render returns a ComponentContext.
Err... right, my confusion was due to wrong cut'n'paste :-)
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: Tiles 2 - How to dispatch to tiles servlet????
Posted by "David H. DeWolf" <dd...@apache.org>.
Moving to Struts Users list, please reply there.
Antonio Petrelli wrote:
> First of all this is a typical question to be submitted in Struts Users
> mailing list.
> Anyway, since Tiles 2 is under development, I will answer anyway.
>
> Stone, Sam ha scritto:
>> I can instantiate the DefinitionsFactory. I can get a
>> ComponentDefinition OK. I cannot figure out how to forward the request
>> from MyServlet to dispatch to my tiles servlet. Any help is greatly
>> appreciated.
>>
> Err... you can't, since TilesServlet does not accept connections (it is
> used without a servlet-mapping).
> Anyway you can forward to (or include) your definition.
>
> <snip>
> ComponentContext context =
> TilesAccess.getContainer(request.getSession().getServletContext())
> .render(request, response, "my.definition.name");
> </snip>
Just to avoid confusion, I don't think Antonio meant to imply that the
Container.render returns a ComponentContext.
TilesContainer tc = TilesAccess.getContainer(servletContext)
ComponentContext context = tc.getComponentContext(req, res);
// do something with the component context if needed,
tc.render(req, res, "my.definition.name");
David
>
> HTH
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Tiles 2 - How to dispatch to tiles servlet????
Posted by "David H. DeWolf" <dd...@apache.org>.
Moving to Struts Users list, please reply there.
Antonio Petrelli wrote:
> First of all this is a typical question to be submitted in Struts Users
> mailing list.
> Anyway, since Tiles 2 is under development, I will answer anyway.
>
> Stone, Sam ha scritto:
>> I can instantiate the DefinitionsFactory. I can get a
>> ComponentDefinition OK. I cannot figure out how to forward the request
>> from MyServlet to dispatch to my tiles servlet. Any help is greatly
>> appreciated.
>>
> Err... you can't, since TilesServlet does not accept connections (it is
> used without a servlet-mapping).
> Anyway you can forward to (or include) your definition.
>
> <snip>
> ComponentContext context =
> TilesAccess.getContainer(request.getSession().getServletContext())
> .render(request, response, "my.definition.name");
> </snip>
Just to avoid confusion, I don't think Antonio meant to imply that the
Container.render returns a ComponentContext.
TilesContainer tc = TilesAccess.getContainer(servletContext)
ComponentContext context = tc.getComponentContext(req, res);
// do something with the component context if needed,
tc.render(req, res, "my.definition.name");
David
>
> HTH
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: Tiles 2 - How to dispatch to tiles servlet????
Posted by Antonio Petrelli <ap...@apache.org>.
First of all this is a typical question to be submitted in Struts Users
mailing list.
Anyway, since Tiles 2 is under development, I will answer anyway.
Stone, Sam ha scritto:
> I can instantiate the DefinitionsFactory. I can get a
> ComponentDefinition OK. I cannot figure out how to forward the request
> from MyServlet to dispatch to my tiles servlet. Any help is greatly
> appreciated.
>
Err... you can't, since TilesServlet does not accept connections (it is
used without a servlet-mapping).
Anyway you can forward to (or include) your definition.
<snip>
ComponentContext context =
TilesAccess.getContainer(request.getSession().getServletContext())
.render(request, response, "my.definition.name");
</snip>
HTH
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org