12.2.2. Seam コンポーネント
Seam コンポーネントを Groovy で記述するのは Java で記述するのと同じで、 Seam コンポーネントとしてクラスに目印をつけるためにアノテーションを使います。
例12.2 Groovy による Seam コンポーネントの記述
@Scope(ScopeType.SESSION)
@Name("bookingList")
class BookingListAction implements Serializable
{
@In EntityManager em
@In User user
@DataModel 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 #{bookingList.booking.id}",
new Object[0])
}
}
@Scope(ScopeType.SESSION)
@Name("bookingList")
class BookingListAction implements Serializable
{
@In EntityManager em
@In User user
@DataModel 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 #{bookingList.booking.id}",
new Object[0])
}
}