Skip to content

Commit

Permalink
change JSF view and its backed bean to be stateless for database inte…
Browse files Browse the repository at this point in the history
…gration guide
  • Loading branch information
majguo committed Oct 12, 2020
1 parent a1b73b7 commit 7041439
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Named;
Expand All @@ -28,7 +28,7 @@
import cafe.model.entity.Coffee;

@Named
@SessionScoped
@RequestScoped
public class Cafe implements Serializable {

private static final long serialVersionUID = 1L;
Expand Down
2 changes: 2 additions & 0 deletions 3-integration/connect-db/mssql/src/main/webapp/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:fc="http://xmlns.jcp.org/jsf/composite/components">
<f:view transient="true">
<h:head>
<title>Java EE Cafe</title>
<link rel="stylesheet"
Expand Down Expand Up @@ -71,4 +72,5 @@
</div>
</h:form>
</h:body>
</f:view>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Named;
Expand All @@ -28,7 +28,7 @@
import cafe.model.entity.Coffee;

@Named
@SessionScoped
@RequestScoped
public class Cafe implements Serializable {

private static final long serialVersionUID = 1L;
Expand Down
2 changes: 2 additions & 0 deletions 3-integration/connect-db/postgres/src/main/webapp/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:fc="http://xmlns.jcp.org/jsf/composite/components">
<f:view transient="true">
<h:head>
<title>Java EE Cafe</title>
<link rel="stylesheet"
Expand Down Expand Up @@ -71,4 +72,5 @@
</div>
</h:form>
</h:body>
</f:view>
</html>
4 changes: 4 additions & 0 deletions guides/howto-integrate-azure-managed-databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The application `<path-to-repo>/2-simple` used in the [previous guide](howto-dep
| `persistence.xml` | | [`<path-to-repo>/3-integration/connect-db/mssql/src/main/resources/META-INF/persistence.xml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/mssql/src/main/resources/META-INF/persistence.xml) | New | A configuration file specifying data persistence schema for your application. |
| `Coffee.java` | [`<path-to-repo>/2-simple/src/main/java/cafe/model/entity/Coffee.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/java/cafe/model/entity/Coffee.java) | [`<path-to-repo>/3-integration/connect-db/mssql/src/main/java/cafe/model/entity/Coffee.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/mssql/src/main/java/cafe/model/entity/Coffee.java) | Updated | Register `Coffee` class as a JPA Entity. |
| `CafeRepository.java` | [`<path-to-repo>/2-simple/src/main/java/cafe/model/CafeRepository.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/java/cafe/model/CafeRepository.java) | [`<path-to-repo>/3-integration/connect-db/mssql/src/main/java/cafe/model/CafeRepository.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/mssql/src/main/java/cafe/model/CafeRepository.java) | Updated | Register `CafeRepository` class as a Stateless Bean which implements CRUD operations using `javax.persistence.EntityManager` and `javax.persistence.PersistenceContext` APIs. |
| `Cafe.java` | [`<path-to-repo>/2-simple/src/mainjava/cafe/web/view/Cafe.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/java/cafe/web/view/Cafe.java) | [`<path-to-repo>/3-integration/connect-db/mssql/src/main/java/cafe/web/view/Cafe.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/mssql/src/main/java/cafe/web/view/Cafe.java) | Updated | Change bean life cycle from `SessionScoped` to `RequestScoped` to make it stateless. |
| `index.xhtml` | [`<path-to-repo>/2-simple/src/main/webapp/index.xhtml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/webapp/index.xhtml) | [`<path-to-repo>/3-integration/connect-db/mssql/src/main/webapp/index.xhtml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/mssql/src/main/webapp/index.xhtml) | Updated | Add `<f:view transient="true">` to make a stateless view. |
| `pom.xml` | [`<path-to-repo>/2-simple/pom.xml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/pom.xml) | [`<path-to-repo>/3-integration/connect-db/mssql/pom.xml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/mssql/pom.xml) | Updated | Add new properties and dependencies for database connection, and add new plugin `maven-dependency-plugin`. |

For reference, these changes have already been applied in `<path-to-repo>/3-integration/connect-db/mssql` of your local clone.
Expand Down Expand Up @@ -203,6 +205,8 @@ The application `<path-to-repo>/2-simple` used in the [previous guide](howto-dep
| `persistence.xml` | | [`<path-to-repo>/3-integration/connect-db/postgres/src/main/resources/META-INF/persistence.xml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/postgres/src/main/resources/META-INF/persistence.xml) | New | A configuration file specifying data persistence schema for your application. |
| `Coffee.java` | [`<path-to-repo>/2-simple/src/main/java/cafe/model/entity/Coffee.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/java/cafe/model/entity/Coffee.java) | [`<path-to-repo>/3-integration/connect-db/postgres/src/main/java/cafe/model/entity/Coffee.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/postgres/src/main/java/cafe/model/entity/Coffee.java) | Updated | Register `Coffee` class as a JPA Entity. |
| `CafeRepository.java` | [`<path-to-repo>/2-simple/src/main/java/cafe/model/CafeRepository.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/java/cafe/model/CafeRepository.java) | [`<path-to-repo>/3-integration/connect-db/postgres/src/main/java/cafe/model/CafeRepository.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/postgres/src/main/java/cafe/model/CafeRepository.java) | Updated | Register `CafeRepository` class as a Stateless Bean which implements CRUD operations using `javax.persistence.EntityManager` and `javax.persistence.PersistenceContext` APIs. |
| `Cafe.java` | [`<path-to-repo>/2-simple/src/mainjava/cafe/web/view/Cafe.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/java/cafe/web/view/Cafe.java) | [`<path-to-repo>/3-integration/connect-db/postgres/src/main/java/cafe/web/view/Cafe.java`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/postgres/src/main/java/cafe/web/view/Cafe.java) | Updated | Change bean life cycle from `SessionScoped` to `RequestScoped` to make it stateless. |
| `index.xhtml` | [`<path-to-repo>/2-simple/src/main/webapp/index.xhtml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/src/main/webapp/index.xhtml) | [`<path-to-repo>/3-integration/connect-db/postgres/src/main/webapp/index.xhtml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/postgres/src/main/webapp/index.xhtml) | Updated | Add `<f:view transient="true">` to make a stateless view. |
| `pom.xml` | [`<path-to-repo>/2-simple/pom.xml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/2-simple/pom.xml) | [`<path-to-repo>/3-integration/connect-db/postgres/pom.xml`](https://github.com/Azure-Samples/open-liberty-on-aro/blob/master/3-integration/connect-db/postgres/pom.xml) | Updated | Add new properties and dependencies for database connection, and add new plugin `maven-dependency-plugin`. |

For reference, these changes have already been applied in `<path-to-repo>/3-integration/connect-db/postgres` of your local clone.
Expand Down

0 comments on commit 7041439

Please sign in to comment.