@Override
 public void setAsText(String text) throws IllegalArgumentException {
   if (text != null && text.trim().length() > 0) {
     Activity activity = activityRepository.getActivityById(text);
     if (activity != null) setValue(activity);
     else throw new IllegalArgumentException("No activity with ID " + text);
   } else setValue(null);
 }
  @RequestMapping(method = {RequestMethod.PUT, RequestMethod.POST})
  public String processSubmit(
      @PathVariable("id") String id,
      @ModelAttribute("form") LiveActivityGroupForm form,
      BindingResult result,
      SessionStatus status,
      Model model) {
    new LiveActivityGroupValidator().validate(form, result);
    if (result.hasErrors()) {
      addNeededEntities(model);
      return "liveactivitygroup/LiveActivityGroupEdit";
    } else {
      LiveActivityGroup group = activityRepository.getLiveActivityGroupById(id);
      form.saveLiveActivityGroup(group, activityRepository);
      activityRepository.saveLiveActivityGroup(group);

      status.setComplete();

      return "redirect:/liveactivitygroup/" + group.getId() + "/view.html";
    }
  }
  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@PathVariable("id") String id, Model model) {
    LiveActivityGroup group = activityRepository.getLiveActivityGroupById(id);
    LiveActivityGroupForm form = new LiveActivityGroupForm();
    form.copyLiveActivityGroup(group);

    model.addAttribute("form", form);
    model.addAttribute("id", id);

    addGlobalModelItems(model);

    addNeededEntities(model);

    return "liveactivitygroup/LiveActivityGroupEdit";
  }
 /**
  * Get any entities needed by the form that will be too heavyweight in the session.
  *
  * @param model the model to put the values in
  */
 private void addNeededEntities(Model model) {
   model.addAttribute(
       "liveactivities",
       WebSupport.getLiveActivitySelections(activityRepository.getAllLiveActivities()));
 }