You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Stevo Slavić <ss...@gmail.com> on 2011/03/08 15:55:57 UTC

Extending generic tiles 2 template

Hello Apache Tiles users,

I have a generic Tile definition

	<definition  name="*/*" extends="standard">
		<put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
cascade="true"/>
		<put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
	</definition>

This one works fine for 90% of my Tiles 2 views (using Tiles 2.2.2
from Spring 3). For some views I need specific view preparer or to
redifine some attribute. Is there a way to extend such generic-named
Tile definition?

Also, can anyone please explain, or point me to some documentation,
what is the purpose of id attribute of a tile definition?

Regards,
Stevo.

Re: Extending generic tiles 2 template

Posted by Nicolas LE BAS <ma...@nlebas.net>.
Let me explain again how the wildcard works:

<definition name="home/*"> creates a lot of definitions, not just one. 
In all attributes, {1} will be replaced by the value of the *.

That means the above declaration defines the definition "home/start", 
too, and {1} will be replaced by "start" everywhere. No need to extend 
the definition for that: it's done already.

Now why do you get an error? Because when you cannot write 
"extends='home/*'": 'home/*' is not a definition, it is a wildcard 
pointing to many different definitions.

Hope this helps,
Nick

On 12-04-11 12:50 PM, Ninju Bohra wrote:
>
>
> My problem is slightly different. I am getting an error when I try to extends a
> wildcard<definition>  in the following manner:
>      <!-- Creating Tile definitions for all the home pages via simple wildcards
> (*) -->
>      <definition name="home/*" extends="template-home">
>          <put-attribute name="page_css" value="/css/{1}.css"/>
>          <put-attribute name="page_js" value="/js/{1}.js"/>
>          <put-attribute name="primary-content" value="/WEB-INF/pages/home/{1}.jsp"/>
>      </definition>
>
>      <definition name="home/start" extends="home/*">
>          <put-attribute name="primary-content"
> value="/WEB-INF/pages/home/start.jsp"/>
>      </definition>


Re: Extending generic tiles 2 template

Posted by Ninju Bohra <ni...@technologypartners.co>.

My problem is slightly different. I am getting an error when I try to extends a
wildcard <definition> in the following manner:
    <!-- Creating Tile definitions for all the home pages via simple wildcards
(*) -->
    <definition name="home/*" extends="template-home">
        <put-attribute name="page_css" value="/css/{1}.css"/>
        <put-attribute name="page_js" value="/js/{1}.js"/>
        <put-attribute name="primary-content" value="/WEB-INF/pages/home/{1}.jsp"/>
    </definition>

    <definition name="home/start" extends="home/*">
        <put-attribute name="primary-content"
value="/WEB-INF/pages/home/start.jsp"/>
    </definition>

Gives the following error:
DEBUG: org.springframework.web.servlet.DispatcherServlet - Could not complete
request
o.a.t.d.NoSuchDefinitionException: Error while resolving
definition inheritance:
child 'home/start' can't find its ancestor 'home/*'.
Please check your description file.
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.resolveInheritance
(ResolvingLocaleUrlDefinitionDAO.java:153)
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.resolveInheritances
(ResolvingLocaleUrlDefinitionDAO.java:105)
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs
(ResolvingLocaleUrlDefinitionDAO.java:67)
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.loadParentDefinitions
(ResolvingLocaleUrlDefinitionDAO.java:58)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs
(CachingLocaleUrlDefinitionDAO.java:239)
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs
(ResolvingLocaleUrlDefinitionDAO.java:65)
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.loadParentDefinitions
(ResolvingLocaleUrlDefinitionDAO.java:58)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs
(CachingLocaleUrlDefinitionDAO.java:239)
	at
o.a.t.d.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs
(ResolvingLocaleUrlDefinitionDAO.java:65)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.loadDefinitions
(CachingLocaleUrlDefinitionDAO.java:222)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.checkAndloadDefinitions
(CachingLocaleUrlDefinitionDAO.java:204)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.getDefinitions
(CachingLocaleUrlDefinitionDAO.java:154)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.getDefinition
(CachingLocaleUrlDefinitionDAO.java:123)
	at
o.a.t.d.dao.CachingLocaleUrlDefinitionDAO.getDefinition
(CachingLocaleUrlDefinitionDAO.java:54)
	at
o.a.t.d.UnresolvingLocaleDefinitionsFactory.getDefinition
(UnresolvingLocaleDefinitionsFactory.java:105)
.
.
.


Re: Extending generic tiles 2 template

Posted by Antonio Petrelli <an...@gmail.com>.
2011/3/8 Stevo Slavić <ss...@gmail.com>:
> and that didn't work either - getting following exception:
>
>
> org.apache.tiles.definition.NoSuchDefinitionException: Error while
> resolving definition inheritance: child 'foo/bar' can't find its
> ancestor 'generic/foo/bar'. Please check your description file.

Strange, I thought I fixed it:
https://issues.apache.org/jira/browse/TILES-475
Are you sure you are using Tiles 2.2.2?

>  http://tiles.apache.org/framework/tutorial/advanced/wildcard.html#Using_different_pattern_matching_languages
> Not sure if it's available by default. I doubt it would help me solve this one.

Not by "default" (i.e. with the default initializer) and it won't help anyway.

Antonio

Re: Extending generic tiles 2 template

Posted by Stevo Slavić <ss...@gmail.com>.
Now I have:

	<definition name="foo/bar" extends="standard" preparer="fooBarViewPreparer">
		<put-attribute name="pageTitle" type="string" value="foo.bar.title"
cascade="true"/>
		<put-attribute name="content" value="/WEB-INF/jsp/foo/bar.jsp" />
	</definition>

	<definition name="*/*" extends="standard">
		<put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
cascade="true"/>
		<put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
	</definition>

Just because foo/bar has a view preparer I have to repeat all the rest
- this is not DRY. Then I tried with

	<definition name="foo/bar" extends="foo/bar/withViewPreparere"
preparer="fooBarViewPreparer"/>

	<definition name="*/*/withViewPreparer" extends="standard">
		<put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
cascade="true"/>
		<put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
	</definition>

	<definition name="*/*" extends="standard">
		<put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
cascade="true"/>
		<put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
	</definition>

Some code duplication but it didn't work anyway (same reason as for
next). Then I tried with

	<definition name="foo/bar" extends="generic/foo/bar"
preparer="fooBarViewPreparer"/>

	<definition name="generic/*/*" extends="standard">
		<put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
cascade="true"/>
		<put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
	</definition>

	<definition name="*/*" extends="generic/{1}/{2}"/>


and that didn't work either - getting following exception:


org.apache.tiles.definition.NoSuchDefinitionException: Error while
resolving definition inheritance: child 'foo/bar' can't find its
ancestor 'generic/foo/bar'. Please check your description file.
	at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.resolveInheritance(ResolvingLocaleUrlDefinitionDAO.java:153)
	at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.resolveInheritances(ResolvingLocaleUrlDefinitionDAO.java:105)
	at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs(ResolvingLocaleUrlDefinitionDAO.java:67)
	at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadParentDefinitions(ResolvingLocaleUrlDefinitionDAO.java:58)
	at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs(CachingLocaleUrlDefinitionDAO.java:239)
	at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs(ResolvingLocaleUrlDefinitionDAO.java:65)
	at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitions(CachingLocaleUrlDefinitionDAO.java:222)
	at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.checkAndloadDefinitions(CachingLocaleUrlDefinitionDAO.java:204)
	at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinitions(CachingLocaleUrlDefinitionDAO.java:154)
	at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:123)
	at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:54)
	at org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory.getDefinition(UnresolvingLocaleDefinitionsFactory.java:105)
	at org.springframework.web.servlet.view.tiles2.TilesView.checkResource(TilesView.java:92)
	at org.springframework.web.servlet.view.UrlBasedViewResolver.loadView(UrlBasedViewResolver.java:421)
	at org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:158)
	at org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:384)
	at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:77)
	at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1078)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1027)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)


ResolvingLocaleUrlDefinitionDAO in resolveInheritance called for
"foo/bar" definition sets "foo/bar" as visited to avoid endless
recursion, and then tries to get definition for "generic/foo/bar" and
it doesn't find one - it tries to get it from a map where definitions
are keyed by definition name, and there is no definition with name/key
"generic/foo/bar", but there is one with name/key "generic/*/*".

So, it seems extends attribute of a tile definition can neither
reference tile name wildcards with placeholders nor in case of fixed
(without placeholders) extends attribute value it can not be a
reference to a matching tile with wildcards in name. It seems not same
mechanism is used when one gets a tile from tiles and when tiles
resolves inheritance. If same mechanism was used previous two examples
would work; I guess to avoid encless recursion in that case tile
definitions would have to be keyed on tile definition instance hash
value and not definition name.

Did anyone configure regexp pattern matching with Apache Tiles 2 and
Spring 3?  http://tiles.apache.org/framework/tutorial/advanced/wildcard.html#Using_different_pattern_matching_languages
Not sure if it's available by default. I doubt it would help me solve this one.

Regards,
Stevo.

On Tue, Mar 8, 2011 at 4:55 PM, Antonio Petrelli
<an...@gmail.com> wrote:
> 2011/3/8 Antonio Petrelli <an...@gmail.com>:
>> 2011/3/8 Stevo Slavić <ss...@gmail.com>:
>>> I understand, but how can one express that a tile definition extends
>>> one with wildcards in name?
>>
>> IIRC you can use placeholders in "extends" attribute.
>
> I rephrase it, sorry.
> If your definition is wildcard-ed and you want to express "extends"
> attribute in a parametrical way, you can use placeholders.
> OTOH if you want to extend a definition that is defined with
> wildcards, simply express *explicitly* a definition that will be
> intercepted by the wildcards.
> You can combine both things.
>
> Antonio
>

Re: Extending generic tiles 2 template

Posted by Antonio Petrelli <an...@gmail.com>.
2011/3/8 Antonio Petrelli <an...@gmail.com>:
> 2011/3/8 Stevo Slavić <ss...@gmail.com>:
>> I understand, but how can one express that a tile definition extends
>> one with wildcards in name?
>
> IIRC you can use placeholders in "extends" attribute.

I rephrase it, sorry.
If your definition is wildcard-ed and you want to express "extends"
attribute in a parametrical way, you can use placeholders.
OTOH if you want to extend a definition that is defined with
wildcards, simply express *explicitly* a definition that will be
intercepted by the wildcards.
You can combine both things.

Antonio

Re: Extending generic tiles 2 template

Posted by Antonio Petrelli <an...@gmail.com>.
2011/3/8 Stevo Slavić <ss...@gmail.com>:
> On Tue, Mar 8, 2011 at 3:59 PM, Antonio Petrelli
> <an...@gmail.com> wrote:
>> 2011/3/8 Stevo Slavić <ss...@gmail.com>:
>>> Hello Apache Tiles users,
>>>
>>> I have a generic Tile definition
>>>
>>>        <definition  name="*/*" extends="standard">
>>>                <put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
>>> cascade="true"/>
>>>                <put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
>>>        </definition>
>>>
>>> This one works fine for 90% of my Tiles 2 views (using Tiles 2.2.2
>>> from Spring 3). For some views I need specific view preparer or to
>>> redifine some attribute. Is there a way to extend such generic-named
>>> Tile definition?
>>
>> Define a more specific definition *above* this one. Definitions with
>> wildcards are evaluated in order of presence in the file.
>>
>
> I understand, but how can one express that a tile definition extends
> one with wildcards in name?

IIRC you can use placeholders in "extends" attribute.

>
>>> Also, can anyone please explain, or point me to some documentation,
>>> what is the purpose of id attribute of a tile definition?
>>
>> Sorry? What id attribute?
>
> Latest DTD that can be found at
> http://tiles.apache.org/dtds/tiles-config_2_1.dtd defines id as
> attribute of definition element. Eclipse IDE offers it for
> auto-completion.

Ah, that id. It is a standard XML attribute, nothing more, and nothing
useful for Tiles :-)

Antonio

Fwd: Extending generic tiles 2 template

Posted by Stevo Slavić <ss...@gmail.com>.
---------- Forwarded message ----------
From: Stevo Slavić <ss...@gmail.com>
Date: Tue, Mar 8, 2011 at 4:15 PM
Subject: Re: Extending generic tiles 2 template
To: Antonio Petrelli <an...@gmail.com>


On Tue, Mar 8, 2011 at 3:59 PM, Antonio Petrelli
<an...@gmail.com> wrote:
> 2011/3/8 Stevo Slavić <ss...@gmail.com>:
>> Hello Apache Tiles users,
>>
>> I have a generic Tile definition
>>
>>        <definition  name="*/*" extends="standard">
>>                <put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
>> cascade="true"/>
>>                <put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
>>        </definition>
>>
>> This one works fine for 90% of my Tiles 2 views (using Tiles 2.2.2
>> from Spring 3). For some views I need specific view preparer or to
>> redifine some attribute. Is there a way to extend such generic-named
>> Tile definition?
>
> Define a more specific definition *above* this one. Definitions with
> wildcards are evaluated in order of presence in the file.
>

I understand, but how can one express that a tile definition extends
one with wildcards in name?

>> Also, can anyone please explain, or point me to some documentation,
>> what is the purpose of id attribute of a tile definition?
>
> Sorry? What id attribute?

Latest DTD that can be found at
http://tiles.apache.org/dtds/tiles-config_2_1.dtd defines id as
attribute of definition element. Eclipse IDE offers it for
auto-completion.

>
> Antonio
>

Re: Extending generic tiles 2 template

Posted by Antonio Petrelli <an...@gmail.com>.
2011/3/8 Stevo Slavić <ss...@gmail.com>:
> Hello Apache Tiles users,
>
> I have a generic Tile definition
>
>        <definition  name="*/*" extends="standard">
>                <put-attribute name="pageTitle" type="string" value="{1}.{2}.title"
> cascade="true"/>
>                <put-attribute name="content" value="/WEB-INF/jsp/{1}/{2}.jsp" />
>        </definition>
>
> This one works fine for 90% of my Tiles 2 views (using Tiles 2.2.2
> from Spring 3). For some views I need specific view preparer or to
> redifine some attribute. Is there a way to extend such generic-named
> Tile definition?

Define a more specific definition *above* this one. Definitions with
wildcards are evaluated in order of presence in the file.

> Also, can anyone please explain, or point me to some documentation,
> what is the purpose of id attribute of a tile definition?

Sorry? What id attribute?

Antonio