[jboss-cvs] jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace ...

Shane Bryzak Shane_Bryzak at symantec.com
Mon Jan 15 04:48:13 EST 2007


  User: sbryzak2
  Date: 07/01/15 04:48:13

  Modified:    examples/seamspace/src/org/jboss/seam/example/seamspace       
                        BlogAction.java BlogComment.java BlogLocal.java
                        LoginAction.java MemberBlog.java
  Removed:     examples/seamspace/src/org/jboss/seam/example/seamspace       
                        CommentAction.java CommentLocal.java
  Log:
  blog comments
  
  Revision  Changes    Path
  1.5       +34 -2     jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BlogAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogAction.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- BlogAction.java	12 Jan 2007 13:24:32 -0000	1.4
  +++ BlogAction.java	15 Jan 2007 09:48:13 -0000	1.5
  @@ -1,5 +1,8 @@
   package org.jboss.seam.example.seamspace;
   
  +import static org.jboss.seam.ScopeType.CONVERSATION;
  +
  +import java.util.Date;
   import java.util.List;
   
   import javax.ejb.Remove;
  @@ -7,12 +10,14 @@
   import javax.persistence.EntityManager;
   import javax.persistence.NoResultException;
   
  +import org.jboss.seam.annotations.Begin;
   import org.jboss.seam.annotations.Destroy;
   import org.jboss.seam.annotations.Factory;
   import org.jboss.seam.annotations.In;
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Out;
   import org.jboss.seam.annotations.RequestParameter;
  +import org.jboss.seam.annotations.security.Restrict;
   
   @Stateful
   @Name("blog")
  @@ -33,9 +38,15 @@
      @Out(required = false)
      private List memberBlogs;
      
  -   @Out(required = false)
  +   @In(required = false) @Out(required = false)
      private MemberBlog selectedBlog;
      
  +   @In(required = false) @Out(required = false, scope = CONVERSATION)
  +   private BlogComment comment;   
  +   
  +   @In
  +   private Member authenticatedMember;
  +   
      /**
       * Returns the 5 latest blog entries for a member
       */
  @@ -63,7 +74,7 @@
      /**
       * Used to read a single blog entry for a member
       */
  -   @Factory("selectedBlog")
  +   @Factory("selectedBlog") @Begin  
      public void getBlog()
      {
         try
  @@ -77,6 +88,27 @@
         catch (NoResultException ex) { }
      }
      
  +   @Factory("comment") @Restrict @Begin(join = true)
  +   public void createComment()
  +   {      
  +      comment = new BlogComment();
  +      comment.setCommentor(authenticatedMember);
  +      
  +      if (selectedBlog == null && name != null && blogId != null)
  +         getBlog();         
  +      
  +      comment.setBlog(selectedBlog);
  +   }
  +   
  +   public void saveComment()
  +   {      
  +      comment.setCommentDate(new Date());
  +      entityManager.persist(comment);
  +      
  +      // Reload the blog entry
  +      entityManager.refresh(selectedBlog);
  +   }     
  +   
      @Remove @Destroy
      public void destroy() { }     
   }
  
  
  
  1.3       +2 -1      jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogComment.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BlogComment.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogComment.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- BlogComment.java	11 Jan 2007 02:23:16 -0000	1.2
  +++ BlogComment.java	15 Jan 2007 09:48:13 -0000	1.3
  @@ -5,6 +5,7 @@
   import java.util.Date;
   
   import javax.persistence.Entity;
  +import javax.persistence.GeneratedValue;
   import javax.persistence.Id;
   import javax.persistence.JoinColumn;
   import javax.persistence.ManyToOne;
  @@ -27,7 +28,7 @@
      private Date commentDate;
      private String comment;
      
  -   @Id
  +   @Id @GeneratedValue
      public Integer getCommentId()
      {
         return commentId;
  
  
  
  1.4       +2 -0      jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogLocal.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BlogLocal.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/BlogLocal.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- BlogLocal.java	11 Jan 2007 02:23:16 -0000	1.3
  +++ BlogLocal.java	15 Jan 2007 09:48:13 -0000	1.4
  @@ -10,5 +10,7 @@
      List getLatestBlogs();
      void getMemberBlogs();
      void getBlog();
  +   void createComment();
  +   void saveComment();
      void destroy();
   }
  
  
  
  1.10      +6 -3      jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/LoginAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LoginAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/LoginAction.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- LoginAction.java	10 Jan 2007 03:13:15 -0000	1.9
  +++ LoginAction.java	15 Jan 2007 09:48:13 -0000	1.10
  @@ -43,6 +43,9 @@
      @In(create=true)
      private EntityManager entityManager;   
      
  +   @Out(required = false)
  +   private Member authenticatedMember;
  +   
      public void login()
      {
         try
  @@ -63,13 +66,13 @@
      {
         try
         {            
  -         Member member = (Member) entityManager.createQuery(
  +         authenticatedMember = (Member) entityManager.createQuery(
               "from Member where username = :username and password = :password")
               .setParameter("username", username)
               .setParameter("password", password)
               .getSingleResult();
   
  -         for (MemberRole mr : member.getRoles())
  +         for (MemberRole mr : authenticatedMember.getRoles())
               roles.add(mr.getName());
            
            return true;
  
  
  
  1.4       +14 -1     jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/MemberBlog.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MemberBlog.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seamspace/src/org/jboss/seam/example/seamspace/MemberBlog.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- MemberBlog.java	11 Jan 2007 02:23:16 -0000	1.3
  +++ MemberBlog.java	15 Jan 2007 09:48:13 -0000	1.4
  @@ -2,11 +2,12 @@
   
   import java.io.Serializable;
   import java.text.SimpleDateFormat;
  +import java.util.Collections;
  +import java.util.Comparator;
   import java.util.Date;
   import java.util.List;
   
   import javax.persistence.Entity;
  -import javax.persistence.FetchType;
   import javax.persistence.Id;
   import javax.persistence.JoinColumn;
   import javax.persistence.ManyToOne;
  @@ -102,6 +103,18 @@
      }
      
      @Transient
  +   public List<BlogComment> getSortedComments()
  +   {
  +      Collections.sort(comments, new Comparator<BlogComment>() {
  +         public int compare(BlogComment o1, BlogComment o2) {
  +            return (int) (o1.getCommentDate().getTime() - o2.getCommentDate().getTime());
  +         }
  +      });
  +      
  +      return comments;
  +   }
  +   
  +   @Transient
      public int getCommentCount()
      {
         return comments.size();
  
  
  



More information about the jboss-cvs-commits mailing list