tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: Configuring Tiles for a modular applications
Date Tue, 16 Jul 2013 02:22:03 GMT
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):
  <param-value>fully qualified class name to MyCustomDefinitionsFactory</param-value>

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.

 Jeromy Evans

On 16/07/2013, at 11:26 AM, Mike Hepple <mike@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)

View raw message