javax.mvc.Controller Java Examples
The following examples show how to use
javax.mvc.Controller.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KrazoContainerInitializer.java From krazo with Apache License 2.0 | 6 votes |
@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { if (classes == null || classes.isEmpty()) { return; } LOG.log(Level.INFO, "Eclipse Krazo version {0} started", getClass().getPackage().getImplementationVersion()); Set<Class> controllerClasses = new LinkedHashSet<>(); for (Class<?> clazz : classes) { // collect all controllers if (AnnotationUtils.hasAnnotationOnClassOrMethod(clazz, Path.class) && AnnotationUtils.hasAnnotationOnClassOrMethod(clazz, Controller.class)) { controllerClasses.add(clazz); } } servletContext.setAttribute(CONTROLLER_CLASSES, Collections.unmodifiableSet(controllerClasses)); }
Example #2
Source File: OzarkContainerInitializer.java From ozark with Apache License 2.0 | 6 votes |
@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { if (classes == null || classes.isEmpty()) { return; } LOG.log(Level.INFO, "Ozark version {0} started", getClass().getPackage().getImplementationVersion()); Set<Class> controllerClasses = new LinkedHashSet<>(); for (Class<?> clazz : classes) { // collect all controllers if (AnnotationUtils.hasAnnotationOnClassOrMethod(clazz, Path.class) && AnnotationUtils.hasAnnotationOnClassOrMethod(clazz, Controller.class)) { controllerClasses.add(clazz); } } servletContext.setAttribute(CONTROLLER_CLASSES, Collections.unmodifiableSet(controllerClasses)); }
Example #3
Source File: BookController.java From ozark with Apache License 2.0 | 5 votes |
/** * MVC controller to render a book in HTML. Uses the models map to * bind a book instance. * * @param id ID of the book given in URI. * @return JSP page used for rendering. */ @GET @Controller @Produces("text/html") @Path("view1/{id}") public String view1(@PathParam("id") String id) { models.put("book", catalog.getBook(id)); return "book.xhtml"; }
Example #4
Source File: OzarkModelProcessor.java From ozark with Apache License 2.0 | 5 votes |
/** * Determines if a resource is a controller. * * @param resource resource to test. * @return outcome of controller test. */ private static boolean isController(Resource resource) { final Boolean b1 = resource.getHandlerClasses().stream() .map(c -> c.isAnnotationPresent(Controller.class)) .reduce(Boolean.FALSE, Boolean::logicalOr); final Boolean b2 = resource.getHandlerInstances().stream() .map(o -> o.getClass().isAnnotationPresent(Controller.class)) .reduce(Boolean.FALSE, Boolean::logicalOr); return b1 || b2; }
Example #5
Source File: ConversationController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @Path("stop") public String stopConversation() { bean.endConversation(); return "stop.jsp"; }
Example #6
Source File: ConversationController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @Path("tellme") public String tellme() { return "tellme.jsp"; }
Example #7
Source File: JythonController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("index.py") public void index(@QueryParam("name") String name) { models.put("name", name); }
Example #8
Source File: GroovyController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("index.groovy") public void index(@QueryParam("name") String name) { models.put("name", name); }
Example #9
Source File: HelloController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.adoc") public void hello(@QueryParam("user") String user) { models.put("user", user); }
Example #10
Source File: HelloController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.st") public void hello(@QueryParam("user") String user) { models.put("user", user); }
Example #11
Source File: HelloController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.vm") @Path("v1") public void hello(@QueryParam("user") String user) { models.put("user", user); }
Example #12
Source File: HelloController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello2.vhtml") @Path("v2") public void hello2(@QueryParam("user2") String user2) { models.put("user2", user2); }
Example #13
Source File: HelloController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.jetx") public void hello(@QueryParam("user") String user) { models.put("user", user); }
Example #14
Source File: OzarkValidationInterceptor.java From ozark with Apache License 2.0 | 5 votes |
/** * For some weird reason we cannot preserve the <code>throws ConstraintViolationException</code> * in the method signature. Bundling Ozark as a Glassfish plugin starts failing as soon as * this class uses any interface from the javax.validation package. My current guess is * that this is related to the OSGi bundling. */ @Override public void onValidate(ValidationInterceptorContext context) { /* * TODO: Won't work correctly for mixed controller/resource methods. */ Class<?> resourceClass = context.getResource().getClass(); boolean mvcRequest = AnnotationUtils.hasAnnotationOnClassOrMethod(resourceClass, Controller.class); if (!mvcRequest) { context.proceed(); } }
Example #15
Source File: NashornController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("index.js") public void index(@QueryParam("name") String name) { models.put("name", name); }
Example #16
Source File: FormController.java From ozark with Apache License 2.0 | 5 votes |
@POST @Controller public Response formPost(@Valid @BeanParam FormDataBean form) { if (br.isFailed()) { ValidationError validationError = (ValidationError) br.getAllErrors().iterator().next(); final ConstraintViolation<?> cv = validationError.getViolation(); final String property = cv.getPropertyPath().toString(); error.setProperty(property.substring(property.lastIndexOf('.') + 1)); error.setValue(cv.getInvalidValue()); error.setMessage(cv.getMessage()); error.setParam(validationError.getParamName()); return Response.status(BAD_REQUEST).entity("error.jsp").build(); } return Response.status(OK).entity("data.jsp").build(); }
Example #17
Source File: JadeController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Path("/markdown") @Controller @View("markdown.jade") public void getMarkdownd(@QueryParam("article") String article) { models.put("pageName", "Markdown Introduction"); }
Example #18
Source File: FormController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Controller public Response get(@QueryParam("n") @DefaultValue("25") int n) { if (br.isFailed()) { final ParamError be = br.getErrors("n").iterator().next(); error.setProperty(be.getParamName()); error.setMessage(be.getMessage()); return Response.ok("binderror.jsp").build(); } return Response.ok(Integer.toString(n)).build(); }
Example #19
Source File: JadeController.java From ozark with Apache License 2.0 | 5 votes |
@GET @Path("/helper") @Controller @View("helper.jade") public void getCofig() { models.put("pageName", "Helper"); }
Example #20
Source File: AnnotationUtilsTest.java From krazo with Apache License 2.0 | 5 votes |
@Test public void getAnnotation() { Path path = AnnotationUtils.getAnnotation(someController.getClass(), Path.class); assertThat(path.value(), is("start")); Named named = AnnotationUtils.getAnnotation(someBean.getClass(), Named.class); assertThat(named.value(), is("someBean")); assertThat(AnnotationUtils.getAnnotation(BaseController.class, Controller.class), is(notNullValue())); // inheritance of class or interface annotations is not supported assertThat(AnnotationUtils.getAnnotation(InheritedController.class, Controller.class), is(nullValue())); assertThat(AnnotationUtils.getAnnotation(ControllerImpl.class, Controller.class), is(nullValue())); }
Example #21
Source File: KrazoCdiExtension.java From krazo with Apache License 2.0 | 5 votes |
/** * Search for {@link Controller} annotation and patch AnnotatedType. * Note: PLATFORM_AFTER is required so we execute AFTER the Hibernate Validator Extension */ public <T> void processAnnotatedType( @Observes @Priority(Interceptor.Priority.PLATFORM_AFTER) @WithAnnotations({Controller.class}) ProcessAnnotatedType<T> pat) { AnnotatedType<T> replacement = annotatedTypeProcessor.getReplacement(pat.getAnnotatedType()); if (replacement != null) { log.log(Level.FINE, "Replacing AnnotatedType of class: {0}", replacement.getJavaClass().getName()); pat.setAnnotatedType(replacement); } }
Example #22
Source File: KrazoModelProcessor.java From krazo with Apache License 2.0 | 5 votes |
/** * Determines if a resource is a controller. * * @param resource resource to test. * @return outcome of controller test. */ private static boolean isController(Resource resource) { final Boolean b1 = resource.getHandlerClasses().stream() .map(c -> c.isAnnotationPresent(Controller.class)) .reduce(Boolean.FALSE, Boolean::logicalOr); final Boolean b2 = resource.getHandlerInstances().stream() .map(o -> o.getClass().isAnnotationPresent(Controller.class)) .reduce(Boolean.FALSE, Boolean::logicalOr); return b1 || b2; }
Example #23
Source File: KrazoValidationInterceptor.java From krazo with Apache License 2.0 | 5 votes |
/** * For some weird reason we cannot preserve the <code>throws ConstraintViolationException</code> * in the method signature. Bundling Krazo as a Glassfish plugin starts failing as soon as * this class uses any interface from the javax.validation package. My current guess is * that this is related to the OSGi bundling. */ @Override public void onValidate(ValidationInterceptorContext context) { /* * TODO: Won't work correctly for mixed controller/resource methods. */ Class<?> resourceClass = context.getResource().getClass(); boolean mvcRequest = AnnotationUtils.hasAnnotationOnClassOrMethod(resourceClass, Controller.class); if (!mvcRequest) { context.proceed(); } }
Example #24
Source File: JadeController.java From krazo with Apache License 2.0 | 5 votes |
@GET @Path("/helper") @Controller @View("helper.jade") public void getCofig() { models.put("pageName", "Helper"); }
Example #25
Source File: BookController.java From ozark with Apache License 2.0 | 5 votes |
/** * MVC controller to render a book in HTML. Uses the models map to * bind a book instance and @View to specify path to view. * * @param id ID of the book given in URI. */ @GET @Controller @Produces("text/html") @Path("view2/{id}") @View("book.jsp") public void view2(@PathParam("id") String id) { final Book book = new Book(); book.setId(id); book.setAuthor("Some author"); book.setTitle("Some title"); book.setIsbn("Some ISBN"); models.put("book", book); }
Example #26
Source File: JadeController.java From krazo with Apache License 2.0 | 5 votes |
@GET @Path("/markdown") @Controller @View("markdown.jade") public void getMarkdownd(@QueryParam("article") String article) { models.put("pageName", "Markdown Introduction"); }
Example #27
Source File: JadeController.java From krazo with Apache License 2.0 | 5 votes |
@GET @Controller @View("main.jade") public void get(@QueryParam("user") String user) { models.put("user", user); models.put("pageName", "Hello Jade"); }
Example #28
Source File: HelloController.java From krazo with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.mustache") public void hello(@QueryParam("user") String user) { models.put("user", user); }
Example #29
Source File: HelloController.java From krazo with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.jetx") public void hello(@QueryParam("user") String user) { models.put("user", user); }
Example #30
Source File: HelloController.java From krazo with Apache License 2.0 | 5 votes |
@GET @Controller @Produces("text/html") @View("hello.html") public void hello(@QueryParam("user") String user) { greeting.setUser(user); }