Thursday, June 10, 2010

conditionally load jQuery-UI

      /* only load jQuery-ui if not present */  
      if (typeof jQuery.ui == 'undefined') {  
           document.write("<script type=\"text/javascript\"  src=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js\"></"+"script>");  
           //var __noconflict = true;  
      }  
      /* if Google is down */  
      if (typeof jQuery.ui == 'undefined') {  
           document.write("<script type=\"text/javascript\"  src=\"webCentral/script/jquery-ui.min.js\"></"+"script>");  
           //var __noconflict = true;  
      }  

Forwarding objects to a new view in Spring

Sometimes it is helpful to forward a command object or view data to another view in Spring.  This is how you do it, using a SimpleFormController.

1:  protected ModelAndView onSubmit(HttpServletRequest request,   
2:   HttpServletResponse response, Object command, BindException errors)  
3:   throws Exception{  
4:    ModelAndView mav = onSubmit(command, errors);  
5:    Map<String, Object> itemGroupMap = referenceData(request);  
6:    ((ItemGroup)command).setItemCount(  
7:              _helper.getItemCount((ItemGroup)command));  
8:    itemGroupMap.put(ITEM_GROUP_COMMAND_OBJECT_NAME, command);  
9:    mav.getModel().putAll(itemGroupMap);  
10:    return mav;  
11:  }  

This method gets the ModelAndView that would normally come out of a submit, then adds objects to the model for use by the second view.