You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zoran Avtarovski <zo...@sparecreative.com> on 2015/05/01 01:32:09 UTC

Cascading Nature of Templates and Themes

We¹ve started a new project which required a custom theme which we call
mobile and we set it to extend the simple theme by creating a
theme.properties file and setting parent=simple.

Unfortunately this isn¹t working. It has in the past without any issues. Has
something changed in the latest version of struts that would explain this?

We are using struts 2.3.20 and freemarker 2.3.19 if it makes any difference.

Z.




Re: Cascading Nature of Templates and Themes

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Thanks for the pointer Lucasz.

One thing I did notice was that some of my files didn’t use the
${parameters.expandTheme} parameter, but instead just had plain old
${parameters.theme} in the free marker templates.

I’ll make the changes and I’m pretty sure that should resolve the issue.

Again thanks for the help.

Z.


On 1/05/2015 6:23 pm, "Lukasz Lenart" <lu...@apache.org> wrote:

>2015-05-01 1:32 GMT+02:00 Zoran Avtarovski <zo...@sparecreative.com>:
>> We¹ve started a new project which required a custom theme which we call
>> mobile and we set it to extend the simple theme by creating a
>> theme.properties file and setting parent=simple.
>>
>> Unfortunately this isn¹t working. It has in the past without any
>>issues. Has
>> something changed in the latest version of struts that would explain
>>this?
>>
>> We are using struts 2.3.20 and freemarker 2.3.19 if it makes any
>>difference.
>
>Strange, the same mechanism is used by Struts itself. Can you show
>project's structure? Or prepare a small demo app to represent your
>case?
>
>Here you have some examples:
>https://github.com/apache/struts-examples/tree/master/themes
>https://github.com/apache/struts-examples/tree/master/themes_override
>
>
>Regards
>-- 
>Łukasz
>+ 48 606 323 122 http://www.lenart.org.pl/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>



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


Re: Cascading Nature of Templates and Themes

Posted by Lukasz Lenart <lu...@apache.org>.
I have made an example app and it works
https://github.com/lukaszlenart/struts2-theme-inherit

2015-05-05 8:12 GMT+02:00 Zoran Avtarovski <zo...@sparecreative.com>:
> Hi Lucasz,
>
>>>I had copied all the missing simple templates into my mobile template
>>
>>don't do it, Struts will find them. Just override those templates which
>>you need
>
> I don¹t think I was clear enough here. If I don¹t include the file the
> error is thrown. The issue I have is struts doesn¹t find them working up
> the chain.
>
>
>>
>>Maybe because of hardcoded "simple" - and it happens that not all
>>templates were adjusted to be "expandTheme" friendly ;)
>>
>>>
>>> The mobile select.ftl template is simply:
>>>
>>> <#include
>>>
>>>"/${parameters.templateDir}/${parameters.expandTheme}/controlheader.ftl"
>>>/>
>>> <#include "/${parameters.templateDir}/simple/select.ftl" />
>>
>>You shouldn't hardcode "simple" here, use "expandTheme" to tell Struts
>>to check your theme first and than parent theme.
>
> I was just following the guidelines. If I don¹t hardcode simple aren¹t I
> at risk of a circular reference, as the file will simply reference itself?
>
>
> Z.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

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


Re: Cascading Nature of Templates and Themes

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Hi Lucasz,

>>I had copied all the missing simple templates into my mobile template
>
>don't do it, Struts will find them. Just override those templates which
>you need

I don¹t think I was clear enough here. If I don¹t include the file the
error is thrown. The issue I have is struts doesn¹t find them working up
the chain.


>
>Maybe because of hardcoded "simple" - and it happens that not all
>templates were adjusted to be "expandTheme" friendly ;)
>
>>
>> The mobile select.ftl template is simply:
>>
>> <#include
>> 
>>"/${parameters.templateDir}/${parameters.expandTheme}/controlheader.ftl"
>>/>
>> <#include "/${parameters.templateDir}/simple/select.ftl" />
>
>You shouldn't hardcode "simple" here, use "expandTheme" to tell Struts
>to check your theme first and than parent theme.

I was just following the guidelines. If I don¹t hardcode simple aren¹t I
at risk of a circular reference, as the file will simply reference itself?


Z.



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


Re: Cascading Nature of Templates and Themes

Posted by Lukasz Lenart <lu...@apache.org>.
2015-05-05 7:19 GMT+02:00 Zoran Avtarovski <zo...@sparecreative.com>:
> I spoke too soon.
>
> I just replaced all instances of parameters.theme with
> parameters.expandTheme.
>
> I had copied all the missing simple templates into my mobile template

don't do it, Struts will find them. Just override those templates which you need

> directory as a work-around. When I deleted optgroup.ftl from the mobile
> template directory I get the following error:
>
> ERROR [ajp-nio-8009-exec-2] - Template processing error: "Error reading
> included file template/~~~mobile/optgroup.ftl"
>
> Error reading included file template/~~~mobile/optgroup.ftl
> The problematic instruction:
> ----------
> ==> include
> "/${parameters.templateDir}/${parameters.expandTheme}/optgroup.ftl" [on
> line 118, column 1 in template/simple/select.ftl]
>  in include "/${parameters.templateDir}/simple/select.ftl" [on line 25,
> column 1 in template/mobile/select.ftl]
> ----------
>
> Java backtrace for programmers:
> ----------
> freemarker.template.TemplateException: Error reading included file
> template/~~~mobile/optgroup.ftl
> .
> .
> .
> Caused by: java.io.FileNotFoundException: Template
> template/~~~mobile/optgroup.ftl not found.
>
>
> What I don’t understand I why the template manager doesn’t try to load
> optgroup.ftl from the simple template?

Maybe because of hardcoded "simple" - and it happens that not all
templates were adjusted to be "expandTheme" friendly ;)

>
> The mobile select.ftl template is simply:
>
> <#include
> "/${parameters.templateDir}/${parameters.expandTheme}/controlheader.ftl" />
> <#include "/${parameters.templateDir}/simple/select.ftl" />

You shouldn't hardcode "simple" here, use "expandTheme" to tell Struts
to check your theme first and than parent theme.

> <#include
> "/${parameters.templateDir}/${parameters.expandTheme}/controlfooter.ftl" />


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

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


Re: Cascading Nature of Templates and Themes

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
I spoke too soon.

I just replaced all instances of parameters.theme with
parameters.expandTheme.

I had copied all the missing simple templates into my mobile template
directory as a work-around. When I deleted optgroup.ftl from the mobile
template directory I get the following error:

ERROR [ajp-nio-8009-exec-2] - Template processing error: "Error reading
included file template/~~~mobile/optgroup.ftl"

Error reading included file template/~~~mobile/optgroup.ftl
The problematic instruction:
----------
==> include 
"/${parameters.templateDir}/${parameters.expandTheme}/optgroup.ftl" [on
line 118, column 1 in template/simple/select.ftl]
 in include "/${parameters.templateDir}/simple/select.ftl" [on line 25,
column 1 in template/mobile/select.ftl]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateException: Error reading included file
template/~~~mobile/optgroup.ftl
.
.
.
Caused by: java.io.FileNotFoundException: Template
template/~~~mobile/optgroup.ftl not found.


What I don’t understand I why the template manager doesn’t try to load
optgroup.ftl from the simple template?


The mobile select.ftl template is simply:

<#include 
"/${parameters.templateDir}/${parameters.expandTheme}/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/select.ftl" />
<#include 
"/${parameters.templateDir}/${parameters.expandTheme}/controlfooter.ftl" />

And the theme.properties file has one entry:

parent=simple

Again any assistance would be appreciated.

Z.

On 1/05/2015 6:23 pm, "Lukasz Lenart" <lu...@apache.org> wrote:

>2015-05-01 1:32 GMT+02:00 Zoran Avtarovski <zo...@sparecreative.com>:
>> We¹ve started a new project which required a custom theme which we call
>> mobile and we set it to extend the simple theme by creating a
>> theme.properties file and setting parent=simple.
>>
>> Unfortunately this isn¹t working. It has in the past without any
>>issues. Has
>> something changed in the latest version of struts that would explain
>>this?
>>
>> We are using struts 2.3.20 and freemarker 2.3.19 if it makes any
>>difference.
>
>Strange, the same mechanism is used by Struts itself. Can you show
>project's structure? Or prepare a small demo app to represent your
>case?
>
>Here you have some examples:
>https://github.com/apache/struts-examples/tree/master/themes
>https://github.com/apache/struts-examples/tree/master/themes_override
>
>
>Regards
>-- 
>Łukasz
>+ 48 606 323 122 http://www.lenart.org.pl/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>



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


Re: Cascading Nature of Templates and Themes

Posted by Lukasz Lenart <lu...@apache.org>.
2015-05-01 1:32 GMT+02:00 Zoran Avtarovski <zo...@sparecreative.com>:
> We¹ve started a new project which required a custom theme which we call
> mobile and we set it to extend the simple theme by creating a
> theme.properties file and setting parent=simple.
>
> Unfortunately this isn¹t working. It has in the past without any issues. Has
> something changed in the latest version of struts that would explain this?
>
> We are using struts 2.3.20 and freemarker 2.3.19 if it makes any difference.

Strange, the same mechanism is used by Struts itself. Can you show
project's structure? Or prepare a small demo app to represent your
case?

Here you have some examples:
https://github.com/apache/struts-examples/tree/master/themes
https://github.com/apache/struts-examples/tree/master/themes_override


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

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