You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Stephan Schröder <si...@gmx.de> on 2008/10/28 16:44:33 UTC

neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

hi,

i'm in the precess of including Tiles 2 to my
Struts2+FreeMarker(+ServletAPI2.5)-project.
Things i did:
-add libs: 
struts2-tiles-plugin-xxx.jar, 
tiles-core-xxx.jar, 
tiles-api-xxx.jar, 
tiles-servlet-xxx.jar,
tiles-jsp-xxx.jar,
commons-beanutils-xxx.jar, 
commons-digester-xxx.jar, 
commons-logging-api-xxx.jar
spring-xxx.jar

-add listener in web.xml:
<listener>

<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

-added the tiles-Result to my my-struts-default.xml (i know, i could habe
just extended tiles-default but i want to make tiles default="true" anyway).

-added an WEB-INF/tiles-defs.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
  <definition name="*" template="/layout/simpleLayout.ftl">
    <put-attribute name="body" value="{1}" />
  </definition>  
</tiles-definitions>

-/layout/simpleLayout.ftl doesn't do anything usefull but i should provide
the HTML-Page with an <!-- test -->-String. It looks like this:
<!-- test -->
<@tiles.insertAttribute name="body" />


This results in the following error message:
...
INFO: Initializing Tiles2 container. . .
28.10.2008 15:59:13 org.apache.tiles.context.ChainedTilesContextFactory init
WARNUNG: Cannot find TilesContextFactory class
org.apache.tiles.portlet.context.PortletTilesContextFactory
28.10.2008 15:59:13 org.apache.catalina.core.StandardContext listenerStart
SCHWERWIEGEND: Exception sending context initialized event to listener
instance of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.IllegalStateException: RendererFactory not specified
	at
org.apache.tiles.impl.BasicTilesContainer.init(BasicTilesContainer.java:142)
	at
org.apache.tiles.factory.TilesContainerFactory.initializeContainer(TilesContainerFactory.java:271)
        ...

Apart from this error there are other things i'm not sure about:
-does Struts/Tiles find WEB-INF/tiles-defs.xml or do i have to set the
BasicTilesContainer.DEFINITIONS_CONFIG parameter?
-in simpleLayout.ftl do i have to include the tiles-jsp-lib myself (<#assign
tiles=JspTaglibs["???"]>
) or does the tiles-plugin do that? If i have to do it myself what is the
(local) address?
-- 
View this message in context: http://www.nabble.com/neccessary-stepts-to-use-Struts-2%2BFreeMarker%2BTiles2.1-tp20209482p20209482.html
Sent from the tiles users mailing list archive at Nabble.com.


Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/29 Stephan Schröder <si...@gmx.de>:
> tiles-jsp-2.0.6.jar is located in /WEB-INF/lib. I think the freemarker error
> with JspTaglibs was solved by adding the JspSupportServlet mentioned in the
> struts2-documentation.

This is what I meant when I told you that I don't like how Struts 2
uses FreeMarker: it overrides the simple FreemarkerServlet with its
own plugins and custom servlet. It seems a bit baroque to me :-D

Anyway good luck
Antonio

Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Stephan Schröder <si...@gmx.de>.
> Where did you put tiles-jsp-xxx.jar?

tiles-jsp-2.0.6.jar is located in /WEB-INF/lib. I think the freemarker error
with JspTaglibs was solved by adding the JspSupportServlet mentioned in the
struts2-documentation.
I uploaded the 
http://www.file-upload.net/download-1215732/filestoreLevel2.war.html
war-file  so you can take a look with
http://localhost:8080/filestoreLevel2/public/index.action

Stephan


Antonio Petrelli-3 wrote:
> 
> 2008/10/29 Stephan Schröder <si...@gmx.de>:
>> ==> assignment: tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]
>> [on
>> line 1, column 1 in layout/simpleLayout.ftl]
> 
> Where did you put tiles-jsp-xxx.jar?
> 
> Antonio
> 
> 

-- 
View this message in context: http://www.nabble.com/neccessary-stepts-to-use-Struts-2%2BFreeMarker%2BTiles2.1-tp20209482p20229473.html
Sent from the tiles users mailing list archive at Nabble.com.


Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/29 Stephan Schröder <si...@gmx.de>:
> ==> assignment: tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"] [on
> line 1, column 1 in layout/simpleLayout.ftl]

Where did you put tiles-jsp-xxx.jar?

Antonio

Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Stephan Schröder <si...@gmx.de>.
> I need to elaborate a bit...

Way to much work for me. The problem is that i don't need Tiles myself but
i'm compiling information for a struts2+freemarker+spring+hibernate-course
i'm giving. If tiles2.1 support for freemarker is not working the students
will have to work with tiles2.0 (albeit not having wildcards hurts quite a
bit. you really need one definition for every body content, don't you?).

So now i replaced the tiles2.1-libs with the tiles.2.0.6-libs, TilesListener
with StrutsTilesListener and my wildcard definition with a non-wildcard
definition. Unfortunately now i got a FreeMarker template error:

Expression JspTaglibs is undefined on line 1, column 16 in
layout/simpleLayout.ftl.
The problematic instruction:
----------
==> assignment: tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"] [on
line 1, column 1 in layout/simpleLayout.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression JspTaglibs is
undefined on line 1, column 16 in layout/simpleLayout.ftl.
	at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
	at
freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:75)
	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        ....

<#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]> doesn't
seem to be loaded, so after reading 
http://cwiki.apache.org/WW/freemarker-tags.html this (look at the bottum)  i
add
<servlet>
    <servlet-name>JspSupportServlet</servlet-name>
   
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
to the web.xml. But now i get an StackOverflowError:
description
The server encountered an internal error () that prevented it from
fulfilling this request.
exception 
javax.servlet.ServletException: Filter execution threw an exception
root cause 
java.lang.StackOverflowError
	org.apache.tomcat.util.buf.C2BConverter.convert(C2BConverter.java:81)
	org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:438)
	org.apache.catalina.connector.CoyoteWriter.write(CoyoteWriter.java:143)
	freemarker.ext.jsp.JspWriterAdapter.write(JspWriterAdapter.java:162)
	java.io.PrintWriter.write(Unknown Source)
	freemarker.ext.jsp.JspWriterAdapter.write(JspWriterAdapter.java:162)
	java.io.PrintWriter.write(Unknown Source)
        .....

What is missing now?

Regards,
Stephan



Antonio Petrelli-3 wrote:
> 
> 2008/10/29 Antonio <an...@gmail.com>:
>>> Now that the StrutsTilesListener is incompatible with Tile2.1 what can i
>>> do?
>>
>> You might modify that code of StrutsTilesListener and, if you like,
>> post a patch to the Struts group. I think they might like it :-D (I
>> have commit privileges, so I could commit your patch).
> 
> I need to elaborate a bit. The current Struts 2/Tiles 2 integration is
> a bit "patched", since it supports only partially the results of
> Struts 2 and does not call the necessary code of
> TilesContainerFactory.
> I would create a StrutsTilesContainerFactory for Tiles 2.1, leaving
> the one for 2.0 for compatibility reasons. Probably the new concept of
> "Attribute renderer" could help a bit:
> http://tiles.apache.org/framework/tutorial/advanced/attribute-rendering.html
> The big problem is that Struts 2 manages FreeMarker without the
> FreeMarker servlet. This poses a big problem if someone wants to use
> FreeMarker for other purposes.
> 
> But there's another choice: use Tiles "without" Struts support. Struts
> tags will be loaded anyway if you force the servlet to process the
> "include" of resources. See
> https://issues.apache.org/struts/browse/TILES-228?focusedCommentId=42840#action_42840
> 
> Anyway, for further questions about the Struts2/Tiles2 plugin ask the
> Struts mailing list because it is developed there.
> 
> Antonio
> 
> 

-- 
View this message in context: http://www.nabble.com/neccessary-stepts-to-use-Struts-2%2BFreeMarker%2BTiles2.1-tp20209482p20228871.html
Sent from the tiles users mailing list archive at Nabble.com.


Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/29 Antonio <an...@gmail.com>:
>> Now that the StrutsTilesListener is incompatible with Tile2.1 what can i do?
>
> You might modify that code of StrutsTilesListener and, if you like,
> post a patch to the Struts group. I think they might like it :-D (I
> have commit privileges, so I could commit your patch).

I need to elaborate a bit. The current Struts 2/Tiles 2 integration is
a bit "patched", since it supports only partially the results of
Struts 2 and does not call the necessary code of
TilesContainerFactory.
I would create a StrutsTilesContainerFactory for Tiles 2.1, leaving
the one for 2.0 for compatibility reasons. Probably the new concept of
"Attribute renderer" could help a bit:
http://tiles.apache.org/framework/tutorial/advanced/attribute-rendering.html
The big problem is that Struts 2 manages FreeMarker without the
FreeMarker servlet. This poses a big problem if someone wants to use
FreeMarker for other purposes.

But there's another choice: use Tiles "without" Struts support. Struts
tags will be loaded anyway if you force the servlet to process the
"include" of resources. See
https://issues.apache.org/struts/browse/TILES-228?focusedCommentId=42840#action_42840

Anyway, for further questions about the Struts2/Tiles2 plugin ask the
Struts mailing list because it is developed there.

Antonio

Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/29 Stephan Schröder <si...@gmx.de>:
> Now the definition is found, but the simpleLayout.ftl isn't parsed by
> FreeMarker it's simply returned as it is:

See:
http://freemarker.org/docs/pgui_misc_servlet.html

> Is this caused by the listener class
> org.apache.tiles.web.startup.TilesListener?
> The  http://struts.apache.org/2.1.2/docs/tiles-plugin.html
> struts-tiles-plugin page  notes org.apache.struts2.tiles.StrutsTilesListener
> "provides tighter integration with Struts features such as freemarker
> integration".
> Now that the StrutsTilesListener is incompatible with Tile2.1 what can i do?

You might modify that code of StrutsTilesListener and, if you like,
post a patch to the Struts group. I think they might like it :-D (I
have commit privileges, so I could commit your patch).

Antonio

Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Stephan Schröder <si...@gmx.de>.
I found a workaround for the wildcard definition problem:
Instead of 
<definition name="*" template="/layout/simpleLayout.ftl">
  <put-attribute name="body" value="{1}" />
</definition>  
i use
<definition name="/*/*" template="/layout/simpleLayout.ftl">
  <put-attribute name="body" value="/{1}/{2}" />
</definition>  

Now the definition is found, but the simpleLayout.ftl isn't parsed by
FreeMarker it's simply returned as it is:
<#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]> 
<html>
	<head>
	    <title>Test</title>
	</head>
	<body>
		<@tiles.insertAttribute name="body" />
	</body>
</html>

Is this caused by the listener class
org.apache.tiles.web.startup.TilesListener? 
The  http://struts.apache.org/2.1.2/docs/tiles-plugin.html
struts-tiles-plugin page  notes org.apache.struts2.tiles.StrutsTilesListener
"provides tighter integration with Struts features such as freemarker
integration".
Now that the StrutsTilesListener is incompatible with Tile2.1 what can i do?

Regards,
Stephan


Stephan Schröder wrote:
> 
>> Probably it is a Tiles bug. Can you open a JIRA issue and, if
>> possible, attach a test case (i.e. a WAR file with sources).
>> https://issues.apache.org/struts/browse/TILES
> 
>  https://issues.apache.org/struts/browse/TILES-325 done 
> 
> Regards,
> Stephan
> 
> 
> Antonio Petrelli-3 wrote:
>> 
>> 2008/10/28 Stephan Schröder <si...@gmx.de>:
>>>> put the URI of the taglib: <#assign
>>>> tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
>>>
>>> done, this will only work as long as i got an internet connection, won't
>>> it?
>> 
>> No, it works as long as you put tiles-jsp-xxx.jar under WEB-INF/lib,
>> or if you define it in web.xml.
>> 
>>> now i get:
>>> "WARNING: Unable to find the definition '/public/files_show.ftl'
>>> or
>>> "org.apache.tiles.definition.NoSuchDefinitionException:
>>> /public/files_show.ftl
>>>
>>> org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:612)"
>>>
>>> /public/files_show.ftl is present under /WebContent.
>> 
>> Mmm... This problem is not due to the presence or not of that file,
>> but it seems that Tiles cannot find the *definition* called
>> "/public/files_show.ftl". This is strange since you put the "*"
>> wildcard.
>> Probably it is a Tiles bug. Can you open a JIRA issue and, if
>> possible, attach a test case (i.e. a WAR file with sources).
>> https://issues.apache.org/struts/browse/TILES
>> 
>> Thanks
>> Antonio
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/neccessary-stepts-to-use-Struts-2%2BFreeMarker%2BTiles2.1-tp20209482p20225922.html
Sent from the tiles users mailing list archive at Nabble.com.


Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/29 Stephan Schröder <si...@gmx.de>:
>
>> Probably it is a Tiles bug. Can you open a JIRA issue and, if
>> possible, attach a test case (i.e. a WAR file with sources).
>> https://issues.apache.org/struts/browse/TILES
>
> https://issues.apache.org/struts/browse/TILES-325 done

I resolved the issue with a "won't fix" since you can use the "**" to
match everything. The "/" is used as a separator.
Sorry, but i really forgot it :-(

Antonio

Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Stephan Schröder <si...@gmx.de>.
> Probably it is a Tiles bug. Can you open a JIRA issue and, if
> possible, attach a test case (i.e. a WAR file with sources).
> https://issues.apache.org/struts/browse/TILES

https://issues.apache.org/struts/browse/TILES-325 done 

Regards,
Stephan


Antonio Petrelli-3 wrote:
> 
> 2008/10/28 Stephan Schröder <si...@gmx.de>:
>>> put the URI of the taglib: <#assign
>>> tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
>>
>> done, this will only work as long as i got an internet connection, won't
>> it?
> 
> No, it works as long as you put tiles-jsp-xxx.jar under WEB-INF/lib,
> or if you define it in web.xml.
> 
>> now i get:
>> "WARNING: Unable to find the definition '/public/files_show.ftl'
>> or
>> "org.apache.tiles.definition.NoSuchDefinitionException:
>> /public/files_show.ftl
>>
>> org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:612)"
>>
>> /public/files_show.ftl is present under /WebContent.
> 
> Mmm... This problem is not due to the presence or not of that file,
> but it seems that Tiles cannot find the *definition* called
> "/public/files_show.ftl". This is strange since you put the "*"
> wildcard.
> Probably it is a Tiles bug. Can you open a JIRA issue and, if
> possible, attach a test case (i.e. a WAR file with sources).
> https://issues.apache.org/struts/browse/TILES
> 
> Thanks
> Antonio
> 
> 

-- 
View this message in context: http://www.nabble.com/neccessary-stepts-to-use-Struts-2%2BFreeMarker%2BTiles2.1-tp20209482p20223967.html
Sent from the tiles users mailing list archive at Nabble.com.


Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/28 Stephan Schröder <si...@gmx.de>:
>> put the URI of the taglib: <#assign
>> tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
>
> done, this will only work as long as i got an internet connection, won't it?

No, it works as long as you put tiles-jsp-xxx.jar under WEB-INF/lib,
or if you define it in web.xml.

> now i get:
> "WARNING: Unable to find the definition '/public/files_show.ftl'
> or
> "org.apache.tiles.definition.NoSuchDefinitionException:
> /public/files_show.ftl
>
> org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:612)"
>
> /public/files_show.ftl is present under /WebContent.

Mmm... This problem is not due to the presence or not of that file,
but it seems that Tiles cannot find the *definition* called
"/public/files_show.ftl". This is strange since you put the "*"
wildcard.
Probably it is a Tiles bug. Can you open a JIRA issue and, if
possible, attach a test case (i.e. a WAR file with sources).
https://issues.apache.org/struts/browse/TILES

Thanks
Antonio

Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Stephan Schröder <si...@gmx.de>.
> Unfortunately StrutsTilesListener is not compatible with the changes

ok, i include
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
now.

> you can use the "tiles.xml" name

ok, done

> put the URI of the taglib: <#assign
> tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>

done, this will only work as long as i got an internet connection, won't it?

now i get:
"WARNING: Unable to find the definition '/public/files_show.ftl'
or
"org.apache.tiles.definition.NoSuchDefinitionException:
/public/files_show.ftl 
   
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:612)"

/public/files_show.ftl is present under /WebContent.

Regards,
Stephan


Antonio Petrelli-3 wrote:
> 
> 2008/10/28 Stephan Schröder <si...@gmx.de>:
>> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
>> </listener>
> 
> Unfortunately StrutsTilesListener is not compatible with the changes
> in the TilesListener (or better, TilesContainerFactory) made in Tiles
> 2.1.
> 
>> INFO: Initializing Tiles2 container. . .
>> 28.10.2008 15:59:13 org.apache.tiles.context.ChainedTilesContextFactory
>> init
>> WARNUNG: Cannot find TilesContextFactory class
>> org.apache.tiles.portlet.context.PortletTilesContextFactory
>> 28.10.2008 15:59:13 org.apache.catalina.core.StandardContext
>> listenerStart
>> SCHWERWIEGEND: Exception sending context initialized event to listener
>> instance of class org.apache.struts2.tiles.StrutsTilesListener
>> java.lang.IllegalStateException: RendererFactory not specified
> 
> The error is caused by the StrutsTilesListener incompatibility mentioned
> above.
> 
> 
>> -does Struts/Tiles find WEB-INF/tiles-defs.xml or do i have to set the
>> BasicTilesContainer.DEFINITIONS_CONFIG parameter?
> 
> You have to. Eventually you can use the "tiles.xml" name to your file
> if you don't want to use this parameter. Notice that this
> configuration parameter has been deprecated. Use this instead:
> http://tiles.apache.org/framework/config-reference.html#org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG
> 
>> -in simpleLayout.ftl do i have to include the tiles-jsp-lib myself
>> (<#assign
>> tiles=JspTaglibs["???"]>
>> ) or does the tiles-plugin do that? If i have to do it myself what is the
>> (local) address?
> 
> You have to include it yourself, put the URI of the taglib:
> <#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
> 
> 
> HTH
> Antonio
> 
> 

-- 
View this message in context: http://www.nabble.com/neccessary-stepts-to-use-Struts-2%2BFreeMarker%2BTiles2.1-tp20209482p20210551.html
Sent from the tiles users mailing list archive at Nabble.com.


Re: neccessary stepts to use Struts 2+FreeMarker+Tiles2.1

Posted by Antonio <an...@gmail.com>.
2008/10/28 Stephan Schröder <si...@gmx.de>:
> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
> </listener>

Unfortunately StrutsTilesListener is not compatible with the changes
in the TilesListener (or better, TilesContainerFactory) made in Tiles
2.1.

> INFO: Initializing Tiles2 container. . .
> 28.10.2008 15:59:13 org.apache.tiles.context.ChainedTilesContextFactory init
> WARNUNG: Cannot find TilesContextFactory class
> org.apache.tiles.portlet.context.PortletTilesContextFactory
> 28.10.2008 15:59:13 org.apache.catalina.core.StandardContext listenerStart
> SCHWERWIEGEND: Exception sending context initialized event to listener
> instance of class org.apache.struts2.tiles.StrutsTilesListener
> java.lang.IllegalStateException: RendererFactory not specified

The error is caused by the StrutsTilesListener incompatibility mentioned above.


> -does Struts/Tiles find WEB-INF/tiles-defs.xml or do i have to set the
> BasicTilesContainer.DEFINITIONS_CONFIG parameter?

You have to. Eventually you can use the "tiles.xml" name to your file
if you don't want to use this parameter. Notice that this
configuration parameter has been deprecated. Use this instead:
http://tiles.apache.org/framework/config-reference.html#org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG

> -in simpleLayout.ftl do i have to include the tiles-jsp-lib myself (<#assign
> tiles=JspTaglibs["???"]>
> ) or does the tiles-plugin do that? If i have to do it myself what is the
> (local) address?

You have to include it yourself, put the URI of the taglib:
<#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>


HTH
Antonio