Results 1 to 2 of 2

Thread: Best way to deliver content for HTML/Mobile/Json

  1. #1
    Join Date
    Jan 2008
    Posts
    248

    Default Best way to deliver content for HTML/Mobile/Json

    Hi,

    I'm just wondering what the best way would be to organize content delivery in a scenario where we have
    * An HTML website
    * A mobile website
    * A PhoneGap app that supports HTML pushState and works of json

    The important thing for me is to have a flexible url structure and minimal coding to support all options. I was thinking something like this

    PHP Code:
    /**
     * Displays a normal HTML page
     */
    @Controller
    @RequestMapping("/path")
    public class 
    StuffController{

        @
    Inject
        ItemManager itemMgr
    ;

        public 
    void insertCommonContent(ModelMap model){
            
    model.addAttribute("items"itemMgr.getItems());
        }

        @
    RequestMapping("/stuff"method=RequestMethod.GET)
        public 
    String getStuff(ModelMap model){
            
    insertCommonContent(model);
            
    model.addAttribute("pageTitle""Hello there");
            
    model.addAttribute("specialOffers"getSpecialOffers());
        }
    }

    /**
     * Returns json
     */
    @Controller
    public class JsonStuffController extends StuffController{

        @
    RequestMapping("/stuff.json"method=RequestMethod.GET)
        public @
    ResponseBody Map<String,ObjectgetStuff(ModelMap model){
            
    Map<String,Objectresp = new HashMap<String,Object>();
            
    resp.add("items"itemMgr.getItems());
            return 
    resp;
        }

    }

    /**
     * Displays an HTML page optimized for mobile
     */
    @Controller
    @RequestMapping("/path/mobile")
    public class 
    MobileStuffController extends StuffController{

        @
    RequestMapping("/stuff"method=RequestMethod.GET)
        public 
    String getStuff(ModelMap model){
            
    insertCommonContent(model);
        }


    Any suggestions?

    Marc

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,791

    Default

    Your code has sense, it work? Because you are working according to the URL (@RequestMapping).

    Other option I think is about a special value in the Header of the request (Check Spring Reference documentation for more details)

    BTW consider to include the @Override too
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •