This was originally a fix for "Saving Template causes Null Pointer Exception"
But... once I fixed the problem I found a series of other problems and ended up making some fundamental changes in the way that Roller's new mobile template support is implemented. I will summarize.
1) The Template Edit page now uses the YUI tab control to switch between a Page's standard and mobile template code on the client side. Both values are saved on the client-side and switching tabs no longer causes a page refresh.
2) This is the big change: Instead of determining the device-type and then injecting the right template code into the Roller Page object, which could cause other requests to get the wrong data inside the Page object, we now determine the device type and pass it down deep into Roller's rendering engine. At the RollerResourceLoader level we use the deviceType to fetch the correct template code for the deviceType.
3) What we called "type" in many places is now an enum called DeviceType and the variable is called deviceType instead of "type" everywhere.