You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Mike Hepple <mi...@impresariostudios.com> on 2013/07/16 03:26:19 UTC

Configuring Tiles for a modular applications

Hi,

 

I'm attempting to make a configuration which will allow me to define modules
at build-time for distribution to various customers. My main client requires
'all' the features, and other clients require a subset of features. It's an
existing application based on Tiles 2.2.2 (although upgrading to 3 if
necessary is fine).

 

Based on the documentation I assumed I could do something like this:

 

core-tiles.xml

 

<definition name="myapp.homepage" template="/layouts/classic.jsp">

  <put-attribute name="header" value="/tiles/banner.jsp" />

  <put-attribute name="menu" value="/tiles/common_menu.jsp" />

  <put-attribute name="body" value="/tiles/home_body.jsp" />

  <put-attribute name="footer" value="/tiles/credits.jsp" />

</definition>

 

 

core.jsp

 

.

<tiles:insertDefinition name="moduleA" ignore="true" />

.

 

module-a.xml

 

<definition name="moduleA" template="/moduleA/module.jsp">

 

Now, if I do that, and include module-a.xml, everything works fine. If I
remove module-a.xml though, I get a runtime exception (as if the
ignore="true" wasn't there).

 

I did some digging, and found this:

 

https://issues.apache.org/jira/browse/TILES-441

 

which I'm guessing means that insertDefinition in 2.2.2 suffers the same
fate. No problem I thought - time to get up to date.. however it seems that
Tiles 3.x removes support for ignore=true in definitions? 

 

http://tiles.apache.org/framework/tiles-jsp/tagreference.html#tiles:insertDe
finition

 

So. I'm stumped! Can anyone think of an intelligent way to handle the
non-existence of features in a meaningful manner? Basically all I want is
the ability to do (in pseudo-code)

 

if moduleA exists:

                                insert module.jsp

                else:

                                do nothing

 

Thanks for reading, appreciate any help you can provide.

 

Mike


Re: Configuring Tiles for a modular applications

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Hi Mike,

An approach I've used in Tiles2 is to create a DefinitionsFactory that applies logic to the selection the correct tiles Definition.
Instead of complex conventions in tiles configuration, include some logic in the lookup instead, falling back to (for example) blank tiles/alternative tiles.

A DefinitionsFactory includes the method that loads the Definition based on name.

Definition getDefinition(String name, TilesRequestContext context);

In can be set up via a context param for tiles (http://tiles.apache.org/config-reference.html):
<context-param>
  <param-name>org.apache.tiles.definition.DefinitionsFactory</param-name>
  <param-value>fully qualified class name to MyCustomDefinitionsFactory</param-value>
</context-param>

The default DefinitionsFactory is UrlDefinitionsFactory.  You won't want to rewrite that, so you can just wrap an instance and delegate to it to access standard functionality.

public class MyCustomDefinitionsFactory implements DefinitionsFactory {
  DefinitionsFactory delegate;

  public MyCustomDefinitionsFactory() {
      delegate = new UrlDefinitionsFactory();
  }

// implement other methods required for the interface, delegating to the delegate 
//  getDefinition should override the name when necessary though:
public Definition getDefinition(String name, TilesRequestContext context) {
     if (need to change tile/exclode tile based on context) {
        String alternativeName = (calculate appropriate tile to use)
        return delegate.getDefinition(alternativeName, context) {
     } else {
         return delegate.getDefinition(name, context);
     }
}


Hope that helps.

Regards,
 Jeromy Evans


On 16/07/2013, at 11:26 AM, Mike Hepple <mi...@impresariostudios.com> wrote:

> 
> So. I'm stumped! Can anyone think of an intelligent way to handle the
> non-existence of features in a meaningful manner? Basically all I want is
> the ability to do (in pseudo-code)
>