Announcement Announcement Module
Collapse
No announcement yet.
Correct way to handle unique object retrieval Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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 .

    Comment

    Working...
    X