PDA

View Full Version : Default ViewController for mobile ?



gonzalad
Aug 29th, 2011, 08:27 AM
Hello,

I'm using for the first time Spring Mobile, works great so far.

Just one question though.

In my webapp, I'm using :

<mvc:view-controller path="/login"/>

I want to decline the login page for mobiles, so I create login-mobile.jsp.

Now, I want mvc:view-controller to display login.jsp for desktop application and login-mobile.jsp for mobile application.

Only way to do that is to remove the mvc:view-controller and create a custom controller like this :

@Controller
public class LoginController {


@RequestMapping("/login")
public String login(Device device) {
if (device.isMobile()) {
return "login-mobile";
} else {
return "login";
}
}
}




Is there an easier way ?

Otherwise should I create a JIRA issue to ask for adding something like :
<mvc:mobile-view-controller path="/login"/> ?

Thanks for the help !

P.S. this thread is quite similar, but no JIRA found : http://forum.springsource.org/showthread.php?98933-InternalResourceViewResolver-and-mobile-views&highlight=mvc%3Aview-controller

Roy Clarkson
Dec 5th, 2012, 09:12 AM
That is correct. Currently, this is how you would do it. We've had a lot of discussion around a "device aware" view resolver [0], and I think we have a good idea how that should look now. I'm planning on including an implementation in the next milestone release.

[0] https://jira.springsource.org/browse/MOBILE-35