joi, 21 ianuarie 2016

9 major differences between MVC 1.0 and JAX-RS

The major differences between MVC 1.0 and JAX-RS are:

- An MVC controller is a JAX-RS resource annotated with the type/method @Controller annotation (javax.mvc.annotation.Controller).

- The @Controller can be used at type or method level. This is useful if you have a JAX-RS resource with a subset of methods that are actually MVC controllers. This is a hybrid class acting as a JAX-RS resource and as an MVC controller.

- MVC classes must be CDI-managed beans only (not JAX-RS native classes, EJBs, managed beans etc). This restrictions is true for hybrid classes also. Such classes must be CDI-managed beans.

- A String returned by an MVC controller is interpreted as a view path rather than text content (e.g. pointing a JSP page). So, pay attention to this aspect, because JAX-RS resource may return content text, while MVC controllers don't.

- The default media type for a response is assumed to be text/html, but otherwise can be declared using @Produces just like in JAX-RS.

- A MVC controller that returns void must be decorated with type/method @View annotation to indicate the view to display.

- We can encapsulates a view path as well as additional information related to its processing via the javax.mvc.Viewable class.

- The method toString() is called on other Java types and the result interpreted as a view path.

- An MVC controller that returns a non-void type may also be decorated with @View. In this case, the @View point the default view for the controller. The default view will be used ONLY if you return null from your non-void controller.

marți, 19 ianuarie 2016

How to handle LocalDate/LocalTime in MVC 1.0 (Ozark RI) (HTML5 based)

This post is a quick intro for a MVC 1.0 (Ozark RI) based application that uses Java 8, LocalDate/LocalTime in @FormParam.  The date/time are provided via HTML5 inputs and formatted using Java 8, DateTimeFormatter.
The complete application is available here.

duminică, 17 ianuarie 2016

PrimeElements + Ozark RI Rocks!

This post is a quick intro for a PrimeElements + Ozark application sample. Bascially we want to obtain in first page the left screenshot, and in the second page the right screenshot using PrimeElements for UI and Ozark for actions:

The complete example is available here. You will need GlassFish 4.1.1.

miercuri, 13 ianuarie 2016

Rapid testing MVC 1.0 (Ozark RI)

1. Use glassfish/ozark Docker image
The Docker image containing GlassFish and Ozark tests is available here. The necessary instructions are available here. The Docker image contains the tests from here.

2. Download NetBeans 8.1 from here
In order to have GlassFish 4.1.1 out of the box, you need to download Java EE bundle. After you install NetBeans bundle you can start developing Ozark applications. Do not forget to add the following two dependencies in your Maven projects:


You can also run the tests available here.

3. If you have older version of NetBeans then you need to download GlassFish 4.1.1.
The GlassFish 4.1.1 is available for download here. Nevertheless, keep in mind that in older NetBeans (previous to 8.1) there is a bug. Practically, NetBeans doesn't recognize the GlassFish 4.1.1 installation folder.

Not fan of Docker, NetBeans and GlassFish 4.1.1 ? Then there is no rapid way for the moment!