Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Use SiteMesh to decorate multiple webapps

Did you know it's possible to decorate multiple webapps with the same SiteMesh decorator? I learned how to do this from the SiteMesh mailing list:

  • Put sitemesh.jar in your container's classpath. You could put it into each webapp's WEB-INF/lib, but it looks like there's problems with that.
  • Create and deploy a webapp that contains the common decorator.
  • In each webapp's decorators.xml, add a "webapp" attribute to point to the webapp you deployed in Step 2.
    <decorators>
        <!-- load decorator from a different web-app deployed in the server -->
        <decorator name="main" webapp="some-other-webapp" 
            page="/decorators/main.jsp">
            <pattern>/*</pattern>
        </decorator>
    </decorators>
    

Try to do *that* with Tiles. ;-)

Posted in Java at Apr 12 2005, 10:05:19 AM MDT 12 Comments
Comments:

Tiles => Composition SiteMesh => Decoration From each tool according to their compentancy to each solution according to their need.

Posted by Patrick Peak on April 12, 2005 at 11:13 AM MDT #

if running in tomcat, just make sure that you've configued it to allow you to cross contexts, this is disabled in later versions for security reasons afair

Posted by analogueboy on April 12, 2005 at 11:26 AM MDT #

Patrick, I know what each does and what they're good at. :-D

I'm just trying to give SiteMesh the credit it deserves. Ever since I switched from Tiles to SiteMesh, I've had no reason to go back. I guess that means I don't have much of a need for page composition in the applications I develop.

Posted by Matt Raible on April 12, 2005 at 11:38 AM MDT #

Hi.

I have a problem with struts + sitemesh + velocity. Struts Velocity tools doesn't work when I try to use it with sitemesh. This is my web.xml.

<display-name>GAMS Web IDE</display-name>
  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping> 

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>velocity</servlet-name>
    <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
    <init-param>
      <param-name>org.apache.velocity.toolbox</param-name>
      <param-value>/WEB-INF/toolbox.xml</param-value>
    </init-param>
    <init-param>
      <param-name>org.apache.velocity.properties</param-name>
      <param-value>/WEB-INF/velocity.properties</param-value>
    </init-param>
    <load-on-startup>4</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>sitemesh-velocity</servlet-name>
    <servlet-class>
		com.opensymphony.module.sitemesh.velocity.VelocityDecoratorServlet
	</servlet-class>
	<load-on-startup>3</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>velocity</servlet-name>
    <url-pattern>*.vm</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>sitemesh-velocity</servlet-name>
    <url-pattern>*.vm</url-pattern>
  </servlet-mapping>

Posted by arek on April 12, 2005 at 03:07 PM MDT #

I remember someone was a Tiles fanboy back then wasn't keen about other solutions. Hmmm, who could that be?

Posted by Aditya on April 12, 2005 at 06:13 PM MDT #

Excellent! I was wanting to know if that could be done. Ill be making some modifications to my apps very soon!

Posted by Dan Campers on April 12, 2005 at 07:25 PM MDT #

Aditya - you are correct. I was once a Tiles fanboy, but then I saw the light. Now I wish I'd seen the light years ago, but at the same time - I'm glad I learned Tiles.

Posted by Matt Raible on April 13, 2005 at 12:08 PM MDT #

I must say that this works very nicely - I've been using a similar approach with SiteMesh on my Alien-Factory website for about a month now.

Splitting your website up into multiple web apps gives you finer grained control over re-deployment. (Why re-deploy your entire website for a little change in one subsection?) And SiteMesh still allows you to retain a consistent look and feel for the whole, in the one place.

Posted by Steve Eynon on April 14, 2005 at 08:54 AM MDT #

Neat trick. Now it would be great if SiteMesh didn't have a issue with its buffering system and could avoid OOM on larger pages.

Posted by Tim on April 21, 2005 at 02:34 PM MDT #

[Trackback] ...

Posted by Guava on April 25, 2005 at 08:10 PM MDT #

will sitemesh affect the speed when running by multiple users?

will so many filters affect the speed of a website?

Posted by 202.237.165.249 on February 03, 2006 at 01:03 AM MST #

        <filter-mapping>
		<filter-name>sitemesh</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>
	<servlet>
		<servlet-name>mainWebapp</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>
	
	<servlet>
		<servlet-name>webapp2</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>mainWebapp</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>webapp2</servlet-name>
		<url-pattern>/webapp2/*</url-pattern>
	</servlet-mapping>

is the web.xml config and the decorator.jsp is as follows

     <decorator name="webapp2" webapp="webapp2" page="default.jsp">
        <pattern>**</pattern>
    </decorator>
	<decorator name="default" page="default.jsp">
                 some patterns here
       </decorator>

and i have separate mainWebapp-servlet.xml and webapp2-sevlet.xml. The dispatcher servlet dispatches correctly and also the decoration is applied properly. But the problem is when you want to exclude the decoration for ajax request, by changing pattern ** to someUrl.* it does not pick up correctly.. i have tried all option like **/webapp2/someUrl.*, **/someUrl.*, **someUrl.*, /someUrl.* for all the any above specific url it is not working..

Any body can explain what may be the problem, that will be great help. thanking you..

Posted by Rakshith Begane on January 27, 2009 at 11:16 PM MST #

Post a Comment:
  • HTML Syntax: Allowed