Author: shane.bryzak(a)jboss.com
Date: 2008-09-17 19:30:31 -0400 (Wed, 17 Sep 2008)
New Revision: 9009
Added:
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/CommentAction.java
Modified:
trunk/examples/seamspace/resources/META-INF/security-rules.drl
trunk/examples/seamspace/resources/WEB-INF/components.xml
trunk/examples/seamspace/resources/WEB-INF/pages.xml
trunk/examples/seamspace/resources/WEB-INF/web.xml
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogAction.java
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java
trunk/examples/seamspace/view/blogentry.xhtml
trunk/examples/seamspace/view/comment.xhtml
trunk/examples/seamspace/view/home.xhtml
trunk/examples/seamspace/view/register.xhtml
Log:
restructured better
Modified: trunk/examples/seamspace/resources/META-INF/security-rules.drl
===================================================================
--- trunk/examples/seamspace/resources/META-INF/security-rules.drl 2008-09-17 22:43:52 UTC
(rev 9008)
+++ trunk/examples/seamspace/resources/META-INF/security-rules.drl 2008-09-17 23:30:31 UTC
(rev 9009)
@@ -124,13 +124,12 @@
no-loop
activation-group "permissions"
when
- check: PermissionCheck(target == "blogComment", action == "create",
granted == false)
+ check: PermissionCheck(target == "blogComment", action == "insert",
granted == false)
Role(name == "user")
then
check.grant();
end
-
# This rule grants permission for users to create their own blog entries
rule CreateBlog
no-loop
Modified: trunk/examples/seamspace/resources/WEB-INF/components.xml
===================================================================
--- trunk/examples/seamspace/resources/WEB-INF/components.xml 2008-09-17 22:43:52 UTC (rev
9008)
+++ trunk/examples/seamspace/resources/WEB-INF/components.xml 2008-09-17 23:30:31 UTC (rev
9009)
@@ -29,21 +29,20 @@
<!--security:identity-manager
identity-store="#{ldapIdentityStore}"/-->
- <!--security:ldap-identity-store
- server-address="60.241.32.50"
+ <security:ldap-identity-store name="ldapIdentityStore"
+ server-address="localhost"
bind-DN="cn=Manager,dc=bryzak,dc=com"
bind-credentials="secret"
user-DN-prefix="uid="
user-DN-suffix=",ou=Person,dc=bryzak,dc=com"
role-DN-prefix="cn="
- role-DN-suffix=",ou=Roles,dc=bryzak,dc=com"
+ role-DN-suffix=",ou=Role,dc=bryzak,dc=com"
user-context-DN="ou=Person,dc=bryzak,dc=com"
- role-context-DN="ou=Roles,dc=bryzak,dc=com"
+ role-context-DN="ou=Role,dc=bryzak,dc=com"
user-role-attribute="roles"
role-name-attribute="cn"
user-object-classes="person,uidObject"
- enabled-attribute="enabled"
- /-->
+ />
<security:jpa-permission-store
user-permission-class="org.jboss.seam.example.seamspace.AccountPermission"/>
@@ -55,7 +54,7 @@
<web:multipart-filter create-temp-files="true"
max-request-size="1000000"
- url-pattern="*.seam"/>
+ url-pattern="*.seam"/>
<web:context-filter url-pattern="/content/*"/>
Modified: trunk/examples/seamspace/resources/WEB-INF/pages.xml
===================================================================
--- trunk/examples/seamspace/resources/WEB-INF/pages.xml 2008-09-17 22:43:52 UTC (rev
9008)
+++ trunk/examples/seamspace/resources/WEB-INF/pages.xml 2008-09-17 23:30:31 UTC (rev
9009)
@@ -18,10 +18,7 @@
<page view-id="/comment.xhtml" login-required="true">
<restrict/>
- <param name="name" value="#{blog.name}"/>
- <param name="blogId" value="#{blog.blogId}"/>
-
- <navigation from-action="#{blog.saveComment}">
+ <navigation from-action="#{commentAction.saveComment}">
<redirect view-id="/blogentry.xhtml"/>
</navigation>
</page>
@@ -41,7 +38,7 @@
<page view-id="/register2.xhtml">
<navigation from-action="#{register.uploadPicture}">
<redirect view-id="/profile.xhtml">
- <param name="name" value="#{newMember.memberName}"/>
+ <param name="name"
value="#{register.member.memberName}"/>
</redirect>
</navigation>
</page>
@@ -60,6 +57,10 @@
<page view-id="/blogentry.xhtml">
<param name="name" value="#{blog.name}"/>
<param name="blogId" value="#{blog.blogId}"/>
+
+ <navigation from-action="#{commentAction.createComment}">
+ <redirect view-id="/comment.xhtml"/>
+ </navigation>
</page>
Modified: trunk/examples/seamspace/resources/WEB-INF/web.xml
===================================================================
--- trunk/examples/seamspace/resources/WEB-INF/web.xml 2008-09-17 22:43:52 UTC (rev 9008)
+++ trunk/examples/seamspace/resources/WEB-INF/web.xml 2008-09-17 23:30:31 UTC (rev 9009)
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<web-app version="2.5"
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_2_5.xsd">
+ <display-name>SeamSpace Example</display-name>
+
<!-- RichFaces -->
<context-param>
@@ -18,6 +19,16 @@
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
+ <servlet>
+ <servlet-name>Seam Resource Servlet</servlet-name>
+
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Seam Resource Servlet</servlet-name>
+ <url-pattern>/seam/resource/*</url-pattern>
+ </servlet-mapping>
+
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
@@ -28,16 +39,6 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
- <servlet>
- <servlet-name>Seam Resource Servlet</servlet-name>
-
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>Seam Resource Servlet</servlet-name>
- <url-pattern>/seam/resource/*</url-pattern>
- </servlet-mapping>
-
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
Modified: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogAction.java
===================================================================
---
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogAction.java 2008-09-17
22:43:52 UTC (rev 9008)
+++
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogAction.java 2008-09-17
23:30:31 UTC (rev 9009)
@@ -15,7 +15,6 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.security.Insert;
@Scope(CONVERSATION)
@Name("blog")
@@ -30,9 +29,6 @@
@In(required = false) @Out(required = false)
private MemberBlog selectedBlog;
- @In(required = false) @Out(required = false, scope = CONVERSATION)
- private BlogComment comment;
-
@In(required = false)
private Member authenticatedMember;
@@ -52,31 +48,8 @@
.getSingleResult();
}
catch (NoResultException ex) { }
- }
+ }
- @Factory("comment") @Insert(BlogComment.class) @Begin(join = true)
- public void createComment()
- {
- comment = new BlogComment();
- comment.setCommentor(authenticatedMember);
-
- if (selectedBlog == null && name != null && blogId != null)
- getBlog();
-
- comment.setBlog(selectedBlog);
- }
-
- @End
- public void saveComment()
- {
- comment.setCommentDate(new Date());
- entityManager.persist(comment);
-
- // Reload the blog entry
- selectedBlog = (MemberBlog) entityManager.find(MemberBlog.class,
- comment.getBlog().getBlogId());
- }
-
@Begin
public void createEntry()
{
Added: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/CommentAction.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/CommentAction.java
(rev 0)
+++
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/CommentAction.java 2008-09-17
23:30:31 UTC (rev 9009)
@@ -0,0 +1,53 @@
+package org.jboss.seam.example.seamspace;
+
+import static org.jboss.seam.ScopeType.CONVERSATION;
+
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.annotations.Begin;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.security.Insert;
+import org.jboss.seam.core.Conversation;
+
+@Scope(CONVERSATION)
+@Name("commentAction")
+public class CommentAction
+{
+ @In
+ private EntityManager entityManager;
+
+ private BlogComment comment;
+
+ @In(required = false)
+ private Member authenticatedMember;
+
+ @In(required = false)
+ private MemberBlog selectedBlog;
+
+ @Begin(nested = true) @Insert(BlogComment.class)
+ public void createComment()
+ {
+ comment = new BlogComment();
+ comment.setCommentor(authenticatedMember);
+ comment.setBlog(selectedBlog);
+ }
+
+ public void saveComment()
+ {
+ comment.setCommentDate(new Date());
+ entityManager.persist(comment);
+
+ entityManager.refresh(selectedBlog);
+
+ Conversation.instance().end();
+ }
+
+ public BlogComment getComment()
+ {
+ return comment;
+ }
+}
Modified:
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java
===================================================================
---
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java 2008-09-17
22:43:52 UTC (rev 9008)
+++
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/RegisterAction.java 2008-09-17
23:30:31 UTC (rev 9009)
@@ -10,11 +10,9 @@
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.End;
-import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.security.Identity;
@@ -26,8 +24,7 @@
@Name("register")
public class RegisterAction
{
- @In(required = false) @Out
- private Member newMember;
+ private Member member;
@In
private EntityManager entityManager;
@@ -55,15 +52,15 @@
private boolean verified;
- @Factory("newMember") @Begin(join = true)
+ @Begin
public void start()
{
- newMember = new Member();
+ member = new Member();
}
public void next()
{
- newMember.setGender(Member.Gender.valueOf(gender.toLowerCase()));
+ member.setGender(Member.Gender.valueOf(gender.toLowerCase()));
verified = (confirm != null && confirm.equals(password));
@@ -79,28 +76,28 @@
// The user *may* have been created from the user manager screen. In that
// case, create a dummy Member record just for the purpose of demonstrating the
// identity management API
- if (newMember == null)
+ if (member == null)
{
- newMember = new Member();
- newMember.setMemberName(account.getUsername());
- newMember.setGender(Member.Gender.male);
- newMember.setFirstName("John");
- newMember.setLastName("Doe");
- newMember.setEmail(account.getUsername() + "(a)nowhere.com");
- newMember.setDob(new Date());
- newMember.setMemberSince(new Date());
- entityManager.persist(newMember);
+ member = new Member();
+ member.setMemberName(account.getUsername());
+ member.setGender(Member.Gender.male);
+ member.setFirstName("John");
+ member.setLastName("Doe");
+ member.setEmail(account.getUsername() + "(a)nowhere.com");
+ member.setDob(new Date());
+ member.setMemberSince(new Date());
+ entityManager.persist(member);
}
- account.setMember(newMember);
+ account.setMember(member);
this.newAccount = account;
}
@End
public void uploadPicture()
{
- newMember.setMemberSince(new Date());
- entityManager.persist(newMember);
+ member.setMemberSince(new Date());
+ entityManager.persist(member);
new RunAsOperation() {
public void execute() {
@@ -110,27 +107,32 @@
}.addRole("admin")
.run();
- newAccount.setMember(newMember);
+ newAccount.setMember(member);
newAccount = entityManager.merge(newAccount);
if (picture != null && picture.length > 0)
{
MemberImage img = new MemberImage();
img.setData(picture);
- img.setMember(newMember);
+ img.setMember(member);
img.setContentType(pictureContentType);
entityManager.persist(img);
- newMember.setPicture(img);
+ member.setPicture(img);
- newMember = entityManager.merge(newMember);
+ member = entityManager.merge(member);
}
// Login the user
- identity.setUsername(username);
- identity.setPassword(password);
+ identity.getCredentials().setUsername(username);
+ identity.getCredentials().setPassword(password);
identity.login();
}
+ public Member getMember()
+ {
+ return member;
+ }
+
public String getUsername()
{
return username;
Modified: trunk/examples/seamspace/view/blogentry.xhtml
===================================================================
--- trunk/examples/seamspace/view/blogentry.xhtml 2008-09-17 22:43:52 UTC (rev 9008)
+++ trunk/examples/seamspace/view/blogentry.xhtml 2008-09-17 23:30:31 UTC (rev 9009)
@@ -32,10 +32,7 @@
<div class="blogText"><s:formattedText
value="#{selectedBlog.text}"/></div>
<div class="blogFooter">
<s:span rendered="#{s:hasPermission(selectedBlog,
'create')}">
- [<s:link view="/comment.seam" value="Add Comment"
propagation="none">
- <f:param name="name"
value="#{selectedMember.memberName}"/>
- <f:param name="blogId"
value="#{selectedBlog.blogId}"/>
- </s:link>]
+ [<s:link action="#{commentAction.createComment}"
value="Add Comment"/>]
</s:span>
[<s:link view="/blog.seam" value="View all blog
entries" propagation="none">
<f:param name="name"
value="#{selectedMember.memberName}"/>
Modified: trunk/examples/seamspace/view/comment.xhtml
===================================================================
--- trunk/examples/seamspace/view/comment.xhtml 2008-09-17 22:43:52 UTC (rev 9008)
+++ trunk/examples/seamspace/view/comment.xhtml 2008-09-17 23:30:31 UTC (rev 9009)
@@ -10,7 +10,7 @@
<div class="errors"><h:messages
globalOnly="true"/></div>
- <s:div rendered="#{comment == null}">
+ <s:div rendered="#{commentAction.comment == null}">
Could not create comment.
</s:div>
@@ -32,12 +32,12 @@
<div class="blogText"><s:formattedText
value="#{selectedBlog.text}"/></div>
</div>
- <s:div rendered="#{comment.comment != null}">
+ <s:div rendered="#{commentAction.comment.comment != null}">
Preview:
<table class="blogComment">
<tr>
<td class="blogCommentText">
- <p><s:formattedText
value="#{comment.comment}"/></p>
+ <p><s:formattedText
value="#{commentAction.comment.comment}"/></p>
</td>
</tr>
</table>
@@ -47,10 +47,10 @@
<h:form>
<h:outputLabel for="comment">Please type your
comment</h:outputLabel><br/>
- <h:inputTextarea id="comment"
value="#{comment.comment}"/><br/>
+ <h:inputTextarea id="comment"
value="#{commentAction.comment.comment}"/><br/>
<div class="buttons">
- <h:commandButton action="#{blog.saveComment}"
value="Add comment" styleClass="action"/>
+ <h:commandButton action="#{commentAction.saveComment}"
value="Add comment" styleClass="action"/>
<h:commandButton value="Preview"
styleClass="action"/>
</div>
Modified: trunk/examples/seamspace/view/home.xhtml
===================================================================
--- trunk/examples/seamspace/view/home.xhtml 2008-09-17 22:43:52 UTC (rev 9008)
+++ trunk/examples/seamspace/view/home.xhtml 2008-09-17 23:30:31 UTC (rev 9009)
@@ -22,7 +22,7 @@
<div id="contentSide">
<div class="advertising"></div>
-
+
<h:form rendered="#{not identity.loggedIn}">
<div class="memberLogin">
<div class="loginHeader">Member Login</div>
Modified: trunk/examples/seamspace/view/register.xhtml
===================================================================
--- trunk/examples/seamspace/view/register.xhtml 2008-09-17 22:43:52 UTC (rev 9008)
+++ trunk/examples/seamspace/view/register.xhtml 2008-09-17 23:30:31 UTC (rev 9009)
@@ -24,25 +24,25 @@
<s:validateAll>
<div class="formRow">
<h:outputLabel for="email">Email
address<em>*</em></h:outputLabel>
- <h:inputText id="email" value="#{newMember.email}"
required="true" styleClass="wide"/>
+ <h:inputText id="email"
value="#{register.member.email}" required="true"
styleClass="wide"/>
<div class="validationError"><h:message
for="email"/></div>
</div>
<div class="formRow">
<h:outputLabel for="firstName">First
name<em>*</em></h:outputLabel>
- <h:inputText id="firstName"
value="#{newMember.firstName}" required="true"/>
+ <h:inputText id="firstName"
value="#{register.member.firstName}" required="true"/>
<div class="validationError"><h:message
for="firstName"/></div>
</div>
<div class="formRow">
<h:outputLabel for="lastName">Last
name<em>*</em></h:outputLabel>
- <h:inputText id="lastName"
value="#{newMember.lastName}" required="true"/>
+ <h:inputText id="lastName"
value="#{register.member.lastName}" required="true"/>
<div class="validationError"><h:message
for="lastName"/></div>
</div>
<div class="formRow">
<h:outputLabel for="memberName">Nick
name<em>*</em></h:outputLabel>
- <h:inputText id="memberName"
value="#{newMember.memberName}" required="true"/>
+ <h:inputText id="memberName"
value="#{register.member.memberName}" required="true"/>
<div class="validationError"><h:message
for="memberName"/></div>
</div>
@@ -75,7 +75,7 @@
<div class="formRow">
<h:outputLabel for="dob">Date of
birth<em>*</em></h:outputLabel>
- <rich:calendar id="dob" value="#{newMember.dob}"
required="true" datePattern="MM/dd/yyyy"
buttonIcon="images/ellipsis.png" />
+ <rich:calendar id="dob"
value="#{register.member.dob}" required="true"
datePattern="MM/dd/yyyy" buttonIcon="images/ellipsis.png" />
<div class="validationError"><h:message
for="dob"/></div>
</div>