9. Possible Variations and Extensions

9.1. Accessibility for Web Apps

The recommended approach to providing accessibility for web apps is defined by the Accessible Rich Internet Applications (ARIA) standard. As summarized by Bryan Garaventa in his article on different forms of accessibility, there are 3 main aspects of accessibility for interactive web technologies: 1) keyboard accessibility, 2) screen reader accessibility, and 3) cognitive accessibility.

Further reading on ARIA:

9.2. Using resource URLs

Whenever an app provides public information about entities, such as the books available in a public library, it is desirable to publish this information with the help of self-descriptive resource URLs, such as http://publiclibrary.norfolk.city/books/006251587X, which would be the resource URL for retrieving information about the book "Weaving the Web" available in the public library of Norfolk. However, resource URLs are not supported by JSF. In the Java world, we would have to use JAX-RS, instead of JSF, for programming a web API with resource URLs. But this would imply that we need to take care of the front-end UI in a different way, since JAX-RS is a pure back-end API, not providing any UI. A natural option would be to use a JavaScript front-end framework, such as BackboneJS or AngularJS, for rendering the UI.

9.3. Dealing with date/time information using Date and <time>

Assume that our Book model class has an additional attribute publicationDate, the values of which have to be included in HTML tables and forms. While date/time information items have to be formatted as strings in a human-readable form on web pages, preferably in a 'localized' form based on the 'locale' setting of the user's browser, it's preferable to store and manipulate date/time values in the Java code not in this form, but rather as instances of the pre-defined Java datatype class Date. For example, a date attribute publicationDate could be defined like so:

public class Book {
  ...
  private Date publicationDate;
  ...
}

For creating an HTML form input field for a Date-valued attribute, we can use the JSF element h:inputText with the attribute p:type="date". This creates an HTML input element with type="date". For our example attribute, publicationDate, the following JSF template could be used:

<h:form id="createBookForm">
  ...
  <h:inputText id="publicationDate" p:type="date"  
     value="#{book.publicationDate}">
    <f:convertDateTime pattern="yyyy-MM-dd" />
  </h:inputText>
  ...
</h:form>

With JSF one can use the built-in f:convertDateTime converter to specify an output pattern for the date format (rendered HTML output value). In the above example, we specify four digits for year representation, two digits for month and two digits for day (e.g., 2015-07-23).

From this template the following HTML code is generated:

<input id="createBookForm:publicationDate" 
  name="createBookForm:publicationDate" type="date">

Notice that the intended meaning of the HTML5 input field type "date" is for the browser to render a calendar date input widget such as a date picker. But such a rendering of date input elements is still not provided by all browsers. We therefore recommend trying this with the Chrome browser.

9.4. Using an alternative DBMS

Instead of MySQL, one can use various other database management systems for persistent storage. The following four steps are required to specify the used DBMS (only one DBMS at a time is possible):

  • configure TomEE/Tomcat so it uses the corresponding resource for your application. For a list of resource configuration examples used for common DBMS check http://tomee.apache.org/common-datasource-configurations.html. For example, if PostgreSQL was chosen as DBMS, then edit the conf/tomee.xml file (part of the TomEE installation) and add the following code:

    <Resource id="application-persistence-unit-name" type="DataSource">
      JdbcDriver   org.postgresql.Driver
      JdbcUrl  jdbc:postgresql://host/database-name
      UserName     dbms-username
      Password     user-password
    </Resource>
  • copy the jar file corresponding to the DBMS driver implementation to lib folder (part of the TomEE/Tomcat installation). After this operation, the TomEE/Tomcat server needs to be restarted.

  • Install the DBMS, if not already installed. Installation instructions are usually available on the corresponding DBMS web page.

  • create the corresponding DBMS user and database to be used for your application.