Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

java - Better alternative to Apache Tiles

I'm looking for a framework that is better and easier to use than Apache Tiles (which so far, I have used a couple of times).

With Tiles, it seems that when I have 100 actions I need to creates 100 jsp files and create 100 definitions in tiles.xml.

Is there a better framework to manage my templates? I want to create, for example, 2 templates:

a) menu and column for content
b) menu, column for content, right column with banner

In both templates the menu is constant. In template b, the right column is constant, so only the content column is different. For this simple example I don't want to define each JSP file that extends the template a (just to provide a body). Thats lame imo. Or maybe I`m lame and I can define a DEFAULT template in Apache Tiles and I'm just not using it right. In anycase, all help appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Overall, I would recommend SiteMesh over Tiles.

Here's how to setup SiteMesh 3

You can use Tiles for in-page templates, but use SiteMesh for site-wide template. Nevertheless...

How to make Tiles suck less:

  1. Use convention over configuration. For example, put your definitions in webapp/WEB-INF/tiles.xml and there's no need to tell tiles where it is.

  2. Use wildcards:

<definition name="default" template="/WEB-INF/templates/default.jsp">
    <put-attribute name="titleKey" value=""/>
    <put-attribute name="body" value=""/>
</definition>

<definition name="*" extends="default">
    <put-attribute name="titleKey" value="{1}.title"/>
    <put-attribute name="body" value="/WEB-INF/views/{1}.jsp" />
</definition>

If your controller returns view name index, it will match the definition *, and use the JSP file /WEB-INF/views/index.jsp for the body, and use the message property index.title.

If your controller returns view name contact-us, it will match the definition *, and use the JSP file /WEB-INF/views/contact-us.jsp for the body, and use the message property contact-us.title

In your template, add:

<c:set var="titleKey"><tiles:getAsString name="titleKey" /></c:set>

and

<title><spring:message code="${titleKey}"/></title>

Add ReloadableResourceBundleMessageSource bean to your servlet application context.

Make a file /src/main/resources/messages.properties, with content like:

index.title = Welcome to Acme, Inc.
contact-us.title = Contact Us

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...