Sign in to edit and +1 items.
Login required
Download

Spring Mobile Grails plugin

(1)
Author(s) Sebastien Blanc
Current Release 0.4   (1 month ago)
Grails Version 1.3.6 > *
Tags
Dependency
compile ":spring-mobile:0.4"
Custom repositories
mavenRepo "http://snapshots.repository.codehaus.org/"
mavenRepo "http://maven.springframework.org/milestone/"
Device resolver based on the Spring Mobile Library
Last updated by admin 1 year ago
Last updated by sebastien.blanc 2 months ago

Introduction

This plugin is a wrapper around the Spring Mobile Project . The main feature is the detection of mobile devices for incoming http requests.

Usage

The plugin will inject the following dynamic method inside your controllers :

withMobileDevice(Device device,Closure closure)

The plugin is shipped with 2 different device resolvers, the default one is the lite resolver :

def list = {
  def view = "list"
  withMobileDevice {
        view = "mobileList"
  }
 render(view: view, model: [list: listInstance])
}

But you can also use a more sophisticated device resolver based on the WURFL project . The WURFL resolver will give you more information about the mobile device, like type (Android, iPhone) or capabilities etc ..

def list = {
  withMobileDevice {def device ->
       println device //The toString() shows a lot of information about the device
       def view = "list"
       if(device.id.contains("iphone"){
           view = "iphoneList"       
        }
       view ="mobileList"
  }
 render(view: view, model: [list: listInstance])
}

If the client is an iPhone, for instance, this will be printed in the console (I stripped some info from the capabilities map to keep it short) :

[WurflDevice mobile=true, id=apple_iphone_ver4_1_sub8b117, userAgent=Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X;
 en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7, capabilities 
={screensaver_greyscale=false, fl_wallpaper=false, mms_xmf=false, columns=20, viewport_supported=true }, 
markup=XHTML_ADVANCED]

To use the WURFL resolver you need to specify it in your Config.groovy :

springMobile {
	deviceResolver="wurfl"
}

Coming features

Spring Mobile is a quite young product, some other features (siteSwitcher, sitePreference) are already available but not included in this plugin for the moment. I will probably wait for the first stable release before I include them.

Last updated by admin 1 year ago
Last updated by admin 1 year ago