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

Shane Bryzak sbryzak at redhat.com
Mon Apr 30 21:31:48 EDT 2007


  User: sbryzak2
  Date: 07/04/30 21:31:48

  Modified:    examples/seambay/src/org/jboss/seam/example/seambay     
                        Account.java AuctionAction.java AuctionService.java
                        User.java
  Added:       examples/seambay/src/org/jboss/seam/example/seambay     
                        RegisterAction.java
  Log:
  new user registration, other various stuff
  
  Revision  Changes    Path
  1.4       +11 -0     jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Account.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Account.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Account.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- Account.java	24 Apr 2007 12:32:22 -0000	1.3
  +++ Account.java	1 May 2007 01:31:48 -0000	1.4
  @@ -6,8 +6,15 @@
   import javax.persistence.Entity;
   import javax.persistence.GeneratedValue;
   import javax.persistence.Id;
  +import javax.persistence.Table;
  +import javax.persistence.UniqueConstraint;
  +
  +import org.hibernate.validator.Length;
  +import org.hibernate.validator.NotNull;
  +import org.hibernate.validator.Pattern;
   
   @Entity
  + at Table(uniqueConstraints = @UniqueConstraint(columnNames = "name"))
   public class Account implements Serializable
   {
      private static final long serialVersionUID = 8444287111124328025L;
  @@ -30,6 +37,10 @@
         this.accountId = accountId;
      }
      
  +   @NotNull
  +   @Length(min = 3, max = 40)
  +   @Pattern(regex="[a-zA-Z]?[a-zA-Z0-9]+", 
  +         message="Account name must start with a letter, and only contain letters or numbers")   
      public String getName()
      {
         return name;
  
  
  
  1.4       +17 -9     jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AuctionAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- AuctionAction.java	16 Apr 2007 03:57:49 -0000	1.3
  +++ AuctionAction.java	1 May 2007 01:31:48 -0000	1.4
  @@ -1,9 +1,10 @@
   package org.jboss.seam.example.seambay;
   
  -import static org.jboss.seam.ScopeType.CONVERSATION;
  +import static org.jboss.seam.ScopeType.SESSION;
   
   import java.io.Serializable;
   import java.util.Calendar;
  +import java.util.Date;
   import java.util.GregorianCalendar;
   
   import javax.persistence.EntityManager;
  @@ -12,10 +13,11 @@
   import org.jboss.seam.annotations.End;
   import org.jboss.seam.annotations.In;
   import org.jboss.seam.annotations.Name;
  +import org.jboss.seam.annotations.Out;
   import org.jboss.seam.annotations.Scope;
   import org.jboss.seam.annotations.security.Restrict;
   
  - at Scope(CONVERSATION)
  + at Scope(SESSION)
   @Name("auctionAction")
   @Restrict("#{identity.loggedIn}")
   public class AuctionAction implements Serializable
  @@ -26,17 +28,21 @@
      
      @In Account authenticatedAccount;
   
  +   @Out
      private Auction auction;
      
      private int durationDays;
   
  -   @Begin
  +   @Begin(pageflow="createAuction", join=true)
  +   @SuppressWarnings("unchecked")
      public void createAuction()
      {
  +      if (auction == null)
  +      {
         auction = new Auction();
         auction.setAccount(authenticatedAccount);
         auction.setStatus(Auction.STATUS_UNLISTED);           
  -      entityManager.persist(auction);     
  +      }
      }   
         
      @Begin(join = true)
  @@ -64,7 +70,9 @@
         cal.add(Calendar.DAY_OF_MONTH, durationDays);
         auction.setEndDate(cal.getTime());
         auction.setStatus(Auction.STATUS_LIVE);
  -      auction = entityManager.merge(auction);
  +      entityManager.persist(auction);
  +      
  +      auction = null;
      }
   
      public Auction getAuction()
  
  
  
  1.9       +1 -1      jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AuctionService.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  
  
  
  1.4       +9 -0      jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/User.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: User.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/User.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- User.java	16 Apr 2007 03:57:49 -0000	1.3
  +++ User.java	1 May 2007 01:31:48 -0000	1.4
  @@ -7,10 +7,15 @@
   import javax.persistence.Id;
   import javax.persistence.JoinColumn;
   import javax.persistence.OneToOne;
  +import javax.persistence.Table;
  +import javax.persistence.UniqueConstraint;
   
  +import org.hibernate.validator.Length;
   import org.hibernate.validator.NotNull;
  +import org.hibernate.validator.Pattern;
   
   @Entity
  + at Table(uniqueConstraints = @UniqueConstraint(columnNames = "username"))
   public class User implements Serializable
   {   
      private static final long serialVersionUID = 1L;
  @@ -31,6 +36,10 @@
         this.userId = userId;
      }
      
  +   @NotNull
  +   @Length(min = 3, max = 40)
  +   @Pattern(regex="[a-zA-Z]?[a-zA-Z0-9]+", 
  +         message="Username must start with a letter, and only contain letters or numbers")   
      public String getUsername()
      {
         return username;
  
  
  
  1.1      date: 2007/05/01 01:31:48;  author: sbryzak2;  state: Exp;jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/RegisterAction.java
  
  Index: RegisterAction.java
  ===================================================================
  package org.jboss.seam.example.seambay;
  
  import static org.jboss.seam.ScopeType.CONVERSATION;
  
  import java.io.Serializable;
  import java.util.Date;
  
  import javax.faces.application.FacesMessage;
  import javax.persistence.EntityExistsException;
  import javax.persistence.EntityManager;
  
  import org.jboss.seam.annotations.Begin;
  import org.jboss.seam.annotations.End;
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Out;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.core.FacesMessages;
  import org.jboss.seam.security.Identity;
  
  @Scope(CONVERSATION)
  @Name("registerAction")
  public class RegisterAction implements Serializable
  {
     private static final long serialVersionUID = -4349512217411197622L;
     
     @In
     EntityManager entityManager;
  
     @Out
     private User newuser;
     
     private String confirm;
     
     @Begin(join = true)
     public void newRegistration()
     {
        if (newuser == null)
        {
           newuser = new User();
           newuser.setAccount(new Account());
        }
     }
     
     @End(ifOutcome = "success")
     public String register()
     {
        if (confirm == null || !confirm.equals(newuser.getPassword()))
        {
           FacesMessages.instance().addToControl("confirm", "Passwords do not match");
           return "failed";
        }
        
        if (entityManager.createQuery("from User where username = :username")
              .setParameter("username", newuser.getUsername())
              .getResultList().size() > 0)
        {
           FacesMessages.instance().addToControl("username", 
                 "That user ID is already taken, please choose a different one");
           return "failed"; 
        }
        
        newuser.getAccount().setFeedbackPercent(0);
        newuser.getAccount().setFeedbackScore(0);
        newuser.getAccount().setMemberSince(new Date());
        
        // The account name *could* be different to the username if we want
        newuser.getAccount().setName(newuser.getUsername());
        
        try
        {
           entityManager.persist(newuser.getAccount());
           entityManager.persist(newuser);
           
           Identity.instance().setUsername(newuser.getUsername());
           Identity.instance().setPassword(newuser.getPassword());
           Identity.instance().login();
           
           return "success";
        }
        catch (EntityExistsException ex)
        {
           FacesMessages.instance().addToControl("username", 
                 "That user ID is already taken, please choose a different one");
           return "failed";  
        }
     }
     
     public String getConfirm()
     {
        return confirm;
     }
     
     public void setConfirm(String confirm)
     {
        this.confirm = confirm;
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list