JSF/EJB/JPA Exercice

The goal of this exercice is to apply the whole JPA/EJB/JSF stack to the forum web site.

Question 1

User management. A user will have four characteristics:

Question 1.1

Create the user class, as a JPA entity.

Question 1.2

Create a stateless bean, called UserService, which will provide CRUD (Create/Retrive/Update/Delete) facilities for the User class.

Question 1.3

Write a ManagedBean and JSF page(s) to create a new user. At this point, user creation will be possible for anyone.

Question 1.4

Write the code (JSF and bean) to list all users.

Question 1.5

Write the code to edit an existing user.

Question 1.6

Manage user connection using a stateful bean, UserConnectionBean. You will write a login form (and corresponding JSF file). The UserConnectionBean bean will be filled with a user login and group if and only if the user connect with the right login and password.

Question 1.7

Update the existing code to implement the following behaviour:
  1. Anyone can create a user if there is no user at all.
  2. Only a admin user can create a new user
  3. A user data can be updated only by an admin and by himself.
  4. A normal user can't change his own group (only admin can do this).
  5. Only admin can list users
  6. When changing groups, or deleting users, the system must ensure there is always at least one admin user.

Question 1.8

Modify the listing of users so that the admin has delete, view and edit buttons for each user.

Question 2

Message management. A message has the following characteristics

Question 2.1

Create the corresponding JPA entity. Add the following functions to your web site:
  1. Message creation (only connected users can create messages)
  2. Message listing
  3. Message deletion (only admin and message author can delete a message)
  4. Message edition (only admin and message author can edit a message)
  5. A search page, which will return all message whose content or title contains a certain text.

Question 2.2

Add Ajax behaviour to your search page. As soon as the user has typed text, we want to display the list of corresponding messages.

Question 2.3

Add pagination to the message list page. At most ten messages titles should be displayed on a page. The page must then have a "previous" and "next" button. For the implementation, you can compute the list of all messages, sorted by id (search the web of how to do this in jpql), and send back only a part of this list.

Question 3

Now, messages can have comments. Comments have content, author, a date, but no title. A comment is linked to a message (not to another comment).

Add the code to add comments to messages, and change the message display page so that:

  1. it's possible to add a comment to a message (only if one is connected)
  2. comments are displayed below the message.