tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: Using Tiles 3 in Struts 2
Date Thu, 14 Jan 2016 07:16:45 GMT
One idea: it would be good to have access to internals of given class,
ie. servletContext is private in ServletApplicationContext class so it
would be helpful to make it protected or deliver a getter to get it
without casting when subclassing (I know there is getContext() but it
returns Object that must be casted)


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

2016-01-14 4:27 GMT+01:00 Nicolas Le Bas <mail@nlebas.net>:
> Hi Łukasz,
>
> Thanks for taking the time to ask here. It's interesting to see what kind of
> challenges people are facing with tiles, and not so many people share theses
> days.
>
>
>
> Concerning ApplicationResources:
>
> First of all I want to clarify that creating an ApplicationResource object
> does not actually load the file, it merely locates it for later use. Only by
> calling the methods on ApplicationResource later can you proceed with
> reading the file.
>
> - #getResource(path) and #getResources(path) are used for non localized
> resources. Tiles uses them to inventory the tiles.xml files at startup, like
> here:
> https://github.com/apache/tiles/blob/TILES_3_0_X/tiles-core/src/main/java/org/apache/tiles/factory/BasicTilesContainerFactory.java#L220
> or here:
> https://github.com/apache/tiles/blob/TILES_3_0_X/tiles-extras/src/main/java/org/apache/tiles/extras/complete/CompleteAutoloadTilesContainerFactory.java#L203
>
> To be honest, I can see you're using it in your StrutsTilesContainerFactory
> (below), and I don't really understand why you're subclassing
> ServletApplicationContext.
>
> https://github.com/apache/struts/pull/73/files#diff-f6b3e4ef563a4a13a4d051eb2e26c379R159
>
> - #getResource(resource, locale) is used to find a localized version of a
> previously located resource. Of course the locale can only be identified at
> request time. There's a cache for performance, but only at request time can
> you know if you need to read /WEB-INF/tiles_en.xml or /WEB-INF/tiles_pl.xml,
> or default to /WEB-INF/tiles.xml. Tiles will read only the files that are
> needed.
>
> I can see you've disabled this feature in your subclass of
> ServletApplicationContext. I can only assume you do not want it.
>
>
>
> To access HttpServletRequest:
>
> Assuming that struts will always run in a servlet enviroment, I suggest you
> use ServletUtil.getServletRequest(request).getRequest(). There should be an
> equivalent for portlet, but I have to admit our test suite is lacking when
> it comes to portlets.
>
> https://github.com/apache/tiles-request/blob/TREQ_1_0_X/tiles-request-servlet/src/main/java/org/apache/tiles/request/servlet/ServletUtil.java#L90
>
> This will unwrap anything that sits around the ServletRequest object,
> whether it is a JspRequest, FreemarkerRequest, VelocityRequest or whatever
> else. Your current code would only support JSP as a templating engine.
>
>
>
> Hope this helps,
>
> Nick.
>
>
>
> On 01/13/2016 11:10 AM, Lukasz Lenart wrote:
>>
>> Hi,
>>
>> I'm working on upgrading the existing Struts 2 Tiles plugin to Tiles
>> 3. I was able upgrade to latest Tiles 2 previously (that upgrade
>> targeted Struts 2.3.x where Tiles 3 will be used in Struts 2.5.x).
>>
>> I have noticed a lot of differences and what worked well in Tiles 2 it
>> can even compile in Tiles 3. Anyway I was able to overcome the
>> problems but I'm not sure if I chose the right solution.
>>
>> First: how should I load resources? Now I'm using this logic
>>
>> https://github.com/apache/struts/pull/73/files#diff-a4ef02a35b4a5838b0cc73fa5e6236f9R98
>> but I have noticed that the resources are loaded twice: first on
>> startup (using #getResources()) then second time when I access an
>> endpoint (but this time using #getResourse(ApplicationResource,
>> Locale)) - why there are two different flows to load resources?
>>
>> Second: I need to gain access to ActionContext via HttpServletRequest
>> so I use this logic to fetch it depending on type of Request
>>
>> https://github.com/apache/struts/pull/73/files#diff-3f37ea6ef2abf4a7a3e08299038543b9R83
>> - is that the right way to obtain the HttpServletRequest?
>>
>> Thanks for any hints!
>>
>>
>> Cheers
>>
>

Mime
View raw message