[seam-commits] Seam SVN: r12470 - in modules/faces/trunk/examples/tiny-url: src/main/java/org/jboss/seam/faces/examples and 5 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Apr 13 11:35:13 EDT 2010
Author: lincolnthree
Date: 2010-04-13 11:35:12 -0400 (Tue, 13 Apr 2010)
New Revision: 12470
Added:
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/LinkBean.java
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/RedirectBean.java
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/TinyLink.java
modules/faces/trunk/examples/tiny-url/src/main/resources/META-INF/
modules/faces/trunk/examples/tiny-url/src/main/resources/META-INF/persistence.xml
Removed:
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java
Modified:
modules/faces/trunk/examples/tiny-url/pom.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml
Log:
Example is functional with MySQL -- needs to be switched back to Derby or embedded HSQLDB if possible.
Modified: modules/faces/trunk/examples/tiny-url/pom.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/pom.xml 2010-04-13 14:34:43 UTC (rev 12469)
+++ modules/faces/trunk/examples/tiny-url/pom.xml 2010-04-13 15:35:12 UTC (rev 12470)
@@ -19,18 +19,16 @@
</repository>
</repositories>
+ <properties>
+ <hibernate.version>3.5.0-Final</hibernate.version>
+ </properties>
+
<dependencies>
<dependency>
- <groupId>org.jboss.seam</groupId>
+ <groupId>org.jboss.seam.faces</groupId>
<artifactId>seam-faces</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.9.RC1</version>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>javax</groupId>
@@ -52,6 +50,28 @@
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>${hibernate.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>${hibernate.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>${hibernate.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.10</version>
+ </dependency>
+
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
Deleted: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java 2010-04-13 14:34:43 UTC (rev 12469)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java 2010-04-13 15:35:12 UTC (rev 12470)
@@ -1,54 +0,0 @@
-/**
- *
- */
-package org.jboss.seam.faces.examples;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.ConversationScoped;
-import javax.inject.Named;
-
-import org.jboss.seam.faces.context.conversation.Begin;
-import org.jboss.seam.faces.context.conversation.End;
-
-/**
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- *
- */
- at Named
- at ConversationScoped
-public class LinkBean implements Serializable
-{
- private static final long serialVersionUID = -2209547152337410725L;
-
- private String key;
- private String url;
-
- @Begin
- @End
- public String createLink()
- {
- System.out.println("Created link: [ " + key + " => " + url + " ]");
- return "pretty:edit";
- }
-
- public String getKey()
- {
- return key;
- }
-
- public void setKey(final String key)
- {
- this.key = key;
- }
-
- public String getUrl()
- {
- return url;
- }
-
- public void setUrl(final String url)
- {
- this.url = url;
- }
-}
Deleted: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java 2010-04-13 14:34:43 UTC (rev 12469)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java 2010-04-13 15:35:12 UTC (rev 12470)
@@ -1,45 +0,0 @@
-/**
- *
- */
-package org.jboss.seam.faces.examples;
-
-import java.io.IOException;
-
-import javax.enterprise.context.RequestScoped;
-import javax.faces.context.FacesContext;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- *
- */
- at Named
- at RequestScoped
-public class RedirectBean
-{
- @Inject
- FacesContext context;
-
- private String key;
-
- public void send() throws IOException
- {
- String url = "http://ocpsoft.com";
- System.out.println("Sent redirect for key: " + key);
- HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
- response.sendRedirect(url);
- context.responseComplete();
- }
-
- public String getKey()
- {
- return key;
- }
-
- public void setKey(final String key)
- {
- this.key = key;
- }
-}
Copied: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/LinkBean.java (from rev 12400, modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java)
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/LinkBean.java (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/LinkBean.java 2010-04-13 15:35:12 UTC (rev 12470)
@@ -0,0 +1,98 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.examples.tinyurl;
+
+import java.io.Serializable;
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateful;
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.sql.DataSource;
+
+import org.jboss.seam.faces.context.conversation.Begin;
+import org.jboss.seam.faces.context.conversation.End;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+ at Named
+ at ConversationScoped
+ at Stateful
+public class LinkBean implements Serializable
+{
+ private static final long serialVersionUID = -2209547152337410725L;
+
+ @PersistenceContext
+ private EntityManager em;
+
+ @Resource(name = "java:app/Application_Level_DataSource")
+ private DataSource ds;
+
+ private TinyLink link = new TinyLink();
+
+ @Begin
+ @End
+ public String createLink() throws SQLException
+ {
+ System.out.println("Created link: [ " + link.getName() + " => " + link.getTarget() + " ]");
+ em.persist(link);
+ // ds.getConnection();
+ return "pretty:create";
+ }
+
+ @SuppressWarnings("unchecked")
+ public TinyLink getByKey(final String key)
+ {
+ Query query = em.createQuery("from TinyLink t where t.name=:key", TinyLink.class);
+ query.setParameter("key", key);
+ List<TinyLink> resultList = query.getResultList();
+ if (resultList.isEmpty())
+ {
+ return new TinyLink();
+ }
+ return resultList.get(0);
+ }
+
+ public String format(final String link)
+ {
+ if (link != null)
+ {
+ String result = link.trim();
+ if (!result.matches("(http|ftp)://.*"))
+ {
+ result = "http://" + result;
+ }
+ return result;
+ }
+ return "";
+ }
+
+ public String deleteAll()
+ {
+ em.createQuery("delete from TinyLink").executeUpdate();
+ return "pretty:";
+ }
+
+ public List<TinyLink> getLinks()
+ {
+ return em.createQuery("from TinyLink").getResultList();
+ }
+
+ public TinyLink getLink()
+ {
+ return link;
+ }
+
+ public void setLink(final TinyLink link)
+ {
+ this.link = link;
+ }
+}
Copied: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/RedirectBean.java (from rev 12400, modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java)
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/RedirectBean.java (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/RedirectBean.java 2010-04-13 15:35:12 UTC (rev 12470)
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.examples.tinyurl;
+
+import java.io.IOException;
+
+import javax.enterprise.context.RequestScoped;
+import javax.faces.context.FacesContext;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+ at Named
+ at RequestScoped
+public class RedirectBean
+{
+ @Inject
+ FacesContext context;
+
+ @Inject
+ LinkBean linkBean;
+
+ private String name;
+
+ public void send() throws IOException
+ {
+ String url = linkBean.getByKey(name).getTarget();
+ System.out.println("Sent redirect for key: " + name + " => " + url);
+ HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
+ response.sendRedirect(linkBean.format(url));
+ context.responseComplete();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(final String key)
+ {
+ this.name = key;
+ }
+}
Added: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/TinyLink.java
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/TinyLink.java (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/tinyurl/TinyLink.java 2010-04-13 15:35:12 UTC (rev 12470)
@@ -0,0 +1,136 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.examples.tinyurl;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.validation.constraints.Pattern;
+
+/**
+ * Represents a mapping between a Tiny URL and its destination URL.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+ at Entity
+public class TinyLink
+{
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+
+ @Column(unique = true, updatable = false)
+ private String uid;
+
+ @Column(unique = true, updatable = false)
+ private String name;
+
+ @Pattern(regexp = "((http|ftp)://)?(www.)?((\\w+\\.)+(\\w+)(/.*)?)", message = "Must be a valid web address")
+ private String target;
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(final Long id)
+ {
+ this.id = id;
+ }
+
+ public String getUid()
+ {
+ return uid;
+ }
+
+ public void setUid(final String key)
+ {
+ this.uid = key;
+ }
+
+ public String getTarget()
+ {
+ return target;
+ }
+
+ public void setTarget(final String target)
+ {
+ this.target = target;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((uid == null) ? 0 : uid.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ TinyLink other = (TinyLink) obj;
+ if (id == null)
+ {
+ if (other.id != null)
+ {
+ return false;
+ }
+ }
+ else if (!id.equals(other.id))
+ {
+ return false;
+ }
+ if (uid == null)
+ {
+ if (other.uid != null)
+ {
+ return false;
+ }
+ }
+ else if (!uid.equals(other.uid))
+ {
+ return false;
+ }
+ if (name == null)
+ {
+ if (other.name != null)
+ {
+ return false;
+ }
+ }
+ else if (!name.equals(other.name))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(final String name)
+ {
+ this.name = name;
+ }
+}
Added: modules/faces/trunk/examples/tiny-url/src/main/resources/META-INF/persistence.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/resources/META-INF/persistence.xml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/resources/META-INF/persistence.xml 2010-04-13 15:35:12 UTC (rev 12470)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence 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"
+ version="2.0">
+ <persistence-unit name="example" transaction-type="JTA">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <jta-data-source> jdbc/mysql </jta-data-source>
+ <!--
+ <jta-data-source> jdbc/__default </jta-data-source>
+ <jta-data-source> java:app/Application_Level_DataSource </jta-data-source>
+ -->
+ <exclude-unlisted-classes>false</exclude-unlisted-classes>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
+ </properties>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
Modified: modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml 2010-04-13 14:34:43 UTC (rev 12469)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml 2010-04-13 15:35:12 UTC (rev 12470)
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/2.0.4
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd">
- <rewrite trailingSlash="remove" toCase="lowercase" />
+ <rewrite match="^/.+$" trailingSlash="remove" toCase="lowercase" />
<url-mapping id="create">
<pattern value="/" />
@@ -11,13 +11,13 @@
</url-mapping>
<url-mapping id="redirect">
- <pattern value="/#{key}" />
+ <pattern value="/#{name}" />
<view-id>/faces/index.xhtml</view-id>
<action phaseId="RENDER_RESPONSE">#{redirectBean.send}</action>
</url-mapping>
<url-mapping id="edit">
- <pattern value="/#{key}/edit" />
+ <pattern value="/#{name}/edit" />
<view-id>/faces/editLink.xhtml</view-id>
<action phaseId="INVOKE_APPLICATION">#{linkBean.send}</action>
</url-mapping>
Modified: modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml 2010-04-13 14:34:43 UTC (rev 12469)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml 2010-04-13 15:35:12 UTC (rev 12470)
@@ -1,24 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
-<web-app version="3.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-app_3_0.xsd">
- <context-param>
- <param-name>javax.faces.PROJECT_STAGE</param-name>
- <param-value>Development</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>/faces/*</url-pattern>
- </servlet-mapping>
- <session-config>
- <session-timeout>
- 30
- </session-timeout>
- </session-config>
- <welcome-file-list>
- <welcome-file>faces/index.xhtml</welcome-file>
- </welcome-file-list>
+<web-app version="3.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-app_3_0.xsd">
+
+ <data-source>
+ <name>java:app/Application_Level_DataSource</name>
+ <class-name>org.hsqldb.jdbc.jdbcDataSource</class-name>
+ <url>jdbc:hsqldb:file:aname</url>
+ <user>sa</user>
+ <password>sa</password>
+ <property>
+ <name>hibernate.dialect</name>
+ <value>org.hibernate.dialect.HSQLDialect</value>
+ </property>
+ </data-source>
+ <data-source>
+ <name>java:app/mysql</name>
+ <class-name>org.hsqldb.jdbc.jdbcDataSource</class-name>
+ <url>jdbc:hsqldb:file:aname</url>
+ <user>sa</user>
+ <password>sa</password>
+ <property>
+ <name>hibernate.dialect</name>
+ <value>org.hibernate.dialect.HSQLDialect</value>
+ </property>
+ </data-source>
+
+
+ <context-param>
+ <param-name>javax.faces.PROJECT_STAGE</param-name>
+ <param-value>Development</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>client</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>/faces/*</url-pattern>
+ </servlet-mapping>
+ <session-config>
+ <session-timeout>30</session-timeout>
+ </session-config>
+ <welcome-file-list>
+ <welcome-file>faces/index.xhtml</welcome-file>
+ </welcome-file-list>
</web-app>
Modified: modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml 2010-04-13 14:34:43 UTC (rev 12469)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml 2010-04-13 15:35:12 UTC (rev 12470)
@@ -1,27 +1,45 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!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://java.sun.com/jsf/core"
- xmlns:ui="http://java.sun.com/jsf/facelets">
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
- <f:metadata>
- <f:viewParam name="key" value="#{redirectBean.key}" />
- </f:metadata>
+<f:metadata>
+ <f:viewParam name="name" value="#{redirectBean.name}" />
+</f:metadata>
- <h:head>
- </h:head>
+<h:head>
+</h:head>
- <h:body>
- <h:form>
+<h:body>
+ <h:form>
+ <fieldset><f:validateBean>
<h3>Create a new link:</h3>
- <label for="key">Key: <h:messages for="key"/><br/></label>
- <h:inputText id="key" value="#{createLinkBean.key}" /><br/>
- <label for="url">Link URL: <h:messages for="url"/><br/></label>
- <h:inputText id="url" value="#{createLinkBean.url}" /><br/>
- <h:commandButton action ="#{createLinkBean.createLink}" value="Create" />
- </h:form>
- </h:body>
+ <label for="url">Link URL: <h:messages for="url" /><br />
+ </label>
+ <h:inputText id="url" value="#{linkBean.link.target}" />
+ <br />
+ <label for="name">Name (optional): <h:messages for="name" /><br />
+ </label>
+ <h:inputText id="name" value="#{linkBean.link.name}" />
+ <br />
+ </f:validateBean></fieldset>
+ <h:commandButton action="#{linkBean.createLink}" value="Create" />
+ <br />
+ <ui:repeat value="#{linkBean.links}" var="link">
+ #{link.id} -
+ <h:link outcome="/index" value="#{link.name}">
+ <f:param name="name" value="#{link.name}" />
+ </h:link>
+ <br />
+ </ui:repeat>
+
+ <h:commandButton action="#{linkBean.deleteAll}" value="deleteAll"
+ immediate="true" rendered="#{!linkBean.links.isEmpty()}" />
+ </h:form>
+</h:body>
+
</html>
More information about the seam-commits
mailing list