Author: vdedik
Date: 2012-08-15 07:37:04 -0400 (Wed, 15 Aug 2012)
New Revision: 15044
Added:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/BookingListAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelBookingAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelSearchingAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/Random.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/RegisterAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Booking.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Hotel.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/User.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/AuthenticatorAction.java
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/ChangePasswordAction.java
Removed:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Booking.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/BookingListAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Hotel.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelBookingAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelSearchingAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Random.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/RegisterAction.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/User.groovy
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/AuthenticatorAction.java
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/ChangePasswordAction.java
Modified:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/pom.xml
Log:
JBSEAM-5014
Modified:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/pom.xml
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/pom.xml 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/pom.xml 2012-08-15
11:37:04 UTC (rev 15044)
@@ -128,19 +128,57 @@
<build>
<finalName>jboss-seam-groovybooking</finalName>
<plugins>
+ <!-- Can't use gmaven-plugin because hot deployment won't work
otherwise -->
<plugin>
- <groupId>org.codehaus.gmaven</groupId>
- <artifactId>gmaven-plugin</artifactId>
- <version>1.4</version>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
+ <id>compile-groovy-files</id>
+ <phase>generate-resources</phase>
+ <configuration>
+ <tasks>
+ <taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc">
+ <classpath refid="maven.compile.classpath"/>
+ </taskdef>
+ <mkdir dir="${project.build.outputDirectory}"/>
+ <groovyc destdir="${project.build.outputDirectory}"
+ srcdir="${basedir}/src/main/groovy/"
+ listfiles="true">
+ <classpath refid="maven.compile.classpath"/>
+ <include name="**/model/**"/>
+ </groovyc>
+ </tasks>
+ </configuration>
<goals>
- <goal>generateStubs</goal>
- <goal>compile</goal>
- <goal>generateTestStubs</goal>
- <goal>testCompile</goal>
+ <goal>run</goal>
</goals>
</execution>
+ <execution>
+ <id>copy-class-files</id>
+ <phase>prepare-package</phase>
+ <configuration>
+ <tasks>
+ <property name="dev.dir"
+
value="${project.build.directory}/${project.build.finalName}/WEB-INF/dev"/>
+ <mkdir dir="${dev.dir}"/>
+ <copy todir="${dev.dir}">
+ <fileset dir="${basedir}/src/main/groovy/">
+ <include name="**/action/**"/>
+ </fileset>
+ </copy>
+ <move todir="${dev.dir}">
+ <fileset
dir="${project.build.outputDirectory}">
+ <include
name="**/AuthenticatorAction.class"/>
+ <include
name="**/ChangePasswordAction.class"/>
+ </fileset>
+ </move>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Booking.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Booking.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Booking.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,92 +0,0 @@
-//$Id: Booking.groovy 4698 2007-04-18 06:40:06Z ebernard $
-package org.jboss.seam.example.groovy
-
-import java.text.DateFormat
-import javax.persistence.Basic
-import javax.persistence.Entity
-import javax.persistence.GeneratedValue
-import javax.persistence.Id
-import javax.persistence.ManyToOne
-import javax.persistence.Temporal
-import javax.persistence.TemporalType
-import javax.persistence.Transient
-
-import org.jboss.seam.annotations.Name
-import javax.validation.constraints.NotNull
-import javax.validation.constraints.Pattern
-import javax.validation.constraints.Size
-
-@Entity
-@Name("booking")
-class Booking implements Serializable
-{
- @Id @GeneratedValue
- Long id
-
- @ManyToOne @NotNull
- User user
-
- @ManyToOne @NotNull
- Hotel hotel
-
- @NotNull
- @Basic @Temporal(TemporalType.DATE)
- Date checkinDate
-
- @Basic @Temporal(TemporalType.DATE)
- @NotNull
- Date checkoutDate
-
- @NotNull(message="Credit card number is required")
- @Size(min=16, max=16, message="Credit card number must 16 digits long")
- @Pattern(regexp=/^\d*$/, message="Credit card number must be numeric")
- String creditCard
-
- @NotNull(message="Credit card name is required")
- @Size(min=3, max=70, message="Credit card name is required")
- String creditCardName
-
- int creditCardExpiryMonth
-
- int creditCardExpiryYear
-
- boolean smoking
-
- int beds
-
- Booking() {}
-
- Booking(Hotel hotel, User user)
- {
- this.hotel = hotel
- this.user = user
- }
-
- @Transient
- BigDecimal getTotal()
- {
- return hotel.price * getNights()
- }
-
- @Transient
- int getNights()
- {
- return (int) ( ( checkoutDate.time - checkinDate.time ) / 1000 / 60 / 60 / 24 )
- }
-
- @Transient
- String getDescription()
- {
- DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM)
- return hotel ?
- "${hotel.name}, ${df.format( checkinDate )} to
${df.format(checkoutDate)}" :
- null
- }
-
- @Override
- String toString()
- {
- return "Booking(" + user + ","+ hotel + ")"
- }
-
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/BookingListAction.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/BookingListAction.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/BookingListAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,57 +0,0 @@
-//$Id: BookingListAction.groovy 8748 2008-08-20 12:08:30Z pete.muir(a)jboss.org $
-package org.jboss.seam.example.groovy
-
-import javax.persistence.EntityManager
-
-import org.jboss.seam.ScopeType
-import org.jboss.seam.annotations.Factory
-import org.jboss.seam.annotations.In
-import org.jboss.seam.annotations.Logger
-import org.jboss.seam.annotations.Name
-import org.jboss.seam.annotations.Scope
-import org.jboss.seam.annotations.datamodel.DataModel
-import org.jboss.seam.annotations.datamodel.DataModelSelection
-import org.jboss.seam.faces.FacesMessages
-import org.jboss.seam.log.Log
-
-(a)Scope(ScopeType.SESSION)
-@Name("bookingList")
-class BookingListAction implements Serializable
-{
-
- @In
- EntityManager em
-
- @In
- User user
-
- @DataModel
- private List<Booking> bookings
-
- @DataModelSelection
- Booking booking
-
- @Logger
- Log log
-
- @Factory
- public void getBookings()
- {
- bookings = em.createQuery('''
- select b from Booking b
- where b.user.username = :username
- order by b.checkinDate''')
- .setParameter("username", user.username)
- .getResultList()
- }
-
- public void cancel()
- {
- log.info("Cancel booking: #{bookingList.booking.id} for
#{user.username}")
- Booking cancelled = em.find(Booking.class, booking.id)
- if (cancelled != null) em.remove( cancelled )
- getBookings()
- FacesMessages.instance().add("Booking cancelled for confirmation number
#0", booking.getId())
- }
-
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Hotel.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Hotel.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Hotel.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,47 +0,0 @@
-//$Id: Hotel.groovy 4698 2007-04-18 06:40:06Z ebernard $
-package org.jboss.seam.example.groovy
-
-import javax.persistence.Column
-import javax.persistence.Entity
-import javax.persistence.GeneratedValue
-import javax.persistence.Id
-
-import org.jboss.seam.annotations.Name
-import javax.validation.constraints.NotNull
-import javax.validation.constraints.Size
-
-
-@Entity
-@Name("hotel")
-class Hotel implements Serializable
-{
- @Id @GeneratedValue
- Long id
-
- @Size(max=50) @NotNull
- String name
-
- @Size(max=100) @NotNull
- String address
-
- @Size(max=40) @NotNull
- String city
-
- @Size(min=2, max=10) @NotNull
- String state
-
- @Size(min=4, max=6) @NotNull
- String zip
-
- @Size(min=2, max=40) @NotNull
- String country
-
- @Column(precision=6, scale=2)
- BigDecimal price
-
- @Override
- String toString()
- {
- return "Hotel(${name},${address},${city},${zip})"
- }
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelBookingAction.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelBookingAction.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelBookingAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,98 +0,0 @@
-//$Id: HotelBookingAction.groovy 5563 2007-06-26 22:20:03Z gavin $
-package org.jboss.seam.example.groovy
-
-import javax.persistence.EntityManager
-
-import org.jboss.seam.ScopeType
-import org.jboss.seam.annotations.Begin
-import org.jboss.seam.annotations.End
-import org.jboss.seam.annotations.In
-import org.jboss.seam.annotations.Logger
-import org.jboss.seam.annotations.Name
-import org.jboss.seam.annotations.Out
-import org.jboss.seam.core.Events
-import org.jboss.seam.faces.FacesMessages
-import org.jboss.seam.log.Log
-
-@Name("hotelBooking")
-class HotelBookingAction
-{
-
- @In
- EntityManager em
-
- @In
- User user
-
- @In(required=false) @Out
- Hotel hotel
-
- @In(required=false)
- @Out(required=false)
- Booking booking
-
- @In
- FacesMessages facesMessages
-
- @In
- Events events
-
- @Logger
- Log log
-
- boolean bookingValid
-
- @Begin
- void selectHotel(Hotel selectedHotel)
- {
- hotel = em.merge(selectedHotel)
- }
-
- void bookHotel()
- {
- booking = new Booking(hotel, user)
- Calendar calendar = Calendar.getInstance()
- booking.checkinDate = calendar.time
- calendar.add Calendar.DAY_OF_MONTH, 1
- booking.checkoutDate = calendar.time
- }
-
- void setBookingDetails()
- {
- Calendar calendar = Calendar.getInstance()
- calendar.add Calendar.DAY_OF_MONTH, -1
- if ( booking.checkinDate < calendar.time )
- {
- facesMessages.addToControl "checkinDate", "Check in date must be
a future date"
- bookingValid=false
- }
- else if ( booking.checkinDate >= booking.checkoutDate )
- {
- facesMessages.addToControl "checkoutDate", "Check out date must
be later than check in date"
- bookingValid=false
- }
- else
- {
- bookingValid=true
- }
- }
-
- @Out (required=false, scope=ScopeType.SESSION)
- List <Booking> bookings
-
- @End
- void confirm()
- {
- em.persist(booking)
- facesMessages.add "Thank you, #{user.name}, your confimation number for
#{hotel.name} is #{booking.id}", new Object[0]
- log.info("New booking: #{booking.id} for #{user.username}")
- // events.raiseTransactionSuccessEvent("bookingConfirmed")
-
- // force refresh in main.xhtml
- bookings = null
- }
-
- @End
- void cancel() {}
-
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelSearchingAction.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelSearchingAction.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelSearchingAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,70 +0,0 @@
-//$Id: HotelSearchingAction.groovy 4933 2007-05-27 03:13:24Z ebernard $
-package org.jboss.seam.example.groovy
-
-import javax.persistence.EntityManager
-import javax.persistence.PersistenceContext
-
-import org.jboss.seam.ScopeType
-import org.jboss.seam.annotations.Destroy
-import org.jboss.seam.annotations.Name
-import org.jboss.seam.annotations.Scope
-import org.jboss.seam.annotations.datamodel.DataModel
-
-import org.jboss.seam.annotations.In
-
-import org.jboss.seam.annotations.Factory
-
-@Name("hotelSearch")
-(a)Scope(ScopeType.SESSION)
-class HotelSearchingAction
-{
-
- @In
- private EntityManager em
-
- String searchString
- int pageSize = 10
- int page
-
- @DataModel
- List<Hotel> hotels
-
- void find()
- {
- page = 0
- queryHotels()
- }
-
- void nextPage()
- {
- page++
- queryHotels()
- }
-
- private void queryHotels()
- {
- def query = em.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}
- ''')
- query.maxResults = pageSize
- query.firstResult = page * pageSize
- hotels = query.getResultList()
- }
-
- @Factory(value="pattern", scope=ScopeType.EVENT)
- String getSearchPattern()
- {
- return searchString ?
- "%${searchString.toLowerCase().replace('*', '%')}%"
:
- "%";
- }
-
- boolean isNextPageAvailable()
- {
- return hotels && hotels.size()==pageSize
- }
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Random.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Random.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Random.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,10 +0,0 @@
-//$Id: Random.groovy 4698 2007-04-18 06:40:06Z ebernard $
-package org.jboss.seam.example.groovy;
-
-/**
- * Not used in the application but a non Seam component is also hot deployable
- */
-class Random
-{
-
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/RegisterAction.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/RegisterAction.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/RegisterAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,63 +0,0 @@
-//$Id: RegisterAction.groovy 5563 2007-06-26 22:20:03Z gavin $
-package org.jboss.seam.example.groovy;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.jboss.seam.annotations.Destroy;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.faces.FacesMessages;
-import static org.jboss.seam.ScopeType.EVENT;
-
-@Scope(EVENT)
-@Name("register")
-class RegisterAction
-{
-
- @In
- User user;
-
- @In
- EntityManager em;
-
- @In
- FacesMessages facesMessages;
-
- String verify;
-
- boolean registered;
-
- void register()
- {
- if ( user.password == verify ) {
- List existing = em.createQuery(
- '''select u.username
- from User u
- where u.username=#{user.username}
- ''').getResultList()
-
- if (!existing.size())
- {
- em.persist(user)
- facesMessages.add("Successfully registered as #{user.username}",
new Object[0]);
- registered = true
- }
- else
- {
- facesMessages.addToControl("username", "Username
#{user.username} already exists")
- }
- }
- else
- {
- facesMessages.add("verify", "Re-enter your password")
- verify=null
- }
- }
-
- void invalid()
- {
- facesMessages.add("Please try again", new Object[0])
- }
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/User.groovy
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/User.groovy 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/User.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,49 +0,0 @@
-//$Id: User.groovy 4698 2007-04-18 06:40:06Z ebernard $
-package org.jboss.seam.example.groovy
-
-import javax.persistence.Entity
-import javax.persistence.Id
-import javax.persistence.Table
-
-
-import org.jboss.seam.ScopeType
-import org.jboss.seam.annotations.Name
-import org.jboss.seam.annotations.Scope
-import javax.validation.constraints.Pattern
-import javax.validation.constraints.NotNull
-import javax.validation.constraints.Size
-
-@Entity
-@Name("user")
-(a)Scope(ScopeType.SESSION)
-@Table(name="Customer")
-class User implements Serializable
-{
- @Id
- @Size(min=5, max=15)
- @Pattern(regexp=/^\w*$/, message="not a valid username")
- String username
-
- @NotNull
- @Size(min=5, max=15)
- String password
-
- @NotNull
- @Size(max=100)
- String name
-
- User(String name, String password, String username)
- {
- this.name = name
- this.password = password
- this.username = username
- }
-
- User() {}
-
- @Override
- String toString()
- {
- return "User(${username})"
- }
-}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/BookingListAction.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/BookingListAction.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/BookingListAction.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/BookingListAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,59 @@
+//$Id: BookingListAction.groovy 8748 2008-08-20 12:08:30Z pete.muir(a)jboss.org $
+package org.jboss.seam.example.groovy.action
+
+import javax.persistence.EntityManager
+
+import org.jboss.seam.ScopeType
+import org.jboss.seam.annotations.Factory
+import org.jboss.seam.annotations.In
+import org.jboss.seam.annotations.Logger
+import org.jboss.seam.annotations.Name
+import org.jboss.seam.annotations.Scope
+import org.jboss.seam.annotations.datamodel.DataModel
+import org.jboss.seam.annotations.datamodel.DataModelSelection
+import org.jboss.seam.faces.FacesMessages
+import org.jboss.seam.log.Log
+import org.jboss.seam.example.groovy.model.Booking
+import org.jboss.seam.example.groovy.model.User
+
+(a)Scope(ScopeType.SESSION)
+@Name("bookingList")
+class BookingListAction implements Serializable
+{
+
+ @In
+ EntityManager em
+
+ @In
+ User user
+
+ @DataModel
+ private List<Booking> bookings
+
+ @DataModelSelection
+ Booking booking
+
+ @Logger
+ Log log
+
+ @Factory
+ public void getBookings()
+ {
+ bookings = em.createQuery('''
+ select b from Booking b
+ where b.user.username = :username
+ order by b.checkinDate''')
+ .setParameter("username", user.username)
+ .getResultList()
+ }
+
+ public void cancel()
+ {
+ log.info("Cancel booking: #{bookingList.booking.id} for
#{user.username}")
+ Booking cancelled = em.find(Booking.class, booking.id)
+ if (cancelled != null) em.remove( cancelled )
+ getBookings()
+ FacesMessages.instance().add("Booking cancelled for confirmation number
#0", booking.getId())
+ }
+
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelBookingAction.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelBookingAction.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelBookingAction.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelBookingAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,101 @@
+//$Id: HotelBookingAction.groovy 5563 2007-06-26 22:20:03Z gavin $
+package org.jboss.seam.example.groovy.action
+
+import javax.persistence.EntityManager
+
+import org.jboss.seam.ScopeType
+import org.jboss.seam.annotations.Begin
+import org.jboss.seam.annotations.End
+import org.jboss.seam.annotations.In
+import org.jboss.seam.annotations.Logger
+import org.jboss.seam.annotations.Name
+import org.jboss.seam.annotations.Out
+import org.jboss.seam.core.Events
+import org.jboss.seam.faces.FacesMessages
+import org.jboss.seam.log.Log
+import org.jboss.seam.example.groovy.model.Booking
+import org.jboss.seam.example.groovy.model.Hotel
+import org.jboss.seam.example.groovy.model.User
+
+@Name("hotelBooking")
+class HotelBookingAction
+{
+
+ @In
+ EntityManager em
+
+ @In
+ User user
+
+ @In(required=false) @Out
+ Hotel hotel
+
+ @In(required=false)
+ @Out(required=false)
+ Booking booking
+
+ @In
+ FacesMessages facesMessages
+
+ @In
+ Events events
+
+ @Logger
+ Log log
+
+ boolean bookingValid
+
+ @Begin
+ void selectHotel(Hotel selectedHotel)
+ {
+ hotel = em.merge(selectedHotel)
+ }
+
+ void bookHotel()
+ {
+ booking = new Booking(hotel, user)
+ Calendar calendar = Calendar.getInstance()
+ booking.checkinDate = calendar.time
+ calendar.add Calendar.DAY_OF_MONTH, 1
+ booking.checkoutDate = calendar.time
+ }
+
+ void setBookingDetails()
+ {
+ Calendar calendar = Calendar.getInstance()
+ calendar.add Calendar.DAY_OF_MONTH, -1
+ if ( booking.checkinDate < calendar.time )
+ {
+ facesMessages.addToControl "checkinDate", "Check in date must be
a future date"
+ bookingValid=false
+ }
+ else if ( booking.checkinDate >= booking.checkoutDate )
+ {
+ facesMessages.addToControl "checkoutDate", "Check out date must
be later than check in date"
+ bookingValid=false
+ }
+ else
+ {
+ bookingValid=true
+ }
+ }
+
+ @Out (required=false, scope=ScopeType.SESSION)
+ List <Booking> bookings
+
+ @End
+ void confirm()
+ {
+ em.persist(booking)
+ facesMessages.add "Thank you, #{user.name}, your confimation number for
#{hotel.name} is #{booking.id}", new Object[0]
+ log.info("New booking: #{booking.id} for #{user.username}")
+ // events.raiseTransactionSuccessEvent("bookingConfirmed")
+
+ // force refresh in main.xhtml
+ bookings = null
+ }
+
+ @End
+ void cancel() {}
+
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelSearchingAction.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/HotelSearchingAction.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelSearchingAction.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/HotelSearchingAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,70 @@
+//$Id: HotelSearchingAction.groovy 4933 2007-05-27 03:13:24Z ebernard $
+package org.jboss.seam.example.groovy.action
+
+import javax.persistence.EntityManager
+
+import org.jboss.seam.ScopeType
+
+import org.jboss.seam.annotations.Name
+import org.jboss.seam.annotations.Scope
+import org.jboss.seam.annotations.datamodel.DataModel
+
+import org.jboss.seam.annotations.In
+
+import org.jboss.seam.annotations.Factory
+import org.jboss.seam.example.groovy.model.Hotel
+
+@Name("hotelSearch")
+(a)Scope(ScopeType.SESSION)
+class HotelSearchingAction
+{
+
+ @In
+ private EntityManager em
+
+ String searchString
+ int pageSize = 10
+ int page
+
+ @DataModel
+ List<Hotel> hotels
+
+ void find()
+ {
+ page = 0
+ queryHotels()
+ }
+
+ void nextPage()
+ {
+ page++
+ queryHotels()
+ }
+
+ private void queryHotels()
+ {
+ def query = em.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}
+ ''')
+ query.maxResults = pageSize
+ query.firstResult = page * pageSize
+ hotels = query.getResultList()
+ }
+
+ @Factory(value="pattern", scope=ScopeType.EVENT)
+ String getSearchPattern()
+ {
+ return searchString ?
+ "%${searchString.toLowerCase().replace('*', '%')}%"
:
+ "%";
+ }
+
+ boolean isNextPageAvailable()
+ {
+ return hotels && hotels.size()==pageSize
+ }
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/Random.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Random.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/Random.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/Random.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,10 @@
+//$Id: Random.groovy 4698 2007-04-18 06:40:06Z ebernard $
+package org.jboss.seam.example.groovy.action;
+
+/**
+ * Not used in the application but a non Seam component is also hot deployable
+ */
+class Random
+{
+
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/RegisterAction.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/RegisterAction.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/RegisterAction.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/action/RegisterAction.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,63 @@
+//$Id: RegisterAction.groovy 5563 2007-06-26 22:20:03Z gavin $
+package org.jboss.seam.example.groovy.action;
+
+import javax.persistence.EntityManager;
+
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.faces.FacesMessages;
+import static org.jboss.seam.ScopeType.EVENT
+import org.jboss.seam.example.groovy.model.User;
+
+@Scope(EVENT)
+@Name("register")
+class RegisterAction
+{
+
+ @In
+ User user;
+
+ @In
+ EntityManager em;
+
+ @In
+ FacesMessages facesMessages;
+
+ String verify;
+
+ boolean registered;
+
+ void register()
+ {
+ if ( user.password == verify ) {
+ List existing = em.createQuery(
+ '''select u.username
+ from User u
+ where u.username=#{user.username}
+ ''').getResultList()
+
+ if (!existing.size())
+ {
+ em.persist(user)
+ facesMessages.add("Successfully registered as #{user.username}",
new Object[0]);
+ registered = true
+ }
+ else
+ {
+ facesMessages.addToControl("username", "Username
#{user.username} already exists")
+ }
+ }
+ else
+ {
+ facesMessages.add("verify", "Re-enter your password")
+ verify=null
+ }
+ }
+
+ void invalid()
+ {
+ facesMessages.add("Please try again", new Object[0])
+ }
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Booking.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Booking.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Booking.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Booking.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,92 @@
+//$Id: Booking.groovy 4698 2007-04-18 06:40:06Z ebernard $
+package org.jboss.seam.example.groovy.model
+
+import java.text.DateFormat
+import javax.persistence.Basic
+import javax.persistence.Entity
+import javax.persistence.GeneratedValue
+import javax.persistence.Id
+import javax.persistence.ManyToOne
+import javax.persistence.Temporal
+import javax.persistence.TemporalType
+import javax.persistence.Transient
+
+import org.jboss.seam.annotations.Name
+import javax.validation.constraints.NotNull
+import javax.validation.constraints.Pattern
+import javax.validation.constraints.Size
+
+@Entity
+@Name("booking")
+class Booking implements Serializable
+{
+ @Id @GeneratedValue
+ Long id
+
+ @ManyToOne @NotNull
+ User user
+
+ @ManyToOne @NotNull
+ Hotel hotel
+
+ @NotNull
+ @Basic @Temporal(TemporalType.DATE)
+ Date checkinDate
+
+ @Basic @Temporal(TemporalType.DATE)
+ @NotNull
+ Date checkoutDate
+
+ @NotNull(message="Credit card number is required")
+ @Size(min=16, max=16, message="Credit card number must 16 digits long")
+ @Pattern(regexp=/^\d*$/, message="Credit card number must be numeric")
+ String creditCard
+
+ @NotNull(message="Credit card name is required")
+ @Size(min=3, max=70, message="Credit card name is required")
+ String creditCardName
+
+ int creditCardExpiryMonth
+
+ int creditCardExpiryYear
+
+ boolean smoking
+
+ int beds
+
+ Booking() {}
+
+ Booking(Hotel hotel, User user)
+ {
+ this.hotel = hotel
+ this.user = user
+ }
+
+ @Transient
+ BigDecimal getTotal()
+ {
+ return hotel.price * getNights()
+ }
+
+ @Transient
+ int getNights()
+ {
+ return (int) ( ( checkoutDate.time - checkinDate.time ) / 1000 / 60 / 60 / 24 )
+ }
+
+ @Transient
+ String getDescription()
+ {
+ DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM)
+ return hotel ?
+ "${hotel.name}, ${df.format( checkinDate )} to
${df.format(checkoutDate)}" :
+ null
+ }
+
+ @Override
+ String toString()
+ {
+ return "Booking(" + user + ","+ hotel + ")"
+ }
+
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Hotel.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/Hotel.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Hotel.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/Hotel.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,47 @@
+//$Id: Hotel.groovy 4698 2007-04-18 06:40:06Z ebernard $
+package org.jboss.seam.example.groovy.model
+
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.GeneratedValue
+import javax.persistence.Id
+
+import org.jboss.seam.annotations.Name
+import javax.validation.constraints.NotNull
+import javax.validation.constraints.Size
+
+
+@Entity
+@Name("hotel")
+class Hotel implements Serializable
+{
+ @Id @GeneratedValue
+ Long id
+
+ @Size(max=50) @NotNull
+ String name
+
+ @Size(max=100) @NotNull
+ String address
+
+ @Size(max=40) @NotNull
+ String city
+
+ @Size(min=2, max=10) @NotNull
+ String state
+
+ @Size(min=4, max=6) @NotNull
+ String zip
+
+ @Size(min=2, max=40) @NotNull
+ String country
+
+ @Column(precision=6, scale=2)
+ BigDecimal price
+
+ @Override
+ String toString()
+ {
+ return "Hotel(${name},${address},${city},${zip})"
+ }
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/User.groovy
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/User.groovy)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/User.groovy
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/groovy/org/jboss/seam/example/groovy/model/User.groovy 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,49 @@
+//$Id: User.groovy 4698 2007-04-18 06:40:06Z ebernard $
+package org.jboss.seam.example.groovy.model
+
+import javax.persistence.Entity
+import javax.persistence.Id
+import javax.persistence.Table
+
+
+import org.jboss.seam.ScopeType
+import org.jboss.seam.annotations.Name
+import org.jboss.seam.annotations.Scope
+import javax.validation.constraints.Pattern
+import javax.validation.constraints.NotNull
+import javax.validation.constraints.Size
+
+@Entity
+@Name("user")
+(a)Scope(ScopeType.SESSION)
+@Table(name="Customer")
+class User implements Serializable
+{
+ @Id
+ @Size(min=5, max=15)
+ @Pattern(regexp=/^\w*$/, message="not a valid username")
+ String username
+
+ @NotNull
+ @Size(min=5, max=15)
+ String password
+
+ @NotNull
+ @Size(max=100)
+ String name
+
+ User(String name, String password, String username)
+ {
+ this.name = name
+ this.password = password
+ this.username = username
+ }
+
+ User() {}
+
+ @Override
+ String toString()
+ {
+ return "User(${username})"
+ }
+}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/AuthenticatorAction.java
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/AuthenticatorAction.java 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/AuthenticatorAction.java 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,35 +0,0 @@
-package org.jboss.seam.example.groovy;
-
-import java.util.List;
-import javax.persistence.EntityManager;
-
-import static org.jboss.seam.ScopeType.SESSION;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Out;
-
-@Name("authenticator")
-public class AuthenticatorAction
-{
- @In EntityManager em;
-
- @Out(required=false, scope = SESSION)
- private User user;
-
- public boolean authenticate()
- {
- List results = em.createQuery("select u from User u where
u.username=#{identity.username} and u.password=#{identity.password}")
- .getResultList();
-
- if ( results.size()==0 )
- {
- return false;
- }
- else
- {
- user = (User) results.get(0);
- return true;
- }
- }
-
-}
Deleted:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/ChangePasswordAction.java
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/ChangePasswordAction.java 2012-08-14
19:38:58 UTC (rev 15043)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/ChangePasswordAction.java 2012-08-15
11:37:04 UTC (rev 15044)
@@ -1,64 +0,0 @@
-//$Id: ChangePasswordAction.java 5305 2007-06-20 01:30:37Z gavin $
-package org.jboss.seam.example.groovy;
-
-import javax.persistence.EntityManager;
-
-import static org.jboss.seam.ScopeType.EVENT;
-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.faces.FacesMessages;
-
-@Scope(EVENT)
-@Name("changePassword")
-public class ChangePasswordAction
-{
-
- @In @Out
- private User user;
-
- @In
- private EntityManager em;
-
- private String verify;
-
- private boolean changed;
-
- public void changePassword()
- {
- if ( user.getPassword().equals(verify) )
- {
- user = em.merge(user);
- FacesMessages.instance().add("Password updated");
- changed = true;
- }
- else
- {
- FacesMessages.instance().add("verify", "Re-enter new
password");
- revertUser();
- verify=null;
- }
- }
-
- public boolean isChanged()
- {
- return changed;
- }
-
- private void revertUser()
- {
- user = em.find(User.class, user.getUsername());
- }
-
- public String getVerify()
- {
- return verify;
- }
-
- public void setVerify(String verify)
- {
- this.verify = verify;
- }
-
-}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/AuthenticatorAction.java
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/AuthenticatorAction.java)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/AuthenticatorAction.java
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/AuthenticatorAction.java 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,36 @@
+package org.jboss.seam.example.groovy.action;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+
+import static org.jboss.seam.ScopeType.SESSION;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.example.groovy.model.User;
+
+@Name("authenticator")
+public class AuthenticatorAction
+{
+ @In EntityManager em;
+
+ @Out(required=false, scope = SESSION)
+ private User user;
+
+ public boolean authenticate()
+ {
+ List results = em.createQuery("select u from User u where
u.username=#{identity.username} and u.password=#{identity.password}")
+ .getResultList();
+
+ if ( results.size()==0 )
+ {
+ return false;
+ }
+ else
+ {
+ user = (User) results.get(0);
+ return true;
+ }
+ }
+
+}
Copied:
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/ChangePasswordAction.java
(from rev 15033,
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/ChangePasswordAction.java)
===================================================================
---
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/ChangePasswordAction.java
(rev 0)
+++
branches/community/Seam_2_3/examples-ee6/groovybooking/groovybooking-web/src/main/java/org/jboss/seam/example/groovy/action/ChangePasswordAction.java 2012-08-15
11:37:04 UTC (rev 15044)
@@ -0,0 +1,65 @@
+//$Id: ChangePasswordAction.java 5305 2007-06-20 01:30:37Z gavin $
+package org.jboss.seam.example.groovy.action;
+
+import javax.persistence.EntityManager;
+
+import static org.jboss.seam.ScopeType.EVENT;
+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.example.groovy.model.User;
+import org.jboss.seam.faces.FacesMessages;
+
+@Scope(EVENT)
+@Name("changePassword")
+public class ChangePasswordAction
+{
+
+ @In @Out
+ private User user;
+
+ @In
+ private EntityManager em;
+
+ private String verify;
+
+ private boolean changed;
+
+ public void changePassword()
+ {
+ if ( user.getPassword().equals(verify) )
+ {
+ user = em.merge(user);
+ FacesMessages.instance().add("Password updated");
+ changed = true;
+ }
+ else
+ {
+ FacesMessages.instance().add("verify", "Re-enter new
password");
+ revertUser();
+ verify=null;
+ }
+ }
+
+ public boolean isChanged()
+ {
+ return changed;
+ }
+
+ private void revertUser()
+ {
+ user = em.find(User.class, user.getUsername());
+ }
+
+ public String getVerify()
+ {
+ return verify;
+ }
+
+ public void setVerify(String verify)
+ {
+ this.verify = verify;
+ }
+
+}