Search in sources :

Example 1 with Render

use of org.webpieces.router.api.controller.actions.Render in project webpieces by deanhiller.

the class CrudTestController method multiSelect.

public Render multiSelect(Integer id) {
    if (id == null) {
        return Actions.renderThis("entity", new UserTestDbo(), "levels", LevelEducation.values(), "roles", Role.values(), "selectedRoles", new ArrayList<>());
    }
    UserTestDbo user = UserTestDbo.findWithJoin(Em.get(), id);
    List<UserRoleDbo> roles = user.getRoles();
    List<Role> selectedRoles = roles.stream().map(r -> r.getRole()).collect(Collectors.toList());
    return Actions.renderThis("entity", user, "levels", LevelEducation.values(), "roles", Role.values(), "selectedRoles", selectedRoles, "password", null);
}
Also used : Role(org.webpieces.plugins.hibernate.app.dbo.Role) Logger(org.slf4j.Logger) Render(org.webpieces.router.api.controller.actions.Render) EDIT_USER_PAGE(org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE) FlashAndRedirect(org.webpieces.router.api.controller.actions.FlashAndRedirect) LoggerFactory(org.slf4j.LoggerFactory) EntityManager(javax.persistence.EntityManager) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Role(org.webpieces.plugins.hibernate.app.dbo.Role) ArrayList(java.util.ArrayList) ADD_USER_PAGE(org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE) List(java.util.List) Query(javax.persistence.Query) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo) LevelEducation(org.webpieces.plugins.hibernate.app.dbo.LevelEducation) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) Em(org.webpieces.plugin.hibernate.Em) Redirect(org.webpieces.router.api.controller.actions.Redirect) Current(org.webpieces.ctx.api.Current) Actions(org.webpieces.router.api.controller.actions.Actions) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)

Example 2 with Render

use of org.webpieces.router.api.controller.actions.Render in project webpieces by deanhiller.

the class ControllerLoader method preconditionCheckForErrorRoute.

private void preconditionCheckForErrorRoute(LoadedController loadedController) {
    Method controllerMethod = loadedController.getControllerMethod();
    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 error route has a method that MUST return a type 'Render' or 'XFuture<Render>' " + "for this method(and did not)=" + controllerMethod);
        @SuppressWarnings("rawtypes") Class<?> type = (Class) type2;
        if (!Render.class.isAssignableFrom(type))
            throw new IllegalArgumentException("This error route has a method that MUST return a type 'Render' or 'XFuture<Render>' not 'XFuture<" + type.getSimpleName() + ">'for this method=" + controllerMethod);
    } else if (!Render.class.isAssignableFrom(clazz))
        throw new IllegalArgumentException("This error route has a method that MUST return a type 'Render' or 'XFuture<Render>' not '" + clazz.getSimpleName() + "' for this method=" + controllerMethod);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Render(org.webpieces.router.api.controller.actions.Render) Method(java.lang.reflect.Method)

Aggregations

Render (org.webpieces.router.api.controller.actions.Render)2 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Current (org.webpieces.ctx.api.Current)1 Em (org.webpieces.plugin.hibernate.Em)1 ADD_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE)1 EDIT_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE)1 LevelEducation (org.webpieces.plugins.hibernate.app.dbo.LevelEducation)1 Role (org.webpieces.plugins.hibernate.app.dbo.Role)1 UserRoleDbo (org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)1 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)1