0

I would like integrate struts 2 with spring mobile. On Spring official site, http://docs.spring.io/spring-mobile/docs/1.1.1.RELEASE/reference/html/device.html

I have follow instructions to integrate spring mobile on my project. On start up, i have not encounter any problem, but when i try to obtain the currentDevice my object is null, with :

Device currentDevice = DeviceUtils.getCurrentDevice(request);

Have someone tried to integrate spring mobile with struts2 ??

my web.xml:

<filter>
    <filter-name>deviceResolverRequestFilter</filter-name>
    <filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
</filter>

 <filter-mapping>
    <filter-name>deviceResolverRequestFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping> 

Definition of my handler interceptor on applicationContext.xml:

 <bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />

My testClass:

    public class AuthenticationAction extends ActionSupport implements
            SessionAware, ServletRequestAware {

        Log mylog = LogFactory.getLog(AuthenticationAction.class);

        // So that we can lookup the current Device
        private HttpServletRequest request;

    @RequestMapping("/")
       public String computeLogin() {
                   ...
         Device currentDevice = DeviceUtils.getCurrentDevice(request);

                if (currentDevice != null) {

                    mylog.info("Device type: ");

                    mylog.info("mobile: " + currentDevice.isMobile());
                    mylog.info("normal " + currentDevice.isNormal());
                    mylog.info("tablet " + currentDevice.isTablet());

                }
    }

public void setSession(Map<String, Object> session) {
        this.mySession = session;

    }

    public void setServletRequest(HttpServletRequest request) {
        this.setRequest(request);

    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
}
Bomberlatinos9
  • 790
  • 3
  • 11
  • 24
  • 1
    Are your filters set up in the correct order in your `web.xml` (see http://stackoverflow.com/questions/10801800/spring-mobile-interceptor-not-applied-device-is-null) – nmc May 12 '14 at 17:35
  • @nmc The solution is to put in the correct order on web.xml. I have move up before struts2 filter definitions, and all goes well.I have delete the bean defined in applicationContext.xml. thnx nmc – Bomberlatinos9 May 12 '14 at 19:03

0 Answers0