This post is a quick intro for a PrimeNG +JAX-RS application sample. Bascially we want to obtain the below result:
The complete example is available here. You will need a server that supports Java EE 7.
miercuri, 2 martie 2016
duminică, 28 februarie 2016
PrimeNG + MVC 1.0 (Ozark RI)
This post is a quick intro for a PrimeNG + MVC 1.0 (Ozark RI) application sample. Bascially we want to obtain the below result:
luni, 8 februarie 2016
Specifying the controller’s method return type (part I)
The controller's method return type can be void, String, Viewable Java
type and Response:
·
void - such controller method must be decorated by @View
·
String - the returned String will be interpreted as a path
·
Viewable - encapsulates a view path as well as
additional information related to its processing
·
Java Type - the method toString() is called on other
Java types and the result interpreted as a view path
·
Response - A JAX-RS Response whose entity’s type is one of the above
Void and String Examples
In the simplest example we return a String
(path) from a controller method, so in this section we will focus more on returning
void, using @View
and exposing the interaction cases between @View and String returning. Let's suppose that we have a simple controller
with a single method that returns void. In such case we need to annotate the method with
@View("path"), as below:
// the helloVoidAction()
will return the hello.html thanks to @View
@Controller
@Path("hello")
public class
HelloController {
@GET
@View("hello.html")
public void helloVoidAction() {
// NOPE
}
}
In the above example, we can achieve the same behavior
by annotating the class with @View. If all the methods of a controller return void
then the @View
from class level will point out the same returned view for all methods.
Further, let's suppose that we have a controller with @View at class level and with different
kind of methods, as follows (notice how the returned path is computed based on certain
priorities: the String returned by a method has the highest priority, while the @View at class
level has the smallest priority):
·
by default, the controller will always return bye.html
@Controller
@Path("bye")
@View("bye.html")
public class ByeController {
...
}
·
method that uses @View at class level (returns the bye.html)
@GET
@Path("forever")
public void byeVoidAction() {
//
NOPE
}
·
method that override the @View from class level with @View at
method level (returns the seeyou.html)
@GET
@Path("wasbye")
@View("seeyou.html")
public void wasForeverVoidAction() {
//
NOPE
}
·
method that override @View from method level by
returning a String
(path) (returns the bye.html)
@GET
@Path("stillbye")
@View("seeyou.html")
public String stillByeStringAction() {
return "bye.html";
}
·
method that returns null will use @View from
class level (returns the bye.html)
@GET
@Path("nullbye")
public String nullByeStringAction() {
return
null;
}
·
method that returns null will use @View from method
level (returns the seeyou.html)
@GET
@Path("nullseeyou")
@View("seeyou.html")
public String nullSeeyouStringAction() {
return
null;
}
·
method that returns String (path) overrides @View from class
level (returns the seeyou.html)
@GET
@Path("fornow")
public String seeyouStringAction() {
return "seeyou.html";
}
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:
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:
<dependency>
<groupId>org.glassfish.ozark</groupId>
<artifactId>ozark</artifactId>
<version>1.0.0-m02</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.mvc</groupId>
<artifactId>javax.mvc-api</artifactId>
<version>1.0-edr2</version>
<type>jar</type>
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!
Abonați-vă la:
Postări (Atom)




