use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.
the class CrudUserController method userAddEdit.
public Action userAddEdit(Integer id) {
if (id == null) {
return Actions.renderThis("entity", new UserDbo(), "levels", EducationEnum.values(), "roles", RoleEnum.values(), "selectedRoles", null, "password", null);
}
UserDbo user = UserDbo.findWithJoin(Em.get(), id);
List<UserRole> roles = user.getRoles();
List<RoleEnum> selectedRoles = roles.stream().map(r -> r.getRole()).collect(Collectors.toList());
return Actions.renderThis("entity", user, "levels", EducationEnum.values(), "roles", RoleEnum.values(), "selectedRoles", selectedRoles, "password", null);
}
use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.
the class ControllerLoader method htmlPreconditionCheck.
private void htmlPreconditionCheck(Object meta, Method controllerMethod, boolean isPostOnly) {
if (isPostOnly) {
Class<?> clazz = controllerMethod.getReturnType();
if (CompletableFuture.class.isAssignableFrom(clazz)) {
Type genericReturnType = controllerMethod.getGenericReturnType();
ParameterizedType t = (ParameterizedType) genericReturnType;
Type type2 = t.getActualTypeArguments()[0];
if (!(type2 instanceof Class))
throw new IllegalArgumentException("Since this route=" + meta + " is for POST, the method MUST return a type 'Redirect' or 'CompletableFuture<Redirect>' for this method=" + controllerMethod);
@SuppressWarnings("rawtypes") Class<?> type = (Class) type2;
if (!Redirect.class.isAssignableFrom(type))
throw new IllegalArgumentException("Since this route=" + meta + " is for POST, the method MUST return a type 'Redirect' or 'XFuture<Redirect>' not 'XFuture<" + type.getSimpleName() + ">'for this method=" + controllerMethod);
} else if (!Redirect.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("Since this route=" + meta + " is for POST, the method MUST return a type 'Redirect' or 'XFuture<Redirect>' not '" + clazz.getSimpleName() + "' for this method=" + controllerMethod);
} else {
Class<?> clazz = controllerMethod.getReturnType();
if (CompletableFuture.class.isAssignableFrom(clazz)) {
Type genericReturnType = controllerMethod.getGenericReturnType();
ParameterizedType t = (ParameterizedType) genericReturnType;
Type type2 = t.getActualTypeArguments()[0];
if (!(type2 instanceof Class))
throw new IllegalArgumentException("This route=" + meta + " has a method that MUST return a type 'Action' or 'XFuture<Action>' for this method(and did not)=" + controllerMethod);
@SuppressWarnings("rawtypes") Class<?> type = (Class) type2;
if (!Action.class.isAssignableFrom(type))
throw new IllegalArgumentException("This route=" + meta + " has a method that MUST return a type 'Action' or 'XFuture<Action>' not 'XFuture<" + type.getSimpleName() + ">'for this method=" + controllerMethod);
} else if (!Action.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("This route=" + meta + " has a method that MUST return a type 'Action' or 'XFuture<Action>' not '" + clazz.getSimpleName() + "' for this method=" + controllerMethod);
}
}
Aggregations