2

As we see the Tiles docs said https://tiles.apache.org/framework/tutorial/advanced/wildcard.html We can define a wildcard to accept arbitrary name. But if the name includes "/", for example "c4/login". Tiles will throw an exception

org.apache.tiles.definition.NoSuchDefinitionException: c4/login
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:625)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)

My definition is below:

<definition name="*" template="/WEB-INF/tiles/basicLayout.jsp">
  <put-attribute name="header" value="/WEB-INF/tiles/header.jsp" />
  <put-attribute name="content" value="/WEB-INF/pages/{1}.jsp" />
  <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" />
</definition>

If I change definition to the example below, a name with slash inside is accepted.

<definition name="c4/login" template="/WEB-INF/tiles/basicLayout.jsp">
  <put-attribute name="header" value="/WEB-INF/tiles/header.jsp" />
  <put-attribute name="content" value="/WEB-INF/pages/c4/login.jsp" />
  <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" />
</definition>

Please advise. Thanks a lot.

Matt
  • 1,671
  • 5
  • 23
  • 34

2 Answers2

2

I think I found a more general workaround: use ** as the wildcard:

<definition name="**" template="/WEB-INF/tiles/basicLayout.jsp">
  <put-attribute name="header" value="/WEB-INF/tiles/header.jsp" />
  <put-attribute name="content" value="/WEB-INF/pages/{1}.jsp" />
  <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" />
</definition>
Didier L
  • 18,905
  • 10
  • 61
  • 103
  • A word of warning: `name="**"` is a very greedy wildcard. Depending on your setup, it could be very easy to get an infinite loop going as per [this question + answer](http://stackoverflow.com/questions/6521609/why-tiles-regexp-wildcard-definition-cause-endless-jsp-including-error/6617343). – Mar May 15 '15 at 03:33
1

I got a workaround solution, use the revised definition below

<definition name="*/*" template="/WEB-INF/tiles/basicLayout.jsp">
  <put-attribute name="header" value="/WEB-INF/tiles/header.jsp" />
  <put-attribute name="content" value="/WEB-INF/pages/{1}/{2}.jsp" />
  <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" />
</definition>

Hope this is useful for you.

Matt
  • 1,671
  • 5
  • 23
  • 34