Under the sitemesh-common folder duplicate all files with “iphone” in the name but replace the “iphone” with “mobile”.  Then open each new file and replace any paths that reference the “iphone” directory with the same paths under our new “mobile” directory.

Under the sitemesh-decorators folder also duplicate all files with “iphone” in the name but replace the “iphone” with “mobile”.  Then open your newly created main-mobile.jsp file.  This main sitemesh file will be used as the shell for all of our mobile pages.  The HTML header contains several iPhone-specific tags that we don’t need so let’s remove them. Just remove everything with "Apple" in the tag.

iPhone Image Links and Meta Tags

iPhone Image Links and Meta Tags

Also in the HTML header are two link tags that link to external stylesheets.  The first is to the iWebKit stylesheet that is used to get that fancy iPhone look and feel.  The second is to a MyEclipse for Spring provided sheet that overrides some of the rules in the iWebKit stylesheet.  Remove one of them and change the second one to link to our style-mobile.css stylesheet.

iPhone CSS Links

iPhone CSS Links

Scroll down to the body of the main-mobile.jsp file and change the references to dashboard-iphone and footer-iphone to use our mobile versions instead.  We’re going to leave those dashboard and footer files alone but you could change them to contain something special for your non-iPhone mobile apps.  Save the main-mobile.jsp file.

Now let’s configure sitemesh to use these new mobile files.  Open the sitemesh.xml file located directly in the WEB-INF folder.  The sitemesh.xml file contains two decorator-mappers, one for the spring mvc decorators and one for the iphone decorators.

Generated Decorator Mappers

Generated Decorator Mappers

We need to create a mapper for our new mobile files that will direct some other mobile browsers to our new sitemesh files.  The mappers work by matching any string in the user-agent string of the HTTPRequest header.  You can find the two new mappers for Android and Palm Pre here. Just paste them into your sitemesh.xml after the iPhone matcher.

I created the new mappers by copying the iphone mapper and changing the name to match on Android or webOS and the value attribute to “mobile”.  That "mobile" value attribute corresponds to the suffix we put on all of our sitemesh files.  There are many web resources that can help you understand what the user-agent strings are for the various browsers and handsets.  I want to match on Android and Palm Pre so my decorator-mappers will look like this when I’m done:

Android and Palm Pre Decorators

Android and Palm Pre Decorators

Note that I created two mappers pointing to my single mobile site. I also used very simple match strings. You can be more specific, I just wanted to pick up all Android phones and all Palm devices that specify webOS.

Disclaimer: There are other technologies that can be used to re-direct browsers based on user agents and browser capabilities.  The mechanism I’m using is the simplest for the MyEclipse for Spring generated applications because it adds to the existing scaffolded configuration.

Related Posts

Connecting your Angular 2 App to your Java EE Back... Connecting your Angular 2 App to your Java EE BackendYou’ve been developing in Java EE all this time, but you’re tired of using JSF, or perhaps even Struts, and want to move to something more modern for your front end? Angular 2 is a perfect fit, and with the recent release of Angular 2 GA, now is the ideal time to make the move! Besides being easi...
Angular Who? Staying true to the Angular dynasty.When you are in a serious relationship, you want your partner to have it all… So when someone more attractive comes along, it’s hard to resist the temptation, isn’t it? That’s true for those who started their love story with Angular (or should we say “AngularJS” or “Angular 1”?), have dumped him for Angular 2 (or...
SDC 2017 – Looks, Security & Neon. Get your installers ready (Java 1.8), because Neon is here! Our first release of the year is based on Eclipse Neon and with it, many other exciting updates.Totally new portal, we are updating the look and feel of the SDC portal, giving extra functionality that allows you to perform basic editing of packages without the need of the Admin Console. Yo...
Java 8 Features Supported by Spring 4 Spring Framework 4 supports Java 8 language and API features. In this article, we will focus on the new Java 8 features which are supported in Spring 4. The most important ones are lambda expressions, method references, JSR-310 Date and Time, and Repeatable annotations.Lambda ExpressionsSpring code base uses a lot of functional interfaces and with ...

Posted on Aug 9th 2010