Repository: deltaspike Updated Branches: refs/heads/master 2da220a2f -> 80c9ae77d
DELTASPIKE-1203 jpa example Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/fcb21a15 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/fcb21a15 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/fcb21a15 Branch: refs/heads/master Commit: fcb21a158295e155ae8abe1e1459d6dfc6bc3005 Parents: 2da220a Author: subaochen <subaoc...@126.com> Authored: Sun Sep 11 21:54:07 2016 +0800 Committer: John D. Ament <johndam...@apache.org> Committed: Sat Oct 15 09:22:39 2016 -0400 ---------------------------------------------------------------------- deltaspike/examples/jpa-examples/README.md | 25 ++++ deltaspike/examples/jpa-examples/pom.xml | 114 +++++++++++++++++++ .../org/apache/deltaspike/example/Article.java | 108 ++++++++++++++++++ .../deltaspike/example/ArticleController.java | 103 +++++++++++++++++ .../apache/deltaspike/example/HttpParam.java | 41 +++++++ .../apache/deltaspike/example/HttpParams.java | 41 +++++++ .../apache/deltaspike/example/LogProducer.java | 37 ++++++ .../apache/deltaspike/example/Resources.java | 63 ++++++++++ .../src/main/resources/META-INF/persistence.xml | 15 +++ .../src/main/webapp/WEB-INF/beans.xml | 23 ++++ .../src/main/webapp/WEB-INF/faces-config.xml | 40 +++++++ .../src/main/webapp/WEB-INF/web.xml | 43 +++++++ .../jpa-examples/src/main/webapp/add.xhtml | 52 +++++++++ .../jpa-examples/src/main/webapp/index.xhtml | 39 +++++++ .../jpa-examples/src/main/webapp/list.xhtml | 64 +++++++++++ deltaspike/examples/pom.xml | 9 +- 16 files changed, 816 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/README.md ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/README.md b/deltaspike/examples/jpa-examples/README.md new file mode 100644 index 0000000..f1c23e0 --- /dev/null +++ b/deltaspike/examples/jpa-examples/README.md @@ -0,0 +1,25 @@ +Notice: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + +JPA support in deltaspike +========================= +This example shows: + +1, how to use JPA in deltaspike; +2, the function of @Transactional, how @Transactional save entity automatically. + +BUT, this example is not involved in deltaspike Data module, please see data-playground example for deltaspike data module. http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/pom.xml b/deltaspike/examples/jpa-examples/pom.xml new file mode 100644 index 0000000..a17e2f5 --- /dev/null +++ b/deltaspike/examples/jpa-examples/pom.xml @@ -0,0 +1,114 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> + +<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/maven-v4_0_0.xsd"> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + --> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.deltaspike.examples</groupId> + <artifactId>examples-project</artifactId> + <version>1.7.2-SNAPSHOT</version> + </parent> + + <artifactId>deltaspike-jpa-examples</artifactId> + + <name>Apache DeltaSpike JPA Examples</name> + + <packaging>war</packaging> + + <properties> + <deploy.skip>true</deploy.skip> + </properties> + + <dependencies> + <!-- DeltaSpike modules --> + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-jsf-module-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-jsf-module-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-jpa-module-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-jpa-module-impl</artifactId> + </dependency> + + + + <!-- The tutorials use postgresql database --> + <!-- + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>9.4.1209.jre7</version> + <scope>provided</scope> + </dependency> + --> + + <dependency> + <groupId>javax</groupId> + <artifactId>javaee-api</artifactId> + <version>7.0</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <finalName>${project.artifactId}</finalName> + </build> +</project> + http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Article.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Article.java b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Article.java new file mode 100644 index 0000000..10505b6 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Article.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.deltaspike.example; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name = "articles") +public class Article implements Serializable +{ + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + private Long id; + + private String title; + private String content; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "time_created") + private Date date; + + // A must have! + public Article() + { + // this form used by Hibernate + } + + public Article(String title, Date date) + { + // for application use, to create new articles + this.title = title; + this.date = date; + } + + public Long getId() + { + return id; + } + + private void setId(Long id) + { + this.id = id; + } + + public Date getDate() + { + return date; + } + + public void setDate(Date date) + { + this.date = date; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getContent() + { + return content; + } + + public void setContent(String content) + { + this.content = content; + } + + @Override + public String toString() + { + return "Article{" + "id=" + id + ", title=" + title + ", content=" + content + ", date=" + date + '}'; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/ArticleController.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/ArticleController.java b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/ArticleController.java new file mode 100644 index 0000000..56c1716 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/ArticleController.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.deltaspike.example; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; +import javax.faces.application.FacesMessage; +import javax.faces.bean.ViewScoped; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.transaction.Transactional; + +/** + * + * @author Su Baochen <subaoc...@126.com> + */ +@Named +@ViewScoped +@Transactional +public class ArticleController implements Serializable +{ + + private Article article = new Article(); + + @Inject + private Logger log; + + @Inject + private EntityManager em; + + @Inject + private FacesContext facesContext; + + @HttpParam("aid") + @Inject + private String aid; // article id + + public Article getArticle() + { + return article; + } + + public void setArticle(Article article) + { + this.article = article; + } + + public Article findArticleById(Long id) + { + article = em.find(Article.class, id); + return article; + } + + + public String persist() + { + article.setDate(new Date()); + em.merge(this.article); + facesContext.addMessage(null, new FacesMessage("article:" + article.getTitle() + " persisted")); + return "persisted"; + } + + public String delete(Article article) + { + em.remove(article); + facesContext.addMessage(null, new FacesMessage("article:" + article.getTitle() + " deleted")); + return "deleted"; + } + + public List<Article> getAllArticles() + { + return em.createQuery("from Article a order by a.id desc").getResultList(); + } + + public void loadArticle() + { + if (aid != null) + { + this.article = findArticleById(Long.valueOf(aid)); + } + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParam.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParam.java b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParam.java new file mode 100644 index 0000000..6ce615c --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParam.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.deltaspike.example; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; + +/** + * + * @author subaochen<subaoc...@126.com> + */ +@Qualifier +@Retention(RUNTIME) +@Target({ METHOD, FIELD, PARAMETER, TYPE }) +public @interface HttpParam +{ + @Nonbinding String value(); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParams.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParams.java b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParams.java new file mode 100644 index 0000000..91938c5 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/HttpParams.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.deltaspike.example; + +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.faces.context.FacesContext; +import javax.servlet.ServletRequest; + +/** + * + * @author subaochen<subaoc...@126.com> + */ +public class HttpParams +{ + + @Produces + @HttpParam("") + String getParamValue(InjectionPoint ip) + { + ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); + return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value()); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/LogProducer.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/LogProducer.java b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/LogProducer.java new file mode 100644 index 0000000..6467a20 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/LogProducer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.deltaspike.example; + +import java.util.logging.Logger; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; + +/** + * + * @author Su Baochen <subaoc...@126.com> + */ +public class LogProducer +{ + + @Produces + Logger createLogger(final InjectionPoint ip) + { + return Logger.getLogger(ip.getMember().getDeclaringClass().getName()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Resources.java ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Resources.java b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Resources.java new file mode 100644 index 0000000..1d62258 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/java/org/apache/deltaspike/example/Resources.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.deltaspike.example; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.Disposes; +import javax.enterprise.inject.Produces; +import javax.faces.context.FacesContext; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; + +// @TODO why ApplicatonScoped? +@ApplicationScoped +public class Resources +{ + + @PersistenceUnit + private EntityManagerFactory entityManagerFactory; + + @Produces + @Default + @RequestScoped + public EntityManager create() + { + return this.entityManagerFactory.createEntityManager(); + } + + public void dispose(@Disposes @Default EntityManager entityManager) + { + if (entityManager.isOpen()) + { + entityManager.close(); + } + } + + @Produces + @RequestScoped + public FacesContext produceFacesContext() + { + return FacesContext.getCurrentInstance(); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/resources/META-INF/persistence.xml b/deltaspike/examples/jpa-examples/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..654ed56 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.0" + xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> + <persistence-unit name="primary" transaction-type="JTA"> + <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> + <class>org.apache.deltaspike.example.Article</class> + + <properties> + <property name="hibernate.hbm2ddl.auto" value="create" /> + <property name="hibernate.show_sql" value="true" /> + </properties> + </persistence-unit> +</persistence> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/beans.xml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/beans.xml b/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..e9f29b3 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> +<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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/faces-config.xml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/faces-config.xml b/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..8b8e365 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,40 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- +~ Licensed to the Apache Software Foundation (ASF) under one +~ or more contributor license agreements. See the NOTICE file +~ distributed with this work for additional information +~ regarding copyright ownership. The ASF licenses this file +~ to you 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. +--> +<faces-config 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" + version="2.0"> + <navigation-rule> + <from-view-id>/add.xhtml</from-view-id> + <navigation-case> + <from-outcome>persisted</from-outcome> + <to-view-id>/list.xhtml</to-view-id> + </navigation-case> + </navigation-rule> + + <navigation-rule> + <from-view-id>/list.xhtml</from-view-id> + <navigation-case> + <from-outcome>deleted</from-outcome> + <to-view-id>/list.xhtml</to-view-id> + </navigation-case> + </navigation-rule> + +</faces-config> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/web.xml b/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..76f7ba6 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> +<web-app 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-app_3_0.xsd" + version="3.0"> + + <context-param> + <param-name>javax.faces.DEFAULT_SUFFIX</param-name> + <param-value>.xhtml</param-value> + </context-param> + + <servlet> + <servlet-name>Faces Servlet</servlet-name> + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + + <servlet-mapping> + <servlet-name>Faces Servlet</servlet-name> + <url-pattern>*.xhtml</url-pattern> + </servlet-mapping> + + <welcome-file-list> + <welcome-file>index.xhtml</welcome-file> + </welcome-file-list> +</web-app> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/webapp/add.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/webapp/add.xhtml b/deltaspike/examples/jpa-examples/src/main/webapp/add.xhtml new file mode 100644 index 0000000..968a6ff --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/webapp/add.xhtml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. +--> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://xmlns.jcp.org/jsf/core"> + <f:metadata> + <f:viewAction action="#{articleController.loadArticle}"/> + </f:metadata> + + <h:head> + <title>Simple JPA page</title> + </h:head> + + <h:body> + <h1>#{empty(articleController.article.id) ? 'Add New ' : 'Edit '}Article</h1> + <h:form> + <h:panelGrid columns="2"> + <h:outputLabel value="title:" for="title"/> + <h:inputText id="title" value="#{articleController.article.title}" size="20"/> + + <h:outputLabel value="content:" for="content"/> + <h:inputTextarea id="content" value="#{articleController.article.content}" cols="20" rows="5"/> + + <h:commandButton value="#{empty(articleController.article.id) ? 'Add New ' : 'Edit '}Article" + action="#{articleController.persist}"/> + </h:panelGrid> + </h:form> + + </h:body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/webapp/index.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/webapp/index.xhtml b/deltaspike/examples/jpa-examples/src/main/webapp/index.xhtml new file mode 100644 index 0000000..43da4e3 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/webapp/index.xhtml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. +--> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html"> + + <h:head> + <title>Simple JPA page</title> + </h:head> + + <h:body> + <h1>Deltaspike JPA module examples</h1> + <h:link value=">>Add new article" outcome="add.xhtml" /> + <br /> + <h:link value=">>article list" outcome="list.xhtml" /> + <br /> + </h:body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/jpa-examples/src/main/webapp/list.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/jpa-examples/src/main/webapp/list.xhtml b/deltaspike/examples/jpa-examples/src/main/webapp/list.xhtml new file mode 100644 index 0000000..bdfd666 --- /dev/null +++ b/deltaspike/examples/jpa-examples/src/main/webapp/list.xhtml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. +--> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html"> + + <h:head> + <title>Simple JPA page</title> + </h:head> + + <h:body> + <h1>Article List</h1> + <h:messages style="color:red"/> + + <h:form> + <h:dataTable value="#{articleController.allArticles}" var="article" border="1"> + <h:column> + <f:facet name="header">ID</f:facet> + <h:outputText value="#{article.id}"/> + </h:column> + <h:column> + <f:facet name="header">title</f:facet> + <h:outputText value="#{article.title}"/> + </h:column> + <h:column> + <f:facet name="header">date</f:facet> + <h:outputText value="#{article.date}"/> + </h:column> + <h:column> + <f:facet name="header">operation</f:facet> + <h:link value="edit" outcome="add.xhtml"> + <f:param name="aid" value="#{article.id}"/> + </h:link> + #{' '} + <h:commandLink value="delete" action="#{articleController.delete(article)}"/> + </h:column> + </h:dataTable> + </h:form> + + <h:link value=">>add new article" outcome="add.xhtml"/> + </h:body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fcb21a15/deltaspike/examples/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/examples/pom.xml b/deltaspike/examples/pom.xml index cfbe3d1..677963c 100644 --- a/deltaspike/examples/pom.xml +++ b/deltaspike/examples/pom.xml @@ -59,6 +59,7 @@ <module>security-requested-page-after-login-cdi</module> <module>security-requested-page-after-login-picketlink</module> <module>scheduler-playground</module> + <module>jpa-examples</module> </modules> <properties> @@ -94,6 +95,12 @@ <skip>${deploy.skip}</skip> <!-- we don't deploy our samples upstream --> </configuration> </plugin> + <!-- run mvn wildfly:deploy to deploy the sample to wildfly --> + <plugin> + <groupId>org.wildfly.plugins</groupId> + <artifactId>wildfly-maven-plugin</artifactId> + <version>1.0.1.Final</version> + </plugin> </plugins> </build> -</project> \ No newline at end of file +</project>