diff -r 4ec7f2600c83 -r 24a3596b8f98 src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat May 30 15:28:27 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat May 30 18:05:06 2020 +0200 @@ -39,10 +39,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; +import java.lang.reflect.*; import java.sql.Connection; import java.sql.SQLException; import java.util.*; @@ -280,30 +277,44 @@ * @return the parameter value or an empty optional, if no parameter with the specified name was found */ protected Optional getParameter(HttpServletRequest req, Class clazz, String name) { - final String paramValue = req.getParameter(name); - if (paramValue == null) return Optional.empty(); - if (clazz.equals(Boolean.class)) { - if (paramValue.toLowerCase().equals("false") || paramValue.equals("0")) { - return Optional.of((T)Boolean.FALSE); - } else { - return Optional.of((T)Boolean.TRUE); + if (clazz.isArray()) { + final String[] paramValues = req.getParameterValues(name); + int len = paramValues == null ? 0 : paramValues.length; + final var array = (T) Array.newInstance(clazz.getComponentType(), len); + for (int i = 0 ; i < len ; i++) { + try { + final Constructor ctor = clazz.getComponentType().getConstructor(String.class); + Array.set(array, i, ctor.newInstance(paramValues[i])); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + return Optional.of(array); + } else { + final String paramValue = req.getParameter(name); + if (paramValue == null) return Optional.empty(); + if (clazz.equals(Boolean.class)) { + if (paramValue.toLowerCase().equals("false") || paramValue.equals("0")) { + return Optional.of((T) Boolean.FALSE); + } else { + return Optional.of((T) Boolean.TRUE); + } + } + if (clazz.equals(String.class)) return Optional.of((T) paramValue); + if (java.sql.Date.class.isAssignableFrom(clazz)) { + try { + return Optional.of((T) java.sql.Date.valueOf(paramValue)); + } catch (IllegalArgumentException ex) { + return Optional.empty(); + } + } + try { + final Constructor ctor = clazz.getConstructor(String.class); + return Optional.of(ctor.newInstance(paramValue)); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); } } - if (clazz.equals(String.class)) return Optional.of((T) paramValue); - if (java.sql.Date.class.isAssignableFrom(clazz)) { - try { - return Optional.of((T)java.sql.Date.valueOf(paramValue)); - } catch (IllegalArgumentException ex) { - return Optional.empty(); - } - } - try { - final Constructor ctor = clazz.getConstructor(String.class); - return Optional.of(ctor.newInstance(paramValue)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } /**