Results 1 to 2 of 2

Thread: Correct way to handle unique object retrieval

  1. #1
    Join Date
    Apr 2006
    Posts
    7

    Default Correct way to handle unique object retrieval

    I'm calling my DAO and I'm looking to get a unique result. I'm trying to figure what to do when there is no result with that ID.

    Is this how?

    -Avinash

    Code:
    protected ModelAndView handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, java.lang.Object command, BindException bindException) throws java.lang.Exception {
            
            DisplayProductCommand displayCommand = (DisplayProductCommand) command;
            Map myModel = new HashMap();
            Product myProduct;
            myProduct = getProductDao().getProduct(displayCommand.getId());
            
            if(myProduct!=null){
                myModel.put("product",myProduct);
                return new ModelAndView("product_detail", "model", myModel);
            } else{
                return new ModelAndView("error","message","Invalid Product ID!");
            }
            
        }

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    It depends on what frameworks on the view side are you using. I'd recommend you take use the web forum - the 'data' part seems to work just fine .
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

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