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

Michael Yuan michael.yuan at jboss.com
Mon Feb 26 18:39:45 EST 2007


  User: myuan   
  Date: 07/02/26 18:39:45

  Modified:    examples/hibernate2/src/org/jboss/seam/example/hibernate     
                        HotelBookingAction.java HotelSearchingAction.java
                        RegisterAction.java
  Added:       examples/hibernate2/src/org/jboss/seam/example/hibernate     
                        AuthenticatorAction.java
  Removed:     examples/hibernate2/src/org/jboss/seam/example/hibernate     
                        Authenticator.java
  Log:
  patch the example
  
  Revision  Changes    Path
  1.5       +5 -3      jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/HotelBookingAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HotelBookingAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/HotelBookingAction.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- HotelBookingAction.java	27 Jan 2007 19:28:22 -0000	1.4
  +++ HotelBookingAction.java	26 Feb 2007 23:39:45 -0000	1.5
  @@ -1,4 +1,4 @@
  -//$Id: HotelBookingAction.java,v 1.4 2007/01/27 19:28:22 gavin Exp $
  +//$Id: HotelBookingAction.java,v 1.5 2007/02/26 23:39:45 myuan Exp $
   package org.jboss.seam.example.hibernate;
   
   import static org.jboss.seam.ScopeType.SESSION;
  @@ -69,11 +69,13 @@
         calendar.add(Calendar.DAY_OF_MONTH, -1);
         if ( booking.getCheckinDate().before( calendar.getTime() ) )
         {
  -         facesMessages.add("Check in date must be a future date");
  +         facesMessages.addToControl("checkinDate", "Check in date must be a future date");
  +         bookingValid=false;
         }
         else if ( !booking.getCheckinDate().before( booking.getCheckoutDate() ) )
         {
  -         facesMessages.add("Check out date must be later than check in date");
  +         facesMessages.addToControl("checkoutDate", "Check out date must be later than check in date");
  +         bookingValid=false;
         }
         else
         {
  
  
  
  1.4       +11 -4     jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/HotelSearchingAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HotelSearchingAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/HotelSearchingAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- HotelSearchingAction.java	27 Jan 2007 19:28:22 -0000	1.3
  +++ HotelSearchingAction.java	26 Feb 2007 23:39:45 -0000	1.4
  @@ -1,4 +1,4 @@
  -//$Id: HotelSearchingAction.java,v 1.3 2007/01/27 19:28:22 gavin Exp $
  +//$Id: HotelSearchingAction.java,v 1.4 2007/02/26 23:39:45 myuan Exp $
   package org.jboss.seam.example.hibernate;
   
   import java.util.List;
  @@ -13,6 +13,8 @@
   
   import org.hibernate.Session;
   
  +import org.jboss.seam.annotations.Factory;
  +
   @Name("hotelSearch")
   @Scope(ScopeType.SESSION)
   public class HotelSearchingAction
  @@ -42,14 +44,19 @@
         
      private void queryHotels()
      {
  -      String searchPattern = searchString==null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
  -      hotels = bookingDatabase.createQuery("select h from Hotel h where lower(h.name) like :search or lower(h.city) like :search or lower(h.zip) like :search or lower(h.address) like :search")
  -            .setParameter("search", searchPattern)
  +      hotels = bookingDatabase.createQuery("select h from Hotel h where lower(h.name) like #{pattern} or lower(h.city) like #{pattern} or lower(h.zip) like #{pattern} or lower(h.address) like #{pattern}")
               .setMaxResults(pageSize)
               .setFirstResult( page * pageSize )
               .list();
      }
      
  +   @Factory(value="pattern", scope=ScopeType.EVENT)
  +   public String getSearchPattern()
  +   {
  +      return searchString==null ?
  +            "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
  +   }
  +   
      public boolean isNextPageAvailable()
      {
         return hotels!=null && hotels.size()==pageSize;
  
  
  
  1.5       +3 -4      jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/RegisterAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RegisterAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/RegisterAction.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- RegisterAction.java	27 Jan 2007 19:28:22 -0000	1.4
  +++ RegisterAction.java	26 Feb 2007 23:39:45 -0000	1.5
  @@ -1,4 +1,4 @@
  -//$Id: RegisterAction.java,v 1.4 2007/01/27 19:28:22 gavin Exp $
  +//$Id: RegisterAction.java,v 1.5 2007/02/26 23:39:45 myuan Exp $
   package org.jboss.seam.example.hibernate;
   
   import static org.jboss.seam.ScopeType.EVENT;
  @@ -35,8 +35,7 @@
      {
         if ( user.getPassword().equals(verify) )
         {
  -         List existing = bookingDatabase.createQuery("select u.username from User u where u.username=:username")
  -            .setParameter("username", user.getUsername())
  +         List existing = bookingDatabase.createQuery("select u.username from User u where u.username=#{user.username}")
               .list();
            if (existing.size()==0)
            {
  @@ -46,7 +45,7 @@
            }
            else
            {
  -            facesMessages.add("Username #{user.username} already exists");
  +            facesMessages.addToControl("username", "Username #{user.username} already exists");
            }
         }
         else 
  
  
  
  1.1      date: 2007/02/26 23:39:45;  author: myuan;  state: Exp;jboss-seam/examples/hibernate2/src/org/jboss/seam/example/hibernate/AuthenticatorAction.java
  
  Index: AuthenticatorAction.java
  ===================================================================
  package org.jboss.seam.example.hibernate;
  
  import static org.jboss.seam.ScopeType.SESSION;
  
  import java.util.List;
  import javax.persistence.EntityManager;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Out;
  import org.jboss.seam.annotations.In;
  
  import org.hibernate.Session;
  
  @Name("authenticator")
  public class AuthenticatorAction
  {
     @In Session bookingDatabase;
     
     @Out(required=false, scope = SESSION)
     private User user;
     
     public boolean authenticate()
     {
        List results = bookingDatabase.createQuery("select u from User u where u.username=#{identity.username} and u.password=#{identity.password}")
              .list();
        
        if ( results.size()==0 )
        {
           return false;
        }
        else
        {
           user = (User) results.get(0);
           return true;
        }
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list