Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.appfuse.webapp.controller;
  
 
 import java.util.Date;
 
 @RequestMapping("/userform*")
 public class UserFormController {
     private final Log log = LogFactory.getLog(UserFormController.class);
 
     @Autowired
 
     @Autowired(required = false)
 
     private MessageSourceAccessor messages;
 
     @Autowired
     public void setMessages(MessageSource messageSource) {
          = new MessageSourceAccessor(messageSource);
     }

    
Set up a custom property editor for converting Longs

Parameters:
binder the default databinder
 
     @InitBinder
     public void initBinder(ServletRequestDataBinder binder) {
         // convert java.util.Date
         SimpleDateFormat dateFormat = new SimpleDateFormat(getText("date.format"));
         dateFormat.setLenient(false);
         binder.registerCustomEditor(Date.classnull,
                 new CustomDateEditor(dateFormattrue));
 
         // convert java.lang.Long
         binder.registerCustomEditor(Long.classnull,
                 new CustomNumberEditor(Long.classnulltrue));
     }
 
     @RequestMapping(method = .)
     public String onSubmit(User userBindingResult resultHttpServletRequest requestthrows Exception {
 
         if (request.getParameter("cancel") != null) {
             return "redirect:users";
         }
 
         if ( != null && request.getParameter("delete") == null) { // validator is null during testing
             .validate(userresult);
 
             if (result.hasErrors()) {
                 return "userform";
             }
         }
 
         .debug("entering 'onSubmit' method...");
 
         if (request.getParameter("delete") != null) {
             .removeUser(user.getId().toString());
             request.getSession().setAttribute("message",
                     getText("user.deleted"user.getFullName()));
         } else {
             try {
                 .saveUser(user);
             } catch (UserExistsException uex) {
                 result.addError(new ObjectError("user"uex.getMessage()));
                 return "userform";
             }
             request.getSession().setAttribute("message",
                     getText("user.saved"user.getFullName()));
         }
 
         return "redirect:users";
     }
 
     @ModelAttribute
     @RequestMapping(method = .)
     protected User getUser(HttpServletRequest request) {
        String userId = request.getParameter("id");
        if ((userId != null) && !userId.equals("")) {
            return .getUser(userId);
        } else {
            return new User();
        }
    }

    
Convenience method for getting a i18n key's value.

Parameters:
msgKey the i18n key to lookup
Returns:
the message for the key
    public String getText(String msgKey) {
        return .getMessage(msgKey);
    }

    
Convenient method for getting a i18n key's value with a single string argument.

Parameters:
msgKey the i18n key to lookup
arg arguments to substitute into key's value
Returns:
the message for the key
    public String getText(String msgKeyString arg) {
        return getText(msgKeynew Object[]{arg});
    }

    
Convenience method for getting a i18n key's value with arguments.

Parameters:
msgKey the i18n key to lookup
args arguments to substitute into key's value
Returns:
the message for the key
    public String getText(String msgKeyObject[] args) {
        return .getMessage(msgKeyargs);
    }
New to GrepCode? Check out our FAQ X