MVC controllers
There is a new package structure reserved for MVC under javax.mvc
. The @javac.mvc.Controller
annotation declares a class type or method as a controller component. Here is an example of its use in a method:
@Controller public String greet() { return "Greetings, Earthling"; }
This controller method is missing the HTTP semantics and this is where the JAX-RS annotations help. It is also useless from an MVC perspective because there are associations with either a Model or View component.
So, first let's turn the method into a proper RESTful resource, starting with the model object:
package uk.co.xenonique.basic.mvc; import javax.enterprise.context.RequestScoped; import javax.inject.Named; @Named(value="user") @RequestScoped public class User { private String name; public User() {} public String getName() {return name; } public void setName(String name) {this.name = name; } }
The User component serves as our Model component. It has one property: the name of the person whom...