New file |
| | |
| | | .classpath |
| | | .project |
| | | .tern-project |
| | | .settings |
| | | target |
New file |
| | |
| | | # JB125 Java EE 7 Hello World web App |
| | | |
| | | ##This app is composed of the following architecture: |
| | | |
| | | * Maven Project - builds a WAR |
| | | * Using JSF 2.2 for web interface, HTML5 facelets page, JSF backing beans, CDI scopes on beans, @Named |
| | | * Statelss EJB for services - uses JPA entity beans - exposes appropriate method as REST API using JAX-RS annotations |
| | | * JAX-RS Application class |
| | | * JPA entity bean to store names - uses H2 in-memory database |
| | | * Use EJB Singleton to lookup messaging connection and queue destination and inject into stateless EJB - lookup should only occur once on startup |
| | | * Servlet that returns "OK" - this is a health check - path should be [context]/health |
| | | * H2 (embedded in-memory DB) backend |
New file |
| | |
| | | USE todo; |
| | | DROP TABLE IF EXISTS `Person`; |
| | | CREATE TABLE `Person` (`id` BIGINT not null auto_increment primary key, `name` VARCHAR(40)); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (1,'John'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (2,'Steve'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (3,'Mark'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (4,'Nick'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (5,'Nita'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (6,'John'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (7,'Julia'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (8,'Joe'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (9,'Nita'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (10,'Branden'); |
| | | |
New file |
| | |
| | | <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> |
| | | <artifactId>create-queries</artifactId> |
| | | <packaging>war</packaging> |
| | | <name>Create Queries web app Project</name> |
| | | <description>This is the create-queries project</description> |
| | | <parent> |
| | | <groupId>com.redhat.training</groupId> |
| | | <artifactId>parent-pom</artifactId> |
| | | <version>1.0</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- First declare the APIs we depend on and need for compilation. All |
| | | of them are provided by JBoss EAP --> |
| | | |
| | | <!-- Import the CDI API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>javax.enterprise</groupId> |
| | | <artifactId>cdi-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the Common Annotations API (JSR-250), we use provided scope |
| | | as the API is included in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.annotation</groupId> |
| | | <artifactId>jboss-annotations-api_1.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JAX-RS API, we use provided scope as the API is included |
| | | in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ws.rs</groupId> |
| | | <artifactId>jboss-jaxrs-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JPA API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate.javax.persistence</groupId> |
| | | <artifactId>hibernate-jpa-2.1-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the EJB API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ejb</groupId> |
| | | <artifactId>jboss-ejb-api_3.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.jms</groupId> |
| | | <artifactId>jboss-jms-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Bean Validation Implementation --> |
| | | <!-- Provides portable constraints such as @Email --> |
| | | <!-- Hibernate Validator is shipped in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator</artifactId> |
| | | <scope>provided</scope> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>slf4j-api</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-search-orm</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-entitymanager</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JSF API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.faces</groupId> |
| | | <artifactId>jboss-jsf-api_2.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.servlet</groupId> |
| | | <artifactId>jboss-servlet-api_3.1_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor to generate the JPA metamodel classes for |
| | | typesafe criteria queries --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-jpamodelgen</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor that raising compilation errors whenever constraint |
| | | annotations are incorrectly used. --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator-annotation-processor</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>create-queries</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>${version.war.plugin}</version> |
| | | <extensions>false</extensions> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <archive> |
| | | <manifestEntries> |
| | | <Dependencies>com.google.guava,org.slf4j |
| | | </Dependencies> |
| | | </manifestEntries> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.NamedQuery; |
| | | |
| | | @Entity |
| | | //add named query here |
| | | |
| | | public class Person{ |
| | | @Id |
| | | private Long id; |
| | | |
| | | private String name; |
| | | |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | Person other = (Person) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.services; |
| | | |
| | | import java.util.List; |
| | | |
| | | import javax.ejb.Stateless; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.PersistenceContext; |
| | | import javax.persistence.TypedQuery; |
| | | import javax.persistence.Query; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | |
| | | @Stateless |
| | | |
| | | public class PersonService { |
| | | |
| | | @PersistenceContext(unitName="hello") |
| | | private EntityManager entityManager; |
| | | |
| | | // Get all Person objects in the Database |
| | | |
| | | //Get persons whose name matches the name given in the query |
| | | |
| | | } |
New file |
| | |
| | | /* |
| | | * JBoss, Home of Professional Open Source |
| | | * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual |
| | | * contributors by the @authors tag. See the copyright.txt in the |
| | | * distribution for a full listing of individual contributors. |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.redhat.training.servlet; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.annotation.WebServlet; |
| | | import javax.servlet.http.HttpServlet; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * <p> |
| | | * A simple servlet taking advantage of features added in 3.0. |
| | | * </p> |
| | | * |
| | | * <p> |
| | | * The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet |
| | | * @HttpServlet}. |
| | | * </p> |
| | | * |
| | | * @author Pete Muir |
| | | * |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | @WebServlet("/health") |
| | | public class PingServlet extends HttpServlet { |
| | | |
| | | static String PAGE_HEADER = "<html><head><title>Ping Servlet</title></head><body>"; |
| | | |
| | | static String PAGE_FOOTER = "</body></html>"; |
| | | |
| | | @Override |
| | | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| | | resp.setContentType("text/html"); |
| | | PrintWriter writer = resp.getWriter(); |
| | | writer.println(PAGE_HEADER); |
| | | writer.println("<h1>OK.</h1>"); |
| | | writer.println("It is now " + new java.util.Date().toString() + " at the server."); |
| | | writer.println(PAGE_FOOTER); |
| | | writer.close(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | import javax.enterprise.context.RequestScoped; |
| | | import javax.inject.Named; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | import com.redhat.training.services.PersonService; |
| | | |
| | | import javax.inject.Inject; |
| | | import java.util.List; |
| | | |
| | | |
| | | |
| | | @RequestScoped |
| | | @Named("hello") |
| | | public class Hello { |
| | | private String name; |
| | | private Long id; |
| | | private List<Person> results; |
| | | |
| | | @Inject |
| | | private PersonService personService; |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | //View all persons in the database table |
| | | /*public List<Person> getPersons() { |
| | | return personService.getAllPersons(); |
| | | }*/ |
| | | |
| | | //view all persons whose name matches the name given in the query |
| | | /*public void search() { |
| | | results = personService.getPersonsWithName(name); |
| | | }*/ |
| | | |
| | | public List<Person> getResults() { |
| | | return results; |
| | | } |
| | | |
| | | public void setResults(List<Person> results) { |
| | | this.results = results; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <persistence version="2.1" |
| | | xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> |
| | | <persistence-unit name="hello" transaction-type="JTA"> |
| | | <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source> |
| | | <properties> |
| | | <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> |
| | | <property name="hibernate.hbm2ddl.auto" value="create-drop" /> |
| | | <property name="hibernate.show_sql" value="true" /> |
| | | <property name="hibernate.format_sql" value="true" /> |
| | | </properties> |
| | | </persistence-unit> |
| | | </persistence> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file can be an empty text file (0 bytes) --> |
| | | <!-- We're declaring the schema to save you time if you do have to configure |
| | | this in the future --> |
| | | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| | | </beans> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file is not required if you don't need any extra configuration. --> |
| | | <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
| | | |
| | | <!-- This descriptor activates the JSF 2.0 Servlet --> |
| | | |
| | | <!-- Write your navigation rules here. You are encouraged to use CDI |
| | | for creating @Named managed beans. --> |
| | | |
| | | </faces-config> |
New file |
| | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets"> |
| | | <h:head> |
| | | <title><ui:insert name="title"> |
| | | [Title will be inserted here] |
| | | </ui:insert> |
| | | </title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <h:outputStylesheet name="css/screen.css" /> |
| | | </h:head> |
| | | <h:body> |
| | | |
| | | <header> |
| | | <h:graphicImage name="images/redhat.png" /> |
| | | <div class="right"> |
| | | Application: |
| | | <ui:insert name="application_name"> |
| | | [Application name will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | </header> |
| | | <div id="content"> |
| | | <ui:insert name="content"> |
| | | [Template content will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | <footer> |
| | | JB183 - Enterprise Java Development - Red Hat Training |
| | | </footer> |
| | | </h:body> |
| | | </html> |
New file |
| | |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- Plain HTML page that kicks us into the app --> |
| | | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Refresh" content="0; URL=index.jsf"> |
| | | </head> |
| | | </html> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Create Queries Web Application |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Create Queries Web Application |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Create Queries</h1> |
| | | <br class="clear"/> |
| | | <h:form id="form"> |
| | | <br class="clear"/> |
| | | <h1> |
| | | <a href="/create-queries/viewPersons.xhtml">View All Users</a> |
| | | <br/> |
| | | <a href="/create-queries/viewPerson.xhtml">Search Users</a> |
| | | </h1> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | body { |
| | | |
| | | } |
| | | |
| | | header { |
| | | background-color: #C40016; |
| | | height: 150px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | border: 4px solid #000000; |
| | | } |
| | | |
| | | header .right { |
| | | display: inline-block; |
| | | float: right; |
| | | font-size: 40px; |
| | | font-weight: bolder; |
| | | height: 150px; |
| | | padding: 48px; |
| | | vertical-align: middle; |
| | | } |
| | | |
| | | #content { |
| | | background-color: #F2F2F2; |
| | | width: 91%; |
| | | margin: 0 auto; |
| | | padding: 100px 50px; |
| | | border: 2px solid #000000; |
| | | } |
| | | |
| | | footer { |
| | | border: 4px solid #000000; |
| | | background-color: #C40016; |
| | | height: 30px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | text-align: center; |
| | | font-weight: bolder; |
| | | font-size: 27px; |
| | | } |
| | | |
| | | label{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
| | | input { |
| | | display: inline-block; |
| | | float: left; |
| | | width: 362px; |
| | | } |
| | | select{ |
| | | display: inline-block; |
| | | float: left; |
| | | width: 371px; |
| | | } |
| | | textarea{ |
| | | display: inline-block; |
| | | float: left; |
| | | } |
| | | |
| | | .clear{ |
| | | clear: both; |
| | | } |
| | | |
| | | .messages{ |
| | | color: green; |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .btn{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Search Users</h1> |
| | | <br class="clear"/> |
| | | <h:form id="viewform"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Name:" for="name" /> |
| | | <h:inputText value="#{hello.name}" id="name" required="true" requiredMessage="Name is required"/> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p class="input"> |
| | | <h:commandButton action="#{hello.search}" value="Submit" styleClass="btn" /> |
| | | </p> |
| | | |
| | | <h:outputLabel value="Results:"/><br/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{hello.results}" var="person"> |
| | | <li> |
| | | <h:outputText value="#{person.id} -- #{person.name}"/> |
| | | |
| | | <br/> |
| | | |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | <a href="/create-queries/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>User Log</h1> |
| | | <br class="clear"/> |
| | | <h:form id="viewform"> |
| | | |
| | | <h:outputLabel value="Users:"/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{hello.persons}" var="person"> |
| | | <li> |
| | | <h:outputText value="#{person.id} -- #{person.name}"/><br/> |
| | | |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | <a href="/create-queries/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | # JB125 Java EE 7 Hello World web App |
| | | |
| | | ##This app is composed of the following architecture: |
| | | |
| | | * Maven Project - builds a WAR |
| | | * Using JSF 2.2 for web interface, HTML5 facelets page, JSF backing beans, CDI scopes on beans, @Named |
| | | * Statelss EJB for services - uses JPA entity beans - exposes appropriate method as REST API using JAX-RS annotations |
| | | * JAX-RS Application class |
| | | * JPA entity bean to store names - uses H2 in-memory database |
| | | * Use EJB Singleton to lookup messaging connection and queue destination and inject into stateless EJB - lookup should only occur once on startup |
| | | * Servlet that returns "OK" - this is a health check - path should be [context]/health |
| | | * H2 (embedded in-memory DB) backend |
New file |
| | |
| | | <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> |
| | | <artifactId>persist-entity</artifactId> |
| | | <packaging>war</packaging> |
| | | <name>Persist Entity web app Project</name> |
| | | <description>This is the persist-entity project</description> |
| | | <parent> |
| | | <groupId>com.redhat.training</groupId> |
| | | <artifactId>parent-pom</artifactId> |
| | | <version>1.0</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- First declare the APIs we depend on and need for compilation. All |
| | | of them are provided by JBoss EAP --> |
| | | |
| | | <!-- Import the CDI API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>javax.enterprise</groupId> |
| | | <artifactId>cdi-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the Common Annotations API (JSR-250), we use provided scope |
| | | as the API is included in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.annotation</groupId> |
| | | <artifactId>jboss-annotations-api_1.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JAX-RS API, we use provided scope as the API is included |
| | | in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ws.rs</groupId> |
| | | <artifactId>jboss-jaxrs-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JPA API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate.javax.persistence</groupId> |
| | | <artifactId>hibernate-jpa-2.1-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the EJB API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ejb</groupId> |
| | | <artifactId>jboss-ejb-api_3.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.jms</groupId> |
| | | <artifactId>jboss-jms-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Bean Validation Implementation --> |
| | | <!-- Provides portable constraints such as @Email --> |
| | | <!-- Hibernate Validator is shipped in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator</artifactId> |
| | | <scope>provided</scope> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>slf4j-api</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-search-orm</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-entitymanager</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JSF API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.faces</groupId> |
| | | <artifactId>jboss-jsf-api_2.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.servlet</groupId> |
| | | <artifactId>jboss-servlet-api_3.1_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor to generate the JPA metamodel classes for |
| | | typesafe criteria queries --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-jpamodelgen</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor that raising compilation errors whenever constraint |
| | | annotations are incorrectly used. --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator-annotation-processor</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>persist-entity</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>${version.war.plugin}</version> |
| | | <extensions>false</extensions> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <archive> |
| | | <manifestEntries> |
| | | <Dependencies>com.google.guava,org.slf4j |
| | | </Dependencies> |
| | | </manifestEntries> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.redhat.training.model; |
| | | //add required libraries |
| | | |
| | | //add @Entity annotation here |
| | | public class Person { |
| | | |
| | | //add annotations for primary key |
| | | private Long id; |
| | | |
| | | //add @Column(name="name") annotation to map column in database table |
| | | private String personName; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getPersonName() { |
| | | return personName; |
| | | } |
| | | |
| | | public void setName(String personName) { |
| | | this.personName = personName; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | Person other = (Person) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.services; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | |
| | | import javax.ejb.EJBException; |
| | | import javax.ejb.Stateless; |
| | | //import persistence related libraries |
| | | import javax.persistence.TypedQuery; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | |
| | | @Stateless |
| | | |
| | | public class PersonService { |
| | | //TODO: obtain an EntityManager instance using @PersistenceContext |
| | | |
| | | |
| | | // Simple non-RESTy method for JSF bean invocation |
| | | public String hello(String name) { |
| | | try { |
| | | // let's grab the current date and time on the server |
| | | LocalDateTime today = LocalDateTime.now(); |
| | | |
| | | // format it nicely for on-screen display |
| | | DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm:ss a"); |
| | | String fdate = today.format(format); |
| | | |
| | | // Create a new Person object and persist to database |
| | | Person p = new Person(); |
| | | p.setName(name); |
| | | // call persist() method of entity manager to save the data |
| | | |
| | | // respond back with Hello and convert the name to UPPERCASE. Also, send the |
| | | // current time on the server. |
| | | return "Hello " + name.toUpperCase() + "!. " + "Time on the server is: " + fdate; |
| | | } catch (Exception e) { |
| | | throw new EJBException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | // TODO:add public String getPerson(Long id) method here to fetch result |
| | | // by Person id using find() method |
| | | |
| | | // Get all Person objects in the Database |
| | | public List<Person> getAllPersons() { |
| | | TypedQuery<Person> query = entityManager.createQuery("SELECT p FROM Person p", Person.class); |
| | | List<Person> persons = query.getResultList(); |
| | | |
| | | return persons; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | /* |
| | | * JBoss, Home of Professional Open Source |
| | | * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual |
| | | * contributors by the @authors tag. See the copyright.txt in the |
| | | * distribution for a full listing of individual contributors. |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.redhat.training.servlet; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.annotation.WebServlet; |
| | | import javax.servlet.http.HttpServlet; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * <p> |
| | | * A simple servlet taking advantage of features added in 3.0. |
| | | * </p> |
| | | * |
| | | * <p> |
| | | * The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet |
| | | * @HttpServlet}. |
| | | * </p> |
| | | * |
| | | * @author Pete Muir |
| | | * |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | @WebServlet("/health") |
| | | public class PingServlet extends HttpServlet { |
| | | |
| | | static String PAGE_HEADER = "<html><head><title>Ping Servlet</title></head><body>"; |
| | | |
| | | static String PAGE_FOOTER = "</body></html>"; |
| | | |
| | | @Override |
| | | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| | | resp.setContentType("text/html"); |
| | | PrintWriter writer = resp.getWriter(); |
| | | writer.println(PAGE_HEADER); |
| | | writer.println("<h1>OK.</h1>"); |
| | | writer.println("It is now " + new java.util.Date().toString() + " at the server."); |
| | | writer.println(PAGE_FOOTER); |
| | | writer.close(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | import javax.enterprise.context.RequestScoped; |
| | | import javax.faces.application.FacesMessage; |
| | | import javax.faces.context.FacesContext; |
| | | import javax.inject.Named; |
| | | import javax.validation.ConstraintViolation; |
| | | import javax.validation.ConstraintViolationException; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | import com.redhat.training.services.PersonService; |
| | | |
| | | import javax.inject.Inject; |
| | | import java.util.List; |
| | | |
| | | @RequestScoped |
| | | @Named("hello") |
| | | public class Hello { |
| | | private String name; |
| | | private Long id; |
| | | |
| | | @Inject |
| | | private PersonService personService; |
| | | |
| | | public void sayHello() { |
| | | try { |
| | | String response = personService.hello(name); |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); |
| | | }catch(Exception e){ |
| | | System.out.println(e.getCause()); |
| | | if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { |
| | | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
| | | String violations = ""; |
| | | for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { |
| | | |
| | | violations += cv.getMessage() + "\n"; |
| | | |
| | | System.out.println("Violations: "+violations); |
| | | } |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | /*public void getPerson() { |
| | | try { |
| | | String response = personService.getPerson(id); |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); |
| | | }catch(Exception e){ |
| | | System.out.println(e.getCause()); |
| | | if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { |
| | | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
| | | String violations = ""; |
| | | for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { |
| | | |
| | | violations += cv.getMessage() + "\n"; |
| | | |
| | | System.out.println("Violations: "+violations); |
| | | } |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); |
| | | } |
| | | |
| | | } |
| | | |
| | | }*/ |
| | | |
| | | |
| | | /*public List<Person> getPersons() { |
| | | return personService.getAllPersons(); |
| | | |
| | | }*/ |
| | | |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <persistence version="2.1" |
| | | xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> |
| | | <persistence-unit name="hello" transaction-type="JTA"> |
| | | <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> |
| | | <properties> |
| | | <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> |
| | | <property name="hibernate.hbm2ddl.auto" value="create-drop" /> |
| | | <property name="hibernate.show_sql" value="true" /> |
| | | <property name="hibernate.format_sql" value="true" /> |
| | | </properties> |
| | | </persistence-unit> |
| | | </persistence> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file can be an empty text file (0 bytes) --> |
| | | <!-- We're declaring the schema to save you time if you do have to configure |
| | | this in the future --> |
| | | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| | | </beans> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file is not required if you don't need any extra configuration. --> |
| | | <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
| | | |
| | | <!-- This descriptor activates the JSF 2.0 Servlet --> |
| | | |
| | | <!-- Write your navigation rules here. You are encouraged to use CDI |
| | | for creating @Named managed beans. --> |
| | | |
| | | </faces-config> |
New file |
| | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets"> |
| | | <h:head> |
| | | <title><ui:insert name="title"> |
| | | [Title will be inserted here] |
| | | </ui:insert> |
| | | </title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <h:outputStylesheet name="css/screen.css" /> |
| | | </h:head> |
| | | <h:body> |
| | | |
| | | <header> |
| | | <h:graphicImage name="images/redhat.png" /> |
| | | <div class="right"> |
| | | Application: |
| | | <ui:insert name="application_name"> |
| | | [Application name will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | </header> |
| | | <div id="content"> |
| | | <ui:insert name="content"> |
| | | [Template content will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | <footer> |
| | | JB183 - Enterprise Java Development - Red Hat Training |
| | | </footer> |
| | | </h:body> |
| | | </html> |
New file |
| | |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- Plain HTML page that kicks us into the app --> |
| | | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Refresh" content="0; URL=index.jsf"> |
| | | </head> |
| | | </html> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Persist Entity web app</h1> |
| | | <br class="clear"/> |
| | | <h:form id="form"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Enter your name:" for="name" /> |
| | | <h:inputText value="#{hello.name}" id="name" required="true" requiredMessage="Name is required"/> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p class="input"> |
| | | <h:commandButton action="#{hello.sayHello()}" value="Submit" styleClass="btn" /> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <h:messages styleClass="messages"/> |
| | | <a href="/persist-entity/viewPersons.xhtml">View all names</a> |
| | | <a href="/persist-entity/viewPerson.xhtml">Search a name</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | body { |
| | | |
| | | } |
| | | |
| | | header { |
| | | background-color: #C40016; |
| | | height: 150px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | border: 4px solid #000000; |
| | | } |
| | | |
| | | header .right { |
| | | display: inline-block; |
| | | float: right; |
| | | font-size: 40px; |
| | | font-weight: bolder; |
| | | height: 150px; |
| | | padding: 48px; |
| | | vertical-align: middle; |
| | | } |
| | | |
| | | #content { |
| | | background-color: #F2F2F2; |
| | | width: 91%; |
| | | margin: 0 auto; |
| | | padding: 100px 50px; |
| | | border: 2px solid #000000; |
| | | } |
| | | |
| | | footer { |
| | | border: 4px solid #000000; |
| | | background-color: #C40016; |
| | | height: 30px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | text-align: center; |
| | | font-weight: bolder; |
| | | font-size: 27px; |
| | | } |
| | | |
| | | label{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
| | | input { |
| | | display: inline-block; |
| | | float: left; |
| | | width: 362px; |
| | | } |
| | | select{ |
| | | display: inline-block; |
| | | float: left; |
| | | width: 371px; |
| | | } |
| | | textarea{ |
| | | display: inline-block; |
| | | float: left; |
| | | } |
| | | |
| | | .clear{ |
| | | clear: both; |
| | | } |
| | | |
| | | .messages{ |
| | | color: green; |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .btn{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Persist Entity web app</h1> |
| | | <br class="clear"/> |
| | | <h:form id="Personform"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Enter Id:" for="id" /> |
| | | <h:inputText value="#{hello.id}" id="id" required="true" requiredMessage="Id is required"/> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p class="input"> |
| | | <h:commandButton action="#{hello.getPerson()}" value="Submit" styleClass="btn" /> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <h:messages styleClass="messages"/> |
| | | <a href="/persist-entity/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | All who said hello |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Say Hello |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>These people said hello</h1> |
| | | <br class="clear"/> |
| | | <h:form id="viewform"> |
| | | |
| | | <h:outputLabel value="Persons:"/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{hello.persons}" var="person"> |
| | | <li> |
| | | <strong>Name:</strong><h:outputText value="#{person.personName}"/><br/> |
| | | |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | <a href="/persist-entity/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | .classpath |
| | | .project |
| | | .tern-project |
| | | .settings |
| | | target |
New file |
| | |
| | | # JB125 Java EE 7 Hello World web App |
| | | |
| | | ##This app is composed of the following architecture: |
| | | |
| | | * Maven Project - builds a WAR |
| | | * Using JSF 2.2 for web interface, HTML5 facelets page, JSF backing beans, CDI scopes on beans, @Named |
| | | * Statelss EJB for services - uses JPA entity beans - exposes appropriate method as REST API using JAX-RS annotations |
| | | * JAX-RS Application class |
| | | * JPA entity bean to store names - uses H2 in-memory database |
| | | * Use EJB Singleton to lookup messaging connection and queue destination and inject into stateless EJB - lookup should only occur once on startup |
| | | * Servlet that returns "OK" - this is a health check - path should be [context]/health |
| | | * H2 (embedded in-memory DB) backend |
New file |
| | |
| | | USE todo; |
| | | DROP TABLE IF EXISTS `Person`; |
| | | CREATE TABLE `Person` (`id` BIGINT not null auto_increment primary key, `name` VARCHAR(40)); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (1,'John'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (2,'Steve'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (3,'Mark'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (4,'Nick'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (5,'Nita'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (6,'John'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (7,'Julia'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (8,'Joe'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (9,'Nita'); |
| | | INSERT INTO `Person` (`id`,`name`) VALUES (10,'Branden'); |
| | | |
New file |
| | |
| | | <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> |
| | | <artifactId>create-queries-solution</artifactId> |
| | | <packaging>war</packaging> |
| | | <name>Create Queries web app Project</name> |
| | | <description>This is the create-queries project</description> |
| | | <parent> |
| | | <groupId>com.redhat.training</groupId> |
| | | <artifactId>parent-pom</artifactId> |
| | | <version>1.0</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- First declare the APIs we depend on and need for compilation. All |
| | | of them are provided by JBoss EAP --> |
| | | |
| | | <!-- Import the CDI API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>javax.enterprise</groupId> |
| | | <artifactId>cdi-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the Common Annotations API (JSR-250), we use provided scope |
| | | as the API is included in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.annotation</groupId> |
| | | <artifactId>jboss-annotations-api_1.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JAX-RS API, we use provided scope as the API is included |
| | | in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ws.rs</groupId> |
| | | <artifactId>jboss-jaxrs-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JPA API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate.javax.persistence</groupId> |
| | | <artifactId>hibernate-jpa-2.1-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the EJB API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ejb</groupId> |
| | | <artifactId>jboss-ejb-api_3.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.jms</groupId> |
| | | <artifactId>jboss-jms-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Bean Validation Implementation --> |
| | | <!-- Provides portable constraints such as @Email --> |
| | | <!-- Hibernate Validator is shipped in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator</artifactId> |
| | | <scope>provided</scope> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>slf4j-api</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-search-orm</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-entitymanager</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JSF API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.faces</groupId> |
| | | <artifactId>jboss-jsf-api_2.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.servlet</groupId> |
| | | <artifactId>jboss-servlet-api_3.1_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor to generate the JPA metamodel classes for |
| | | typesafe criteria queries --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-jpamodelgen</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor that raising compilation errors whenever constraint |
| | | annotations are incorrectly used. --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator-annotation-processor</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>create-queries</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>${version.war.plugin}</version> |
| | | <extensions>false</extensions> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <archive> |
| | | <manifestEntries> |
| | | <Dependencies>com.google.guava,org.slf4j |
| | | </Dependencies> |
| | | </manifestEntries> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.NamedQuery; |
| | | |
| | | @Entity |
| | | //add named query here |
| | | @NamedQuery( |
| | | name="getAllPersonsWithName", |
| | | query="select p from Person p where p.name = :pname") |
| | | public class Person{ |
| | | @Id |
| | | private Long id; |
| | | |
| | | private String name; |
| | | |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | Person other = (Person) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.services; |
| | | |
| | | import java.util.List; |
| | | |
| | | import javax.ejb.Stateless; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.PersistenceContext; |
| | | import javax.persistence.TypedQuery; |
| | | import javax.persistence.Query; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | |
| | | @Stateless |
| | | |
| | | public class PersonService { |
| | | |
| | | @PersistenceContext(unitName="hello") |
| | | private EntityManager entityManager; |
| | | |
| | | // Get all Person objects in the Database |
| | | public List<Person> getAllPersons() { |
| | | TypedQuery<Person> query = entityManager.createQuery("SELECT p FROM Person p", Person.class); |
| | | return query.getResultList(); |
| | | } |
| | | /*//Get persons whose name matches the name given in the query -- Named parameters |
| | | public List<Person> getPersonsWithName(String name) { |
| | | TypedQuery<Person> query = entityManager.createQuery("SELECT p from Person p where p.name =:pname", Person.class); |
| | | query.setParameter("pname", name); |
| | | return = query.getResultList(); |
| | | |
| | | }*/ |
| | | /* //Get persons whose name matches the name given in the query -- positional parameters |
| | | public List<Person> getPersonsWithName(String name) { |
| | | TypedQuery<Person> query = entityManager.createQuery("SELECT p from Person p where p.name =?1", Person.class); |
| | | query.setParameter(1, name); |
| | | return = query.getResultList(); |
| | | }*/ |
| | | //Get persons whose name matches the name given in the query |
| | | public List<Person> getPersonsWithName(String name) { |
| | | TypedQuery<Person> query = entityManager.createNamedQuery("getAllPersonsWithName", Person.class); |
| | | query.setParameter("pname", name); |
| | | return query.getResultList(); |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * JBoss, Home of Professional Open Source |
| | | * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual |
| | | * contributors by the @authors tag. See the copyright.txt in the |
| | | * distribution for a full listing of individual contributors. |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.redhat.training.servlet; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.annotation.WebServlet; |
| | | import javax.servlet.http.HttpServlet; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * <p> |
| | | * A simple servlet taking advantage of features added in 3.0. |
| | | * </p> |
| | | * |
| | | * <p> |
| | | * The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet |
| | | * @HttpServlet}. |
| | | * </p> |
| | | * |
| | | * @author Pete Muir |
| | | * |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | @WebServlet("/health") |
| | | public class PingServlet extends HttpServlet { |
| | | |
| | | static String PAGE_HEADER = "<html><head><title>Ping Servlet</title></head><body>"; |
| | | |
| | | static String PAGE_FOOTER = "</body></html>"; |
| | | |
| | | @Override |
| | | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| | | resp.setContentType("text/html"); |
| | | PrintWriter writer = resp.getWriter(); |
| | | writer.println(PAGE_HEADER); |
| | | writer.println("<h1>OK.</h1>"); |
| | | writer.println("It is now " + new java.util.Date().toString() + " at the server."); |
| | | writer.println(PAGE_FOOTER); |
| | | writer.close(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | import javax.enterprise.context.RequestScoped; |
| | | import javax.inject.Named; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | import com.redhat.training.services.PersonService; |
| | | |
| | | import javax.inject.Inject; |
| | | import java.util.List; |
| | | |
| | | |
| | | |
| | | @RequestScoped |
| | | @Named("hello") |
| | | public class Hello { |
| | | private String name; |
| | | private Long id; |
| | | private List<Person> results; |
| | | |
| | | @Inject |
| | | private PersonService personService; |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | //View all persons in the database table |
| | | public List<Person> getPersons() { |
| | | return personService.getAllPersons(); |
| | | } |
| | | |
| | | //view all persons whose name matches the name given in the query |
| | | public void search() { |
| | | results = personService.getPersonsWithName(name); |
| | | } |
| | | |
| | | public List<Person> getResults() { |
| | | return results; |
| | | } |
| | | |
| | | public void setResults(List<Person> results) { |
| | | this.results = results; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <persistence version="2.1" |
| | | xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> |
| | | <persistence-unit name="hello" transaction-type="JTA"> |
| | | <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source> |
| | | <properties> |
| | | <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> |
| | | <property name="hibernate.hbm2ddl.auto" value="create-drop" /> |
| | | <property name="hibernate.show_sql" value="true" /> |
| | | <property name="hibernate.format_sql" value="true" /> |
| | | </properties> |
| | | </persistence-unit> |
| | | </persistence> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file can be an empty text file (0 bytes) --> |
| | | <!-- We're declaring the schema to save you time if you do have to configure |
| | | this in the future --> |
| | | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| | | </beans> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file is not required if you don't need any extra configuration. --> |
| | | <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
| | | |
| | | <!-- This descriptor activates the JSF 2.0 Servlet --> |
| | | |
| | | <!-- Write your navigation rules here. You are encouraged to use CDI |
| | | for creating @Named managed beans. --> |
| | | |
| | | </faces-config> |
New file |
| | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets"> |
| | | <h:head> |
| | | <title><ui:insert name="title"> |
| | | [Title will be inserted here] |
| | | </ui:insert> |
| | | </title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <h:outputStylesheet name="css/screen.css" /> |
| | | </h:head> |
| | | <h:body> |
| | | |
| | | <header> |
| | | <h:graphicImage name="images/redhat.png" /> |
| | | <div class="right"> |
| | | Application: |
| | | <ui:insert name="application_name"> |
| | | [Application name will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | </header> |
| | | <div id="content"> |
| | | <ui:insert name="content"> |
| | | [Template content will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | <footer> |
| | | JB183 - Enterprise Java Development - Red Hat Training |
| | | </footer> |
| | | </h:body> |
| | | </html> |
New file |
| | |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- Plain HTML page that kicks us into the app --> |
| | | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Refresh" content="0; URL=index.jsf"> |
| | | </head> |
| | | </html> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Create Queries Web Application |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Create Queries Web Application |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Create Queries</h1> |
| | | <br class="clear"/> |
| | | <h:form id="form"> |
| | | <br class="clear"/> |
| | | <h1> |
| | | <a href="/create-queries/viewPersons.xhtml">View All Users</a> |
| | | <br/> |
| | | <a href="/create-queries/viewPerson.xhtml">Search Users</a> |
| | | </h1> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | body { |
| | | |
| | | } |
| | | |
| | | header { |
| | | background-color: #C40016; |
| | | height: 150px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | border: 4px solid #000000; |
| | | } |
| | | |
| | | header .right { |
| | | display: inline-block; |
| | | float: right; |
| | | font-size: 40px; |
| | | font-weight: bolder; |
| | | height: 150px; |
| | | padding: 48px; |
| | | vertical-align: middle; |
| | | } |
| | | |
| | | #content { |
| | | background-color: #F2F2F2; |
| | | width: 91%; |
| | | margin: 0 auto; |
| | | padding: 100px 50px; |
| | | border: 2px solid #000000; |
| | | } |
| | | |
| | | footer { |
| | | border: 4px solid #000000; |
| | | background-color: #C40016; |
| | | height: 30px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | text-align: center; |
| | | font-weight: bolder; |
| | | font-size: 27px; |
| | | } |
| | | |
| | | label{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
| | | input { |
| | | display: inline-block; |
| | | float: left; |
| | | width: 362px; |
| | | } |
| | | select{ |
| | | display: inline-block; |
| | | float: left; |
| | | width: 371px; |
| | | } |
| | | textarea{ |
| | | display: inline-block; |
| | | float: left; |
| | | } |
| | | |
| | | .clear{ |
| | | clear: both; |
| | | } |
| | | |
| | | .messages{ |
| | | color: green; |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .btn{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Search Users</h1> |
| | | <br class="clear"/> |
| | | <h:form id="viewform"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Name:" for="name" /> |
| | | <h:inputText value="#{hello.name}" id="name" required="true" requiredMessage="Name is required"/> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p class="input"> |
| | | <h:commandButton action="#{hello.search}" value="Submit" styleClass="btn" /> |
| | | </p> |
| | | |
| | | <h:outputLabel value="Results:"/><br/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{hello.results}" var="person"> |
| | | <li> |
| | | <h:outputText value="#{person.id} -- #{person.name}"/> |
| | | |
| | | <br/> |
| | | |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | <a href="/create-queries/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Create Queries |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>User Log</h1> |
| | | <br class="clear"/> |
| | | <h:form id="viewform"> |
| | | |
| | | <h:outputLabel value="Users:"/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{hello.persons}" var="person"> |
| | | <li> |
| | | <h:outputText value="#{person.id} -- #{person.name}"/><br/> |
| | | |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | <a href="/create-queries/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | .classpath |
| | | .project |
| | | .tern-project |
| | | .settings |
| | | target |
New file |
| | |
| | | # JB125 Java EE 7 Hello World web App |
| | | |
| | | ##This app is composed of the following architecture: |
| | | |
| | | * Maven Project - builds a WAR |
| | | * Using JSF 2.2 for web interface, HTML5 facelets page, JSF backing beans, CDI scopes on beans, @Named |
| | | * Statelss EJB for services - uses JPA entity beans - exposes appropriate method as REST API using JAX-RS annotations |
| | | * JAX-RS Application class |
| | | * JPA entity bean to store names - uses H2 in-memory database |
| | | * Use EJB Singleton to lookup messaging connection and queue destination and inject into stateless EJB - lookup should only occur once on startup |
| | | * Servlet that returns "OK" - this is a health check - path should be [context]/health |
| | | * H2 (embedded in-memory DB) backend |
New file |
| | |
| | | <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> |
| | | <artifactId>persist-entity-solution</artifactId> |
| | | <packaging>war</packaging> |
| | | <name>Persist Entity web app Project</name> |
| | | <description>This is the persist-entity project</description> |
| | | <parent> |
| | | <groupId>com.redhat.training</groupId> |
| | | <artifactId>parent-pom</artifactId> |
| | | <version>1.0</version> |
| | | <relativePath>../pom.xml</relativePath> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- First declare the APIs we depend on and need for compilation. All |
| | | of them are provided by JBoss EAP --> |
| | | |
| | | <!-- Import the CDI API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>javax.enterprise</groupId> |
| | | <artifactId>cdi-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the Common Annotations API (JSR-250), we use provided scope |
| | | as the API is included in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.annotation</groupId> |
| | | <artifactId>jboss-annotations-api_1.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JAX-RS API, we use provided scope as the API is included |
| | | in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ws.rs</groupId> |
| | | <artifactId>jboss-jaxrs-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JPA API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate.javax.persistence</groupId> |
| | | <artifactId>hibernate-jpa-2.1-api</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the EJB API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.ejb</groupId> |
| | | <artifactId>jboss-ejb-api_3.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.jms</groupId> |
| | | <artifactId>jboss-jms-api_2.0_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Bean Validation Implementation --> |
| | | <!-- Provides portable constraints such as @Email --> |
| | | <!-- Hibernate Validator is shipped in JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator</artifactId> |
| | | <scope>provided</scope> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>slf4j-api</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-search-orm</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-entitymanager</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Import the JSF API, we use provided scope as the API is included in |
| | | JBoss EAP --> |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.faces</groupId> |
| | | <artifactId>jboss-jsf-api_2.2_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.jboss.spec.javax.servlet</groupId> |
| | | <artifactId>jboss-servlet-api_3.1_spec</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor to generate the JPA metamodel classes for |
| | | typesafe criteria queries --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-jpamodelgen</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | <!-- Annotation processor that raising compilation errors whenever constraint |
| | | annotations are incorrectly used. --> |
| | | <dependency> |
| | | <groupId>org.hibernate</groupId> |
| | | <artifactId>hibernate-validator-annotation-processor</artifactId> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <finalName>persist-entity</finalName> |
| | | <plugins> |
| | | <plugin> |
| | | <artifactId>maven-war-plugin</artifactId> |
| | | <version>${version.war.plugin}</version> |
| | | <extensions>false</extensions> |
| | | <configuration> |
| | | <failOnMissingWebXml>false</failOnMissingWebXml> |
| | | <archive> |
| | | <manifestEntries> |
| | | <Dependencies>com.google.guava,org.slf4j |
| | | </Dependencies> |
| | | </manifestEntries> |
| | | </archive> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | </project> |
New file |
| | |
| | | package com.redhat.training.model; |
| | | |
| | | //add required libraries |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.Column; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | //add @Entity annotation here |
| | | @Entity |
| | | public class Person implements Serializable{ |
| | | //add annotations for primary key |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | //add @Column(name="name") annotation to map column in database table |
| | | @Column(name="name") |
| | | private String personName; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getPersonName() { |
| | | return personName; |
| | | } |
| | | |
| | | public void setName(String personName) { |
| | | this.personName = personName; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | final int prime = 31; |
| | | int result = 1; |
| | | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) |
| | | return true; |
| | | if (obj == null) |
| | | return false; |
| | | if (getClass() != obj.getClass()) |
| | | return false; |
| | | Person other = (Person) obj; |
| | | if (id == null) { |
| | | if (other.id != null) |
| | | return false; |
| | | } else if (!id.equals(other.id)) |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.services; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | |
| | | import javax.ejb.EJBException; |
| | | import javax.ejb.Stateless; |
| | | import javax.persistence.EntityManager; |
| | | import javax.persistence.PersistenceContext; |
| | | import javax.persistence.TypedQuery; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | |
| | | @Stateless |
| | | |
| | | public class PersonService { |
| | | //TODO: obtain an EntityManager instance using @PersistenceContext |
| | | @PersistenceContext(unitName="hello") |
| | | private EntityManager entityManager; |
| | | |
| | | // Simple non-RESTy method for JSF bean invocation |
| | | public String hello(String name) { |
| | | try { |
| | | // let's grab the current date and time on the server |
| | | LocalDateTime today = LocalDateTime.now(); |
| | | |
| | | // format it nicely for on-screen display |
| | | DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm:ss a"); |
| | | String fdate = today.format(format); |
| | | |
| | | // Create a new Person object and persist to database |
| | | Person p = new Person(); |
| | | p.setName(name); |
| | | // call persist() method of entity manager to save the data |
| | | entityManager.persist(p); |
| | | |
| | | // respond back with Hello and convert the name to UPPERCASE. Also, send the |
| | | // current time on the server. |
| | | return "Hello " + name.toUpperCase() + "!. " + "Time on the server is: " + fdate; |
| | | } catch (Exception e) { |
| | | throw new EJBException(e); |
| | | } |
| | | } |
| | | |
| | | // TODO:add public String getPerson(Long id) method here to fetch result |
| | | //by Person id using find() method |
| | | |
| | | public String getPerson(Long id) { |
| | | |
| | | return entityManager.find(Person.class, id).getPersonName(); |
| | | } |
| | | |
| | | // Get all Person objects in the Database |
| | | public List<Person> getAllPersons() { |
| | | TypedQuery<Person> query = entityManager.createQuery("SELECT p FROM Person p", Person.class); |
| | | List<Person> persons = query.getResultList(); |
| | | |
| | | return persons; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | /* |
| | | * JBoss, Home of Professional Open Source |
| | | * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual |
| | | * contributors by the @authors tag. See the copyright.txt in the |
| | | * distribution for a full listing of individual contributors. |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.redhat.training.servlet; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.annotation.WebServlet; |
| | | import javax.servlet.http.HttpServlet; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * <p> |
| | | * A simple servlet taking advantage of features added in 3.0. |
| | | * </p> |
| | | * |
| | | * <p> |
| | | * The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet |
| | | * @HttpServlet}. |
| | | * </p> |
| | | * |
| | | * @author Pete Muir |
| | | * |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | @WebServlet("/health") |
| | | public class PingServlet extends HttpServlet { |
| | | |
| | | static String PAGE_HEADER = "<html><head><title>Ping Servlet</title></head><body>"; |
| | | |
| | | static String PAGE_FOOTER = "</body></html>"; |
| | | |
| | | @Override |
| | | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| | | resp.setContentType("text/html"); |
| | | PrintWriter writer = resp.getWriter(); |
| | | writer.println(PAGE_HEADER); |
| | | writer.println("<h1>OK.</h1>"); |
| | | writer.println("It is now " + new java.util.Date().toString() + " at the server."); |
| | | writer.println(PAGE_FOOTER); |
| | | writer.close(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.redhat.training.ui; |
| | | |
| | | import javax.enterprise.context.RequestScoped; |
| | | import javax.faces.application.FacesMessage; |
| | | import javax.faces.context.FacesContext; |
| | | import javax.inject.Named; |
| | | import javax.validation.ConstraintViolation; |
| | | import javax.validation.ConstraintViolationException; |
| | | |
| | | import com.redhat.training.model.Person; |
| | | import com.redhat.training.services.PersonService; |
| | | |
| | | import javax.inject.Inject; |
| | | import java.util.List; |
| | | |
| | | |
| | | |
| | | @RequestScoped |
| | | @Named("hello") |
| | | public class Hello { |
| | | private String name; |
| | | private Long id; |
| | | |
| | | @Inject |
| | | private PersonService personService; |
| | | |
| | | public void sayHello() { |
| | | try { |
| | | String response = personService.hello(name); |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); |
| | | }catch(Exception e){ |
| | | System.out.println(e.getCause()); |
| | | if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { |
| | | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
| | | String violations = ""; |
| | | for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { |
| | | |
| | | violations += cv.getMessage() + "\n"; |
| | | |
| | | System.out.println("Violations: "+violations); |
| | | } |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public void getPerson() { |
| | | try { |
| | | String response = personService.getPerson(id); |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); |
| | | }catch(Exception e){ |
| | | System.out.println(e.getCause()); |
| | | if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { |
| | | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
| | | String violations = ""; |
| | | for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { |
| | | |
| | | violations += cv.getMessage() + "\n"; |
| | | |
| | | System.out.println("Violations: "+violations); |
| | | } |
| | | FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | public List<Person> getPersons() { |
| | | return personService.getAllPersons(); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <persistence version="2.1" |
| | | xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> |
| | | <persistence-unit name="hello" transaction-type="JTA"> |
| | | <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> |
| | | <properties> |
| | | <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> |
| | | <property name="hibernate.hbm2ddl.auto" value="create-drop" /> |
| | | <property name="hibernate.show_sql" value="true" /> |
| | | <property name="hibernate.format_sql" value="true" /> |
| | | </properties> |
| | | </persistence-unit> |
| | | </persistence> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file can be an empty text file (0 bytes) --> |
| | | <!-- We're declaring the schema to save you time if you do have to configure |
| | | this in the future --> |
| | | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| | | </beans> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- This file is not required if you don't need any extra configuration. --> |
| | | <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation=" |
| | | http://java.sun.com/xml/ns/javaee |
| | | http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> |
| | | |
| | | <!-- This descriptor activates the JSF 2.0 Servlet --> |
| | | |
| | | <!-- Write your navigation rules here. You are encouraged to use CDI |
| | | for creating @Named managed beans. --> |
| | | |
| | | </faces-config> |
New file |
| | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets"> |
| | | <h:head> |
| | | <title><ui:insert name="title"> |
| | | [Title will be inserted here] |
| | | </ui:insert> |
| | | </title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <h:outputStylesheet name="css/screen.css" /> |
| | | </h:head> |
| | | <h:body> |
| | | |
| | | <header> |
| | | <h:graphicImage name="images/redhat.png" /> |
| | | <div class="right"> |
| | | Application: |
| | | <ui:insert name="application_name"> |
| | | [Application name will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | </header> |
| | | <div id="content"> |
| | | <ui:insert name="content"> |
| | | [Template content will be inserted here] |
| | | </ui:insert> |
| | | </div> |
| | | <footer> |
| | | JB183 - Enterprise Java Development - Red Hat Training |
| | | </footer> |
| | | </h:body> |
| | | </html> |
New file |
| | |
| | | <!-- |
| | | JBoss, Home of Professional Open Source |
| | | Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual |
| | | contributors by the @authors tag. See the copyright.txt in the |
| | | distribution for a full listing of individual contributors. |
| | | |
| | | Licensed under the Apache License, Version 2.0 (the "License"); |
| | | you may not use this file except in compliance with the License. |
| | | You may obtain a copy of the License at |
| | | http://www.apache.org/licenses/LICENSE-2.0 |
| | | Unless required by applicable law or agreed to in writing, software |
| | | distributed under the License is distributed on an "AS IS" BASIS, |
| | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | See the License for the specific language governing permissions and |
| | | limitations under the License. |
| | | --> |
| | | <!-- Plain HTML page that kicks us into the app --> |
| | | |
| | | <html> |
| | | <head> |
| | | <meta http-equiv="Refresh" content="0; URL=index.jsf"> |
| | | </head> |
| | | </html> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Persist Entity web app</h1> |
| | | <br class="clear"/> |
| | | <h:form id="form"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Enter your name:" for="name" /> |
| | | <h:inputText value="#{hello.name}" id="name" required="true" requiredMessage="Name is required"/> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p class="input"> |
| | | <h:commandButton action="#{hello.sayHello()}" value="Submit" styleClass="btn" /> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <h:messages styleClass="messages"/> |
| | | <a href="/persist-entity/viewPersons.xhtml">View all names</a> |
| | | <a href="/persist-entity/viewPerson.xhtml">Search a name</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | body { |
| | | |
| | | } |
| | | |
| | | header { |
| | | background-color: #C40016; |
| | | height: 150px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | border: 4px solid #000000; |
| | | } |
| | | |
| | | header .right { |
| | | display: inline-block; |
| | | float: right; |
| | | font-size: 40px; |
| | | font-weight: bolder; |
| | | height: 150px; |
| | | padding: 48px; |
| | | vertical-align: middle; |
| | | } |
| | | |
| | | #content { |
| | | background-color: #F2F2F2; |
| | | width: 91%; |
| | | margin: 0 auto; |
| | | padding: 100px 50px; |
| | | border: 2px solid #000000; |
| | | } |
| | | |
| | | footer { |
| | | border: 4px solid #000000; |
| | | background-color: #C40016; |
| | | height: 30px; |
| | | padding: 10px; |
| | | width: 95%; |
| | | margin: 0 auto; |
| | | text-align: center; |
| | | font-weight: bolder; |
| | | font-size: 27px; |
| | | } |
| | | |
| | | label{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
| | | input { |
| | | display: inline-block; |
| | | float: left; |
| | | width: 362px; |
| | | } |
| | | select{ |
| | | display: inline-block; |
| | | float: left; |
| | | width: 371px; |
| | | } |
| | | textarea{ |
| | | display: inline-block; |
| | | float: left; |
| | | } |
| | | |
| | | .clear{ |
| | | clear: both; |
| | | } |
| | | |
| | | .messages{ |
| | | color: green; |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .btn{ |
| | | display: inline-block; |
| | | float: left; |
| | | clear: left; |
| | | width: 165px; |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Persist Entity web app |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>Persist Entity web app</h1> |
| | | <br class="clear"/> |
| | | <h:form id="Personform"> |
| | | <p class="input"> |
| | | <h:outputLabel value="Enter Id:" for="id" /> |
| | | <h:inputText value="#{hello.id}" id="id" required="true" requiredMessage="Id is required"/> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <p class="input"> |
| | | <h:commandButton action="#{hello.getPerson()}" value="Submit" styleClass="btn" /> |
| | | </p> |
| | | <br class="clear"/> |
| | | <br class="clear"/> |
| | | <h:messages styleClass="messages"/> |
| | | <a href="/persist-entity/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | |
| | | <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:ui="http://java.sun.com/jsf/facelets" |
| | | xmlns:f="http://java.sun.com/jsf/core" |
| | | xmlns:h="http://java.sun.com/jsf/html" |
| | | template="/WEB-INF/templates/default.xhtml"> |
| | | <ui:define name="title"> |
| | | All who said hello |
| | | </ui:define> |
| | | <ui:define name="application_name"> |
| | | Say Hello |
| | | </ui:define> |
| | | <ui:define name="content"> |
| | | <h1>These people said hello</h1> |
| | | <br class="clear"/> |
| | | <h:form id="viewform"> |
| | | |
| | | <h:outputLabel value="Persons:"/> |
| | | <br class="clear"/> |
| | | <ul> |
| | | <ui:repeat value="#{hello.persons}" var="person"> |
| | | <li> |
| | | <strong>Name:</strong><h:outputText value="#{person.personName}"/><br/> |
| | | |
| | | </li> |
| | | </ui:repeat> |
| | | </ul> |
| | | <a href="/persist-entity/index.xhtml">Back</a> |
| | | </h:form> |
| | | </ui:define> |
| | | </ui:composition> |