View engine

Spring MVC provides View and ViewResolver to find view and render view. MVC provides ViewEngine to do the same job.

View Engine

By default, ozark support tow built-in view engines to render JSP and Facelets, respectively.

In the org.glassfish.ozark.ext (check org.glassfish.ozark.ext) package, ozark provides several ViewEngine implementations for the popular template.

  • Thymeleaf

  • Freemarker

  • Velocity

  • Handlebars

  • Mustache

  • Asciidoc

  • Stringtemplate

  • Jade

  • JSR223(Script engine)

Facelets

Originally, Facelets is part of JSF specification, now it can be worked as a standard template engine in MVC.

  1. Activate Facelets in web.xml.

    We do not need face-config.xml file to activate JSF here.

  2. Convert all jsp files in the mvc sample to facelets template. Facelets supports Composite View pattern, we can define a template for all views.

    The template includes header and footer fragments directly, it also define a content placeholder, in the extended views the content will be inserted in the content definition.

    If you are familiar with JSF before, it is easy to understand the codes.

    Check out the codes and explore them yourself.

  3. Do not forget to change the view postfix to .xhtml in the TaskController. eg. the view in allTasks method.

Source Codes

  1. Clone the codes from my GitHub account.

    https://github.com/hantsy/ee8-sandbox/

  2. Open the mvc-facelets project in NetBeans IDE.

  3. Run it on Glassfish.

  4. After it is deployed and running on Glassfish application server, navigate http://localhost:8080/ee8-mvc/mvc/tasks in browser.

Last updated

Was this helpful?