GithubHelp home page GithubHelp logo

aerogear-controller's Introduction

AeroGear Controller - very lean mvc controller

AeroGear Controller is a very lean mvc controller written in Java. It focuses on the routing of HTTP request to plain Java object endpoint and the handling of the results, by either forwarding the data to a view, or returning the data in the format requested by the caller.

Installation

  1. Add the following maven dependency

     <dependency>
         <groupId>org.jboss.aerogear</groupId>
         <artifactId>aerogear-controller</artifactId>
         <version>1.0.0.M8</version>
         <scope>compile</scope>
     </dependency>
    
  2. Since AeroGear Controller uses CDI it is required that a beans.xml file exists in the WEB-INF folder

     <beans xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
     </beans>  
    

Usage

  1. Create a pojo controller

     public class Home {
         public void index() {
         }
     }
    
  2. Create a Java class containing the routes (must extend AbstractRoutingModule)

     public class Routes extends AbstractRoutingModule {
    
     @Override
     public void configuration() {
         route()
                .from("/")
                .on(RequestMethod.GET)
                .to(Home.class).index();
         }
     }
    
  3. Create a jsp page at /WEB-INF/pages/<Controller Class Name>/<method>.jsp

     <!-- /WEB-INF/pages/Home/index.jsp -->
     <html>
         <body>
             <p>hello from index!</p>
         </body>
     </html>
    

For information about creating RESTful routes, please refer to the [user guide]((http://aergear.org/docs/guides/aerogear-controller/).

Populating parameters

You can use immutable beans straight away as controller parameters:

    public class Store {
        public Car save(Car car) {
            return car;
        }
    }

This can be populated by configuring a route to handle POST requests:

    route()
           .from("/cars")
           .on(RequestMethod.POST)
           .to(Store.class).save(param(Car.class));

And you can use a simple html form for it, by just following the convention:

        <input type="text" name="car.color"/>
        <input type="text" name="car.brand"/>

The car object will be automatically populated with the provided values - note that it supports deep linking, so this would work fine too:

        <input type="text" name="car.brand.owner"/>

All the intermediate objects are created automatically.

Documentation

Community

Issue Tracker

Examples

aerogear-controller's People

Contributors

danbev avatar josedonizetti avatar qmx avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.