package nl.vpro.poel.controller;

import nl.vpro.poel.UserUtil;
import nl.vpro.poel.domain.CurrentUser;
import nl.vpro.poel.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;

/**
 * This class adds model attributes that are common to all controllers.
 */
@ControllerAdvice
public class PoelControllerAdvice {

    private final MessageService messageService;

    private final String title;

    @Autowired
    public PoelControllerAdvice(MessageService messageService, @Value("${poel.title}") String title) {
        this.messageService = messageService;
        this.title = title;
    }

    @ModelAttribute("user")
    public CurrentUser user(Principal principal) {
        return UserUtil.getCurrentUser(principal).orElse(null);
    }

    @ModelAttribute("message")
    public String message(HttpServletRequest request) {
        String key = request.getRequestURI();
        return messageService.getText(key).orElse("");
    }

    @ModelAttribute("title")
    public String title() {
        return title;
    }
}

@@ -303,35 +303,145 @@
 ind.
-annotation.ControllerAdvice
+WebDataBinder;%0Aimport org.springframework.web.bind.annotation.ControllerAdvice;%0Aimport org.springframework.web.bind.annotation.InitBinder
 ;%0Aim
@@ -603,48 +603,51 @@
 ass 
-adds model attributes that are common to
+sets configuration and model attributes for
  all
@@ -966,16 +966,16 @@
 ervice;%0A
-
         
@@ -993,32 +993,234 @@
 = title;%0A    %7D%0A%0A
+    @InitBinder%0A    public void initBinder(WebDataBinder binder) %7B%0A        binder.setAutoGrowCollectionLimit(1024); // By default 256 is the max and we might get a POST with more users than that%0A    %7D%0A%0A
     @ModelAttrib

Allow posting collections with more than 256 items, Luke!