Hi Antonio
 
I have implemented two new classes as suggested by you in our previous 
discussion:
 
(1) A class called DbTilesContainerFactory which extends 
BasicTilesContainerFactory (the code is identical to the example on the Tiles 
website)
(2) A class called DbDefinitionDao which implements the DefinitionDAO and 
Refreshable interfaces.
 
I have modified web.xml as follows:
 
<servlet>
     <servlet-name>tiles</servlet-name>
        <servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
        <init-param>
           
<param-name>org.apache.tiles.factory.AbstractTilesContainerFactory</param-name>
           <param-value>com.xyz.DbTilesContainerFactory</param-value>
       </init-param>
</servlet>
 
I can confirm that the AbstractTilesContainerFactory constructor creates an 
instance of the DbTilesFactoryContainer, however NEITHER of its two methods 
[ instantiateDefinitionsFactory() and createLocaleDefinitionDao() ] are 
invoked.  I have a simple Definition in my which I insert in my JSP:
 
<tiles:insertDefinition name="Blank" flush="true" />
 
A java.lang.NullPointerException is thrown when the above line is executed:
 
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromURLs(CachingLocaleUrlDefinitionDAO.java:230)
        at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadP
arentDefinitions(ResolvingLocaleUrlDefinitionDAO.java:57)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDef
initionsFromURLs(CachingLocaleUrlDefinitionDAO.java:223)
        at org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadP
arentDefinitions(ResolvingLocaleUrlDefinitionDAO.java:57)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDef
initionsFromURLs(CachingLocaleUrlDefinitionDAO.java:223)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDef
initions(CachingLocaleUrlDefinitionDAO.java:205)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.checkAn
dloadDefinitions(CachingLocaleUrlDefinitionDAO.java:188)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefi
nitions(CachingLocaleUrlDefinitionDAO.java:151)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefi
nition(CachingLocaleUrlDefinitionDAO.java:119)
        at org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefi
nition(CachingLocaleUrlDefinitionDAO.java:53)
        at org.apache.tiles.definition.UrlDefinitionsFactory.getDefinition(UrlDe
finitionsFactory.java:104)
        at org.apache.tiles.impl.BasicTilesContainer.getDefinition(BasicTilesCon
tainer.java:363)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.
java:616)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.
java:322)
        at org.apache.tiles.jsp.taglib.InsertDefinitionTag.renderContext(InsertD
efinitionTag.java:66)
 
Why is the UrlDefinitionsFactory factory being returned by the 
BasicTilesContainer?  I expected the LocaleDefinitionsFactory to have been 
instantiated and returned instead.  This confirms my findings none of the 
methods on my DbTilesContainerFactory are being called, and instead the 
BasicTilesContainer returns its default DefinitionsFactory, which in turn tries 
to read definitions from the default .xml files (which don't exist!).
 
In a separate debugging exercise to determine if the container returns the 
correct DefinitionsFactory, I have the following code in a JSP:
 
  TilesContainer container = JspUtil.getContainer(pageContext);
  LocaleDefinitionsFactory factory = (LocaleDefinitionsFactory) 
container.getDefinitionsFactory(); 

The container variable is of type BasicTilesContainer.  The next line in the 
code throws a ClassCastException.
 
I will appreciate any help you can provide.  Do let me know if you need any 
further details, and thanks for the guidance so far!
 
Vibhore 

--- On Wed, 4/1/09, Antonio Petrelli <[email protected]> wrote:


From: Antonio Petrelli <[email protected]>
Subject: Re: Support for reloading/refreshing Tile Definitions
To: [email protected]
Date: Wednesday, April 1, 2009, 8:07 PM


2009/4/1 Vibhore Anant <[email protected]>:
> I now want to implement a feature where a single Definition can be reloaded 
> if it has changed.  I see that there is a "refresh()" method available on the 
> UrlDefinitionsFactory class.

This way of refreshing is deprecated. It works only using
"TilesFilter" to startup Tiles.

> do I have to switch over to writing a custom DefinitionsDAO class in order to 
> get refresh support?  I did look at the source code for the refresh() method 
> in UrlDefinitionsFactory and it is calling refresh() on a defintionsDAO 
> object.  I haven't provided an implementation, so what is getting called by 
> default?

You can use CachingLocaleUrlDefinitionDAO, together with
LocaleDefinitionsFactory, forcing to "true" this parameter in web.xml:
org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO.CHECK_REFRESH
(not documented, I will open a JIRA issue for this)
or, if you are using Java initialization, call
"CachingLocaleUrlDefinitionDAO.setCheckRefresh".
And yes, you should move definition loading into the DAO.
However, are you really sure that you *need* refresh? You can
implement your DefinitionDAO without managing caching, using
LocaleDefinitionsFactory (that does not cache anything).

>  Having studied the example in the HOW-TO section, it wasn't entirely 
> clear what purpose the customisation Key serves.  I have no intent to support 
> localised Definitions - what else could be used as the customisation Key if I 
> must migrate to this approach instead of the custom DefinitionsReader class I 
> have now?

Think of a portal, in which definitions are customized per user. In
this case the customization key is the user.

> If anyone can shed some light on what my approach should be to support 
> refresh of single Definitions, that will be much appreciated.

The refresh operation is "global", so you cannot update a single
definition. However, as I said before, you can use a variant of
LocaleDbDefinitionDAO and LocaleDefinitionsFactory

HTH
Antonio



      

Reply via email to