This sample is a single WAR module that provides two user interface views.
- An online polling view that displays a question, a list of answers to choose from, and current voting results.
- An administration view that provides options for voting data to be initialized (empty, default seed data, or from the database if it has been populated). The administration view is always shown on startup, to allow an initialization preference to be set. It can always be returned to by clicking the "Admin" button from the online polling view.
This sample demonstrates the technologies of packaging an EJB in a WAR, Contexts and Dependency Injection (CDI), and Java Persistence API (JPA). The application consists of a servlet, stateless session bean, a JSP, two JPA entities, and an interceptor. The servlet uses CDI annotations to inject the stateless session bean, and then call various business methods declared by the bean. The stateless session bean (PollBean) uses a JPA EntityManager to perform queries and updates to the database. Before the bean populates the database, the interceptor (PollInterceptorImpl) uses a JPA EntityManager to clear the database. Finally, the servlet includes a small JSP to demonstrate CDI, by referencing the stateless session bean from within an EL expression to generate output.
This sample can be installed onto runtime versions 22.214.171.124 and later.
Online installation (requires 126.96.36.199 or later):
- Install the sample by running the command below from the bin directory of your server installation:
installUtility install OnlinePollingSample
Any missing features required by the server will be installed for you.
- Download the
OnlinePollingSample.jar using the download button at the top of the page and place it in the root of your server installation.
- Extract the sample into the Liberty installation by running the command below from the root of your server installation:
java -jar OnlinePollingSample.jar
Any missing features required by the server will need to be installed separately.
OnlinePollingSampleWeb.war file contains the source and binaries for the application, and can be used to import it to Eclipse.
This sample does not include the open source dependencies. The installer will provide a list of the open source pre-requisite libraries and where they can be downloaded from. To help obtaining these libraries, the installer provides the option to download them on your behalf.