Florian Hirsch (dwins GmbH)
The reports of my death
are greatly exaggerated
— MVC
53% of mobile site visits are abandoned if pages take longer than 3 seconds to load.
time to first tweet matters!
— twitter, 2012
Option 1
Option 2
Option 3
Thanks to Libor Kramoliš
@Controller @Path("todo")
public class TodoController {
@Inject Models models;
@Inject BindingResult br;
@Inject TodoService todoService;
@POST
public String post(@Valid @BeanParam Todo todo) {
if (br.isFailed()) {
models.put("errors", br.getAllMessages());
return "todo-form.mustache";
}
todoService.add(todo);
return "redirect:todos";
}
}
@RedirectScoped
public class Messages implements Serializable {
...
}
public String get() {
return "redirect:/todos/" + id;
}
@ApplicationScoped
public class EventObserver {
private static final Logger LOG =
LoggerFactory.getLogger(EventObserver.class);
public void beforeCtrl(@Observes BeforeControllerEvent e) {
LOG.info("Resource {} will be handled by {}#{}",
e.getUriInfo().getRequestUri(),
e.getResourceInfo().getResourceClass().getName(),
e.getResourceInfo().getResourceMethod().getName());
}
}
@POST
@CsrfValid
public String post(@BeanParam Todo todo) {
...
}
<input type="hidden"
name="{{mvc.csrf.name}}" value="{{mvc.csrf.token}}" />
public interface LocaleResolver {
Locale resolveLocale(LocaleResolverContext context);
}
@FormParam("dob")
@ConvertWith(DateConverter.class)
private LocaleDate dob;
@Controller
public class TodoController {
@GET
@Path("todo/{id}")
@UriRef("todo")
public String getOne(@PathParam("id") long id) {
...
}
}
{{ mvc.uri('todo', [4711] }}
{{ mvc.uri('todo', {id: 4711} }}
{{ mvc.uri('TodoController#getOne', {id: 4711} }}
Resource-oriented client architecture
roca-style.org