You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Lukasz Lenart <lu...@apache.org> on 2015/11/25 12:19:25 UTC
Upgrading Struts-Tiles
Hi,
I'm working on upgrading the Struts Tiles plugin to use the latest
2.2.2 Tiles version (the Struts Tiles 3 plugin will be next :).
Everything almost works but I have one issue I cannot resolve.
Basically I don't know how to add support for Struts tags in
Freemarker templates.
As far I understand, I must somehow register tag directive with
Freemarker but I don't know how to do it with Tiles.
Any hints?
Thanks in advance
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-25 15:17 GMT+01:00 JOSE L MARTINEZ-AVIAL <jl...@gmail.com>:
> This upgrade will be for 2.5, or it will be also available on 2.3.x?
2.5 but it can be easily incorporated into 2.3.x
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by JOSE L MARTINEZ-AVIAL <jl...@gmail.com>.
This upgrade will be for 2.5, or it will be also available on 2.3.x?
thanks
2015-11-25 6:36 GMT-05:00 Lukasz Lenart <lu...@apache.org>:
> 2015-11-25 12:19 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
> > Hi,
> >
> > I'm working on upgrading the Struts Tiles plugin to use the latest
> > 2.2.2 Tiles version (the Struts Tiles 3 plugin will be next :).
> > Everything almost works but I have one issue I cannot resolve.
> > Basically I don't know how to add support for Struts tags in
> > Freemarker templates.
> >
> > As far I understand, I must somehow register tag directive with
> > Freemarker but I don't know how to do it with Tiles.
>
> Small success ;-) I have created my own version of
> FreeMarkerAttributeRenderer and now it supports Struts tags, but
> support for Tiles tags is gone :\
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-25 12:19 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
> Hi,
>
> I'm working on upgrading the Struts Tiles plugin to use the latest
> 2.2.2 Tiles version (the Struts Tiles 3 plugin will be next :).
> Everything almost works but I have one issue I cannot resolve.
> Basically I don't know how to add support for Struts tags in
> Freemarker templates.
>
> As far I understand, I must somehow register tag directive with
> Freemarker but I don't know how to do it with Tiles.
Small success ;-) I have created my own version of
FreeMarkerAttributeRenderer and now it supports Struts tags, but
support for Tiles tags is gone :\
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 14:51 GMT+01:00 JOSE L MARTINEZ-AVIAL <jl...@gmail.com>:
> Hello Lukasz,
> You need to add an attribute cascade=true to the attribute that needs to
> be inherited.
Thanks a lot!
I have been using wrong DTD and now everything works :) That means the
PR is ready https://github.com/apache/struts/pull/59 :D
Kind regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by JOSE L MARTINEZ-AVIAL <jl...@gmail.com>.
Hello Lukasz,
You need to add an attribute cascade=true to the attribute that needs to
be inherited.
JL
2015-11-27 7:01 GMT-05:00 Lukasz Lenart <lu...@apache.org>:
> 2015-11-27 12:45 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
> > The problem is with AttributeContext and ArrayStack. When evaluating
> > ftl file I see three AttributeContexts - empty,
> > with-attributes-from-tiles.xml, empty - and the last empty is used to
> > evaluate the ftl :\
> >
> > In BasicTilesContainer method render() looks like this
> >
> > protected void render(TilesRequestContext request, Definition
> definition) {
> > AttributeContext originalContext = getAttributeContext(request);
> > BasicAttributeContext subContext = new
> > BasicAttributeContext(originalContext);
> > subContext.inherit(definition);
> >
> > pushContext(subContext, request);
> >
> > try {
> > render(request, subContext);
> > } finally {
> > popContext(request);
> > }
> > }
> >
> > the first line will create an empty AttributeContext and will push to
> > the stack - why? Then the proper AttributeContext will be created and
> > pushed again (with values from tiles.xml). I cannot figure out where
> > the third ActionContext is created.
>
> I think I understand - AttributeContext is created per a tile (ie.
> /tiles/layout.jsp, /tiles/menu.jsp, etc) and it isn't possible to use
> it outside of the tile - which looks like a bug to me :)
>
> I have a very simple tiles.xml:
>
> <tiles-definitions>
>
> <definition name="baseLayout" template="/tiles/layout.jsp">
> <put-attribute name="title" value="Template"/>
> <put-attribute name="header" value="/tiles/header.jsp"/>
> <put-attribute name="menu" value="/tiles/menu.jsp"/>
> <put-attribute name="body" value="/tiles/body.jsp"/>
> <put-attribute name="footer" value="/tiles/footer.ftl"/>
> </definition>
>
> <definition name="hello" extends="baseLayout">
> <put-attribute name="title" value="Hello"/>
> <put-attribute name="body" value="/example/HelloWorld.jsp"/>
> </definition>
>
> </tiles-definitions>
>
> and now an attribute "title" is only accessible inside "layout.jsp",
> it won't be accessible in header.jsp, menu.jsp and so on as for each
> of this tile a new empty AttributeContext is created. I would assume
> that the attributes will be inherited in that case, but they aren't.
>
> I have tested this by simply adding <tiles:insertAttribute
> name="title"/> tag to menu.jsp and got exception:
> org.apache.tiles.template.NoSuchAttributeException: Attribute 'title'
> not found
>
> How can I tell Tiles to inherit attributes?
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 12:45 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
> The problem is with AttributeContext and ArrayStack. When evaluating
> ftl file I see three AttributeContexts - empty,
> with-attributes-from-tiles.xml, empty - and the last empty is used to
> evaluate the ftl :\
>
> In BasicTilesContainer method render() looks like this
>
> protected void render(TilesRequestContext request, Definition definition) {
> AttributeContext originalContext = getAttributeContext(request);
> BasicAttributeContext subContext = new
> BasicAttributeContext(originalContext);
> subContext.inherit(definition);
>
> pushContext(subContext, request);
>
> try {
> render(request, subContext);
> } finally {
> popContext(request);
> }
> }
>
> the first line will create an empty AttributeContext and will push to
> the stack - why? Then the proper AttributeContext will be created and
> pushed again (with values from tiles.xml). I cannot figure out where
> the third ActionContext is created.
I think I understand - AttributeContext is created per a tile (ie.
/tiles/layout.jsp, /tiles/menu.jsp, etc) and it isn't possible to use
it outside of the tile - which looks like a bug to me :)
I have a very simple tiles.xml:
<tiles-definitions>
<definition name="baseLayout" template="/tiles/layout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="header" value="/tiles/header.jsp"/>
<put-attribute name="menu" value="/tiles/menu.jsp"/>
<put-attribute name="body" value="/tiles/body.jsp"/>
<put-attribute name="footer" value="/tiles/footer.ftl"/>
</definition>
<definition name="hello" extends="baseLayout">
<put-attribute name="title" value="Hello"/>
<put-attribute name="body" value="/example/HelloWorld.jsp"/>
</definition>
</tiles-definitions>
and now an attribute "title" is only accessible inside "layout.jsp",
it won't be accessible in header.jsp, menu.jsp and so on as for each
of this tile a new empty AttributeContext is created. I would assume
that the attributes will be inherited in that case, but they aren't.
I have tested this by simply adding <tiles:insertAttribute
name="title"/> tag to menu.jsp and got exception:
org.apache.tiles.template.NoSuchAttributeException: Attribute 'title'
not found
How can I tell Tiles to inherit attributes?
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 9:36 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
> 2015-11-27 9:32 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
>>> As far I understand it requires FreemarkerServlet to be registered
>>> (Struts doesn't use it) and also FM Environment must have Tiles model
>>> registered already :(
>>
>> Problem solved! I had to register dedicated JSP servlet to support this :)
>
> Almost, Tiles tags are missing values - looks like the model has no
> Tiles definition in
The problem is with AttributeContext and ArrayStack. When evaluating
ftl file I see three AttributeContexts - empty,
with-attributes-from-tiles.xml, empty - and the last empty is used to
evaluate the ftl :\
In BasicTilesContainer method render() looks like this
protected void render(TilesRequestContext request, Definition definition) {
AttributeContext originalContext = getAttributeContext(request);
BasicAttributeContext subContext = new
BasicAttributeContext(originalContext);
subContext.inherit(definition);
pushContext(subContext, request);
try {
render(request, subContext);
} finally {
popContext(request);
}
}
the first line will create an empty AttributeContext and will push to
the stack - why? Then the proper AttributeContext will be created and
pushed again (with values from tiles.xml). I cannot figure out where
the third ActionContext is created.
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 9:32 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
>> As far I understand it requires FreemarkerServlet to be registered
>> (Struts doesn't use it) and also FM Environment must have Tiles model
>> registered already :(
>
> Problem solved! I had to register dedicated JSP servlet to support this :)
Almost, Tiles tags are missing values - looks like the model has no
Tiles definition in
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 7:42 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
> 2015-11-27 7:08 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
>>> Concerning how we do it for tiles: I don't remember how we did back in in
>>> tiles 2.2, it's probably similar to 3.0, which is awkwards. For 3.1 I'm
>>> reworking it into just registering a variable in freemarker's configuration
>>> object:
>>>
>>> https://github.com/nlebas/tiles/blob/master/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/TilesFreemarkerServlet.java
>>
>> That should help, thanks a lot!
>
> This won't work :( Did the same but then I get exception:
>
> java.lang.NullPointerException
> org.apache.tiles.freemarker.context.FreeMarkerUtil.getCurrentContainer(FreeMarkerUtil.java:148)
> org.apache.tiles.freemarker.template.InsertAttributeFMModel.execute(InsertAttributeFMModel.java:74)
> freemarker.core.Environment.visit(Environment.java:389)
> freemarker.core.UnifiedCall.accept(UnifiedCall.java:104)
> freemarker.core.Environment.visit(Environment.java:324)
> freemarker.core.MixedContent.accept(MixedContent.java:54)
> freemarker.core.Environment.visit(Environment.java:324)
> freemarker.core.Environment.process(Environment.java:302)
> freemarker.template.Template.process(Template.java:325)
> org.apache.struts2.views.freemarker.FreemarkerResult.doExecute(FreemarkerResult.java:233)
> .....
>
> As far I understand it requires FreemarkerServlet to be registered
> (Struts doesn't use it) and also FM Environment must have Tiles model
> registered already :(
Problem solved! I had to register dedicated JSP servlet to support this :)
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 7:08 GMT+01:00 Lukasz Lenart <lu...@apache.org>:
>> Concerning how we do it for tiles: I don't remember how we did back in in
>> tiles 2.2, it's probably similar to 3.0, which is awkwards. For 3.1 I'm
>> reworking it into just registering a variable in freemarker's configuration
>> object:
>>
>> https://github.com/nlebas/tiles/blob/master/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/TilesFreemarkerServlet.java
>
> That should help, thanks a lot!
This won't work :( Did the same but then I get exception:
java.lang.NullPointerException
org.apache.tiles.freemarker.context.FreeMarkerUtil.getCurrentContainer(FreeMarkerUtil.java:148)
org.apache.tiles.freemarker.template.InsertAttributeFMModel.execute(InsertAttributeFMModel.java:74)
freemarker.core.Environment.visit(Environment.java:389)
freemarker.core.UnifiedCall.accept(UnifiedCall.java:104)
freemarker.core.Environment.visit(Environment.java:324)
freemarker.core.MixedContent.accept(MixedContent.java:54)
freemarker.core.Environment.visit(Environment.java:324)
freemarker.core.Environment.process(Environment.java:302)
freemarker.template.Template.process(Template.java:325)
org.apache.struts2.views.freemarker.FreemarkerResult.doExecute(FreemarkerResult.java:233)
.....
As far I understand it requires FreemarkerServlet to be registered
(Struts doesn't use it) and also FM Environment must have Tiles model
registered already :(
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Lukasz Lenart <lu...@apache.org>.
2015-11-27 1:14 GMT+01:00 Nicolas Le Bas <ma...@nlebas.net>:
> Hi Łukasz,
>
> I didn't even know struts supported freemarker. Well, I'll admit I've not
> used struts in the past 10 years...
Struts 2 to be correct ;-) And yes, it supports Freemarker directly
from the very beginning, also Struts tags are written in Freemarker
> So... how do you register the struts tags with freemarker without tiles? I
> think it should work more or less the same.
Struts builds a dedicated Model to be used by FM but Tiles does the
same - each of them register tags within the Model (as far I
understand Tiles codebase)
https://github.com/apache/struts/blob/master/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java#L504-L517
> Concerning how we do it for tiles: I don't remember how we did back in in
> tiles 2.2, it's probably similar to 3.0, which is awkwards. For 3.1 I'm
> reworking it into just registering a variable in freemarker's configuration
> object:
>
> https://github.com/nlebas/tiles/blob/master/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/TilesFreemarkerServlet.java
That should help, thanks a lot!
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Re: Upgrading Struts-Tiles
Posted by Nicolas Le Bas <ma...@nlebas.net>.
Hi Łukasz,
I didn't even know struts supported freemarker. Well, I'll admit I've
not used struts in the past 10 years...
So... how do you register the struts tags with freemarker without tiles?
I think it should work more or less the same.
Concerning how we do it for tiles: I don't remember how we did back in
in tiles 2.2, it's probably similar to 3.0, which is awkwards. For 3.1
I'm reworking it into just registering a variable in freemarker's
configuration object:
https://github.com/nlebas/tiles/blob/master/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/TilesFreemarkerServlet.java
Hope this helps,
Nick
On 11/25/2015 06:19 AM, Lukasz Lenart wrote:
> Hi,
>
> I'm working on upgrading the Struts Tiles plugin to use the latest
> 2.2.2 Tiles version (the Struts Tiles 3 plugin will be next :).
> Everything almost works but I have one issue I cannot resolve.
> Basically I don't know how to add support for Struts tags in
> Freemarker templates.
>
> As far I understand, I must somehow register tag directive with
> Freemarker but I don't know how to do it with Tiles.
>
> Any hints?
>
>
> Thanks in advance
>