Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/.idea
/gb-java-ee/.idea
/gb-java-ee/first-web-app/target
/gb-java-ee/first-jsf-app/target
8 changes: 0 additions & 8 deletions gb-java-ee/.idea/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions gb-java-ee/.idea/compiler.xml

This file was deleted.

6 changes: 0 additions & 6 deletions gb-java-ee/.idea/encodings.xml

This file was deleted.

2 changes: 0 additions & 2 deletions gb-java-ee/.idea/gb-java-ee.iml

This file was deleted.

20 changes: 0 additions & 20 deletions gb-java-ee/.idea/jarRepositories.xml

This file was deleted.

17 changes: 0 additions & 17 deletions gb-java-ee/.idea/misc.xml

This file was deleted.

39 changes: 39 additions & 0 deletions gb-java-ee/first-jsf-app/first-web-app (1).iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
</webroots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<content url="file://$MODULE_DIR$/../first-web-app/src/main/java">
<sourceFolder url="file://$MODULE_DIR$/../first-web-app/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="RUNTIME" name="Maven: mysql:mysql-connector-java:8.0.16" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.faces:javax.faces-api:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.enterprise:cdi-api:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.el:javax.el-api:3.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.interceptor:javax.interceptor-api:1.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
</component>
</module>
103 changes: 103 additions & 0 deletions gb-java-ee/first-jsf-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>first-jsf-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>first-jsf-app Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>first-jsf-app</finalName>

<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.1.Final</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ru.geekbrains.controller;

import ru.geekbrains.persist.Product;
import ru.geekbrains.persist.ProductRepository;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;

@SessionScoped
@Named
public class ProductController implements Serializable {

@Inject
private ProductRepository productRepository;

private Product product;

public Product getProduct() {
return product;
}

public void setProduct(Product product) {
this.product = product;
}

public List<Product> getAllProducts() throws SQLException {
return productRepository.findAll();
}

public Object deleteProduct(Product product) throws SQLException {
productRepository.delete(product.getId());
return "/index.xhtml?faces-redirect=true";
}

public String editProduct(Product product) {
this.product = product;
return "/product.xhtml?faces-redirect=true";
}

public String createProduct() {
this.product = new Product();
return "/product.xhtml?faces-redirect=true";
}

public String saveProduct() throws SQLException {
if (product.getId() != null) {
productRepository.update(product);
} else {
productRepository.insert(product);
}
return "/index.xhtml?faces-redirect=true";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.geekbrains.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.geekbrains.persist.Product;
import ru.geekbrains.persist.ProductRepository;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

@WebListener
public class AppBootstrapListener implements ServletContextListener {

private static final Logger logger = LoggerFactory.getLogger(AppBootstrapListener.class);
@Override
public void contextInitialized(ServletContextEvent sce) {
logger.info("Initializing app");
ServletContext sc = sce.getServletContext();

String jdbcConnectionString = sc.getInitParameter("jdbcConnectionString");
String username = sc.getInitParameter("username");
String password = sc.getInitParameter("password");

try {
Connection conn = DriverManager.getConnection(jdbcConnectionString, username, password);
sc.setAttribute("connection", conn);

// ProductRepository productRepository = new ProductRepository(conn);
// sc.setAttribute("productRepository", productRepository);

} catch (SQLException ex) {
logger.error("", ex);
}

}

@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
Connection conn = (Connection) sc.getAttribute("connection");
try {
if (conn != null && conn.isClosed()) {
conn.close();
}
} catch (SQLException ex) {
logger.error("", ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.geekbrains.persist;

import java.io.Serializable;
import java.math.BigDecimal;

public class Product implements Serializable {

private Long id;
private String name;
private String description;
private BigDecimal price;

public Product() {
}

public Product(Long id, String name, String description, BigDecimal price) {
this.id = id;
this.name = name;
this.description = description;
this.price = price;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}
}
Loading