All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jwebform.spring.ContainerFormRunnerArgumentResolver Maven / Gradle / Ivy

package jwebform.spring;

import jwebform.integration.ContainerFormRunner;
import jwebform.integration.FormRunnerConfig;
import jwebform.processor.FormGenerator;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.servlet.http.HttpServletRequest;


public class ContainerFormRunnerArgumentResolver implements HandlerMethodArgumentResolver {

  private final FormRunnerConfig formRunnerConfig;

  public ContainerFormRunnerArgumentResolver(
    FormRunnerConfig formRunnerConfig) {
    this.formRunnerConfig = formRunnerConfig;
  }

  @Override
  public Object resolveArgument(MethodParameter methodParam, ModelAndViewContainer mavContainer,
      NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {

    methodParam.increaseNestingLevel();
    Class typeOfBean = (Class) methodParam.getNestedParameterType();
    methodParam.decreaseNestingLevel();

    ContainerFormRunner f = new ContainerFormRunner(typeOfBean, t -> request.getParameter(t),
        t -> request.getNativeRequest(HttpServletRequest.class).getAttribute(t),
        (t, v) -> request.getNativeRequest(HttpServletRequest.class).setAttribute(t, v),
        (t, v) -> mavContainer.addAttribute(t, v), formRunnerConfig);

    return f;
  }


  @Override
  public boolean supportsParameter(MethodParameter parameter) {
    return parameter.getParameterType().equals(ContainerFormRunner.class);
  }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy