[seam-commits] Seam SVN: r10743 - in examples/trunk/booking/ejb-jar/src/main/java: org/jboss/seam/examples/booking and 5 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri May 1 15:49:28 EDT 2009
Author: dan.j.allen
Date: 2009-05-01 15:49:27 -0400 (Fri, 01 May 2009)
New Revision: 10743
Added:
examples/trunk/booking/ejb-jar/src/main/java/controls/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducer.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/bindings/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/controls/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/events/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java
Removed:
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/BookingEvent.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Confirmed.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Registered.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducer.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducerBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistory.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistoryBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManager.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManagerBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/Registrar.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/RegistrarBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java
examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java
examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java
Log:
packaging
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/BookingEvent.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/BookingEvent.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/BookingEvent.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,25 +0,0 @@
-package org.jboss.seam.examples.booking;
-
-import org.jboss.seam.examples.booking.model.Booking;
-
-/**
- * An event that is raised when a booking change occurs
- * (either a new booking is confirmed or an existing
- * booking is canceled).
- *
- * @author Dan Allen
- */
-public class BookingEvent
-{
- private Booking booking;
-
- public BookingEvent(Booking booking)
- {
- this.booking = booking;
- }
-
- public Booking getBooking()
- {
- return booking;
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Confirmed.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Confirmed.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Confirmed.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,30 +0,0 @@
-package org.jboss.seam.examples.booking;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import javax.inject.BindingType;
-
-/**
- * @author Dan Allen
- */
-public
- at Target(
-{
- TYPE, METHOD, PARAMETER, FIELD
-})
- at Retention(RUNTIME)
- at Documented
- at BindingType
- at Inherited
- at interface Confirmed
-{
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Registered.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Registered.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Registered.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,35 +0,0 @@
-package org.jboss.seam.examples.booking;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import javax.inject.BindingType;
-import org.jboss.seam.examples.booking.model.User;
-
-/**
- * A binding type representing something that is registererd.
- * In this simple application the only thing that can be
- * registered is a {@link User}.
- *
- * @author Dan Allen
- */
-public
- at Target(
-{
- TYPE, METHOD, PARAMETER, FIELD
-})
- at Retention(RUNTIME)
- at Documented
- at BindingType
- at Inherited
- at interface Registered
-{
-}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducer.java (from rev 10729, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducer.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducer.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducer.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,17 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.ejb.Local;
+import org.jboss.seam.examples.booking.model.User;
+
+/**
+ * The <strong>AccountProducer</strong> produces the object that
+ * represents the current user's account information. The account
+ * information is represented by the {@link User} entity.
+ *
+ * @author Dan Allen
+ */
+public
+ at Local
+interface AccountProducer {
+ User getCurrentAccount();
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducerBean.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,45 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+import javax.ejb.Stateless;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.account.Registered;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.examples.booking.security.Identity;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Stateless
+class AccountProducerBean implements AccountProducer
+{
+ @PersistenceContext EntityManager em;
+
+ @Current Identity identity;
+
+ public
+ @Produces
+ @Registered
+ @Named("user")
+ @SessionScoped
+ User getCurrentAccount()
+ {
+ if (identity.isLoggedIn())
+ {
+ User user = em.find(User.class, identity.getUsername());
+ if (user != null)
+ {
+ user.setPassword(null);
+ return user;
+ }
+ }
+
+ // TODO can't return null, but then we are not honoring the semantics of our binding type
+ return new User();
+ }
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManager.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,26 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.ejb.Local;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ *
+ * @author Dan Allen
+ */
+public
+ at Local
+interface PasswordManager
+{
+ void changePassword();
+
+ boolean isChanged();
+
+ void setConfirmPassword(String password);
+
+ @NotNull
+ @Size(min = 5, max = 15)
+ String getConfirmPassword();
+
+ void destroy();
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManagerBean.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,74 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.annotation.Named;
+import javax.annotation.PreDestroy;
+import javax.context.RequestScoped;
+import javax.ejb.Stateful;
+import javax.inject.Current;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.account.Registered;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.seam.examples.booking.controls.RegistrationFormControls;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Named("passwordManager")
+ at Stateful
+ at RequestScoped
+class PasswordManagerBean implements PasswordManager
+{
+ @PersistenceContext EntityManager em;
+
+ @Current StatusMessages statusMessages;
+
+ @Current RegistrationFormControls formControls;
+
+ @Registered User user;
+
+ private String confirmPassword;
+
+ private boolean changed;
+
+ public void changePassword()
+ {
+ if (user.getPassword().equals(confirmPassword))
+ {
+ // FIXME: dirty hack, can't merge a managed bean
+ em.merge(new User(user.getName(), user.getUsername(), user.getPassword()));
+ user.setPassword(null);
+ statusMessages.add("Password successfully updated.");
+ changed = true;
+ }
+ else
+ {
+ // FIME reverting isn't going to work here
+ //revertUser();
+ confirmPassword = null;
+ statusMessages.addToControl(formControls.getConfirmPasswordControlId(), "Passwords do not match. Please re-type the new password.");
+ }
+ }
+
+ public boolean isChanged()
+ {
+ return changed;
+ }
+
+ public void setConfirmPassword(String password)
+ {
+ this.confirmPassword = password;
+ }
+
+ public String getConfirmPassword()
+ {
+ return this.confirmPassword;
+ }
+
+ @PreDestroy
+ public void destroy()
+ {
+ }
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java (from rev 10729, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/Registrar.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,32 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.ejb.Local;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import org.jboss.seam.examples.booking.model.User;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Local
+interface Registrar
+{
+ void register();
+
+ boolean isRegistrationInvalid();
+
+ void notifyIfRegistrationIsInvalid(boolean validationFailed);
+
+ User getNewUser();
+
+ boolean isRegistered();
+
+ @NotNull
+ @Size(min = 5, max = 15)
+ String getConfirmPassword();
+
+ void setConfirmPassword(String password);
+
+ void destroy();
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java (from rev 10740, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/RegistrarBean.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,131 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.annotation.Named;
+import javax.annotation.PreDestroy;
+import javax.context.RequestScoped;
+import javax.ejb.Stateful;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.examples.booking.security.Credentials;
+import org.jboss.seam.examples.booking.security.Identity;
+import org.jboss.seam.international.StatusMessage;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.seam.examples.booking.controls.RegistrationFormControls;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Named("registrar")
+ at Stateful
+ at RequestScoped
+class RegistrarBean implements Registrar
+{
+ @PersistenceContext EntityManager em;
+
+ @Current StatusMessages statusMessages;
+
+ @Current RegistrationFormControls formControls;
+
+ @Current Credentials credentials;
+
+ @Current Identity identity;
+
+ private User newUser;
+
+ private String confirmPassword;
+
+ private boolean registered;
+
+ private boolean registrationInvalid;
+
+ public void register()
+ {
+ if (verifyPasswordsMatch() && verifyUsernameIsAvailable())
+ {
+ em.persist(newUser);
+ credentials.setUsername(newUser.getUsername());
+ identity.autoLogin();
+ registered = true;
+ statusMessages.add("You have been successfully registered as the user {0}!", newUser.getUsername());
+ }
+ else
+ {
+ registrationInvalid = true;
+ }
+ }
+
+ public boolean isRegistrationInvalid()
+ {
+ return registrationInvalid;
+ }
+
+ // TODO it would be nice to move the conditional to the UI but <f:event> doesn't support if=""
+ public void notifyIfRegistrationIsInvalid(boolean validationFailed)
+ {
+ if (validationFailed || registrationInvalid)
+ {
+ statusMessages.add(StatusMessage.Severity.WARN, "Invalid registration. Please correct the errors and try again.");
+ }
+ }
+
+ public
+ @Produces
+ @Named
+ @RequestScoped
+ User getNewUser()
+ {
+ newUser = new User();
+ return newUser;
+ }
+
+ public boolean isRegistered()
+ {
+ return registered;
+ }
+
+ public String getConfirmPassword()
+ {
+ return confirmPassword;
+ }
+
+ public void setConfirmPassword(String password)
+ {
+ this.confirmPassword = password;
+ }
+
+ /**
+ * Verify that the same password is entered twice.
+ */
+ private boolean verifyPasswordsMatch()
+ {
+ if (!newUser.getPassword().equals(confirmPassword))
+ {
+ statusMessages.addToControl(formControls.getConfirmPasswordControlId(), "Passwords do not match. Please re-type your password.");
+ confirmPassword = null;
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean verifyUsernameIsAvailable()
+ {
+ User existing = em.find(User.class, newUser.getUsername());
+ if (existing != null)
+ {
+ statusMessages.addToControl(formControls.getUsernameControlId(), "The username '{0}' is already taken. Please choose another username.", newUser.getUsername());
+ return false;
+ }
+
+ return true;
+ }
+
+ @PreDestroy
+ public void destroy()
+ {
+ }
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java (from rev 10713, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.booking;
+
+import javax.ejb.Local;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.Hotel;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Local
+interface BookingAgent
+{
+ void selectHotel(Hotel hotel);
+
+ void bookHotel();
+
+ void validateBooking();
+
+ void cancel();
+
+ void confirm();
+
+ Hotel getHotelSelection();
+
+ Booking getBooking();
+
+ boolean isBookingValid();
+
+ void destroy();
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.booking;
+
+import java.util.Calendar;
+import static javax.persistence.PersistenceContextType.EXTENDED;
+import javax.annotation.Named;
+import javax.context.Conversation;
+import javax.context.ConversationScoped;
+import javax.context.RequestScoped;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.event.Event;
+import javax.event.Fires;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.booking.BookingEvent;
+import org.jboss.seam.examples.booking.booking.Confirmed;
+import org.jboss.seam.examples.booking.account.Registered;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logger;
+import org.jboss.seam.examples.booking.controls.BookingFormControls;
+
+public
+ at Named("bookingAgent")
+ at Stateful
+ at ConversationScoped
+class BookingAgentBean implements BookingAgent
+{
+ private @Logger Log log;
+
+ @PersistenceContext(type = EXTENDED) EntityManager em;
+
+ @Current Conversation conversation;
+
+ @Current StatusMessages statusMessages;
+
+ @Current BookingFormControls formControls;
+
+ @Registered User user;
+
+ //@Fires @Confirmed Event<BookingEvent> bookingConfirmedEvent;
+
+ private Hotel hotelSelection;
+
+ private Booking booking;
+
+ private boolean bookingValid;
+
+ public void selectHotel(Hotel hotel)
+ {
+ // NOTE get a fresh reference that's managed by the conversational persistence context
+ hotelSelection = em.find(Hotel.class, hotel.getId());
+ log.info("Selected the " + hotelSelection.getName() + " in " + hotelSelection.getCity());
+ conversation.begin();
+ }
+
+ public void bookHotel()
+ {
+ booking = new Booking(hotelSelection, user);
+ // QUESTION push logic into Booking?
+ Calendar calendar = Calendar.getInstance();
+ booking.setCheckinDate(calendar.getTime());
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
+ booking.setCheckoutDate(calendar.getTime());
+ hotelSelection = null;
+ statusMessages.add("You've initiated a booking at {0}.", booking.getHotel().getName());
+ }
+
+ public void validateBooking()
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ if (booking.getCheckinDate().before(calendar.getTime()))
+ {
+ statusMessages.addToControl(formControls.getCheckinDateControlId(), "Check in date must be a future date");
+ bookingValid = false;
+ }
+ else if (!booking.getCheckinDate().before(booking.getCheckoutDate()))
+ {
+ statusMessages.addToControl(formControls.getCheckoutDateControlId(), "Check out date must be after check in date");
+ bookingValid = false;
+ }
+ else
+ {
+ bookingValid = true;
+ }
+ }
+
+ public void confirm()
+ {
+ em.persist(booking);
+ //bookingConfirmedEvent.fire(new BookingEvent(booking));
+ log.info("New booking at the " + booking.getHotel().getName() + " confirmed for " + booking.getUser().getName());
+ statusMessages.add("You're booked!");
+ conversation.end();
+ }
+
+ public void cancel()
+ {
+ booking = null;
+ hotelSelection = null;
+ conversation.end();
+ }
+
+ public
+ @Produces
+ @Named
+ @ConversationScoped
+ Booking getBooking()
+ {
+ return booking;
+ }
+
+ public
+ @Produces
+ @Named("hotel")
+ @RequestScoped
+ Hotel getHotelSelection()
+ {
+ return booking != null ? booking.getHotel() : hotelSelection;
+ }
+
+ public boolean isBookingValid()
+ {
+ return bookingValid;
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistory.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,22 @@
+package org.jboss.seam.examples.booking.booking;
+
+import java.util.List;
+import javax.ejb.Local;
+import org.jboss.seam.examples.booking.booking.BookingEvent;
+import org.jboss.seam.examples.booking.model.Booking;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Local
+interface BookingHistory
+{
+ List<Booking> getBookingsForCurrentUser();
+
+ void cancelBooking(Booking booking);
+
+ void destroy();
+
+ void afterBookingConfirmed(BookingEvent bookingEvent);
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistoryBean.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,85 @@
+package org.jboss.seam.examples.booking.booking;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Named;
+import javax.annotation.PreDestroy;
+import javax.context.RequestScoped;
+import javax.context.SessionScoped;
+import javax.ejb.Stateful;
+import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.booking.BookingEvent;
+import org.jboss.seam.examples.booking.booking.Confirmed;
+import org.jboss.seam.examples.booking.account.Registered;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logger;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Named("bookingHistory")
+ at Stateful
+ at SessionScoped
+class BookingHistoryBean implements BookingHistory {
+
+ private @Logger Log log;
+
+ @PersistenceContext EntityManager em;
+
+ @Current StatusMessages statusMessages;
+
+ @Registered User user;
+
+ private List<Booking> bookingsForUser = new ArrayList<Booking>();
+
+ public
+ @Produces
+ @Registered
+ @Named("bookings")
+ @SessionScoped
+ List<Booking> getBookingsForCurrentUser()
+ {
+ bookingsForUser.clear();
+ bookingsForUser.addAll(em.createQuery("select b from Booking b join fetch b.hotel where b.user.username = :username order by b.checkinDate")
+ .setParameter("username", user.getUsername())
+ .getResultList());
+ return bookingsForUser;
+ }
+
+ // TODO should probably observe after transaction success
+ public void afterBookingConfirmed(@Observes @Confirmed BookingEvent bookingEvent)
+ {
+ getBookingsForCurrentUser();
+ }
+
+ public void cancelBooking(Booking selectedBooking)
+ {
+ log.info("Canceling booking " + selectedBooking.getId() + " for " + user.getName());
+ Booking booking = em.find(Booking.class, selectedBooking.getId());
+ if (booking != null)
+ {
+ em.remove(booking);
+ statusMessages.add("The booking at the {0} on {1,date} has been canceled.", selectedBooking.getHotel().getName(), selectedBooking.getCheckinDate());
+ }
+ else
+ {
+ statusMessages.add("Our records indicate that the booking you selected has already been canceled.");
+ }
+
+ bookingsForUser.remove(selectedBooking);
+ }
+
+ @PreDestroy
+ public void destroy()
+ {
+ }
+
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java (from rev 10713, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.inventory;
+
+import java.util.List;
+import javax.ejb.Local;
+import org.jboss.seam.examples.booking.model.Hotel;
+
+public
+ at Local
+interface HotelSearch
+{
+ public void find();
+
+ public void previousPage();
+
+ public void nextPage();
+
+ public List<Hotel> getHotels();
+
+ public boolean isNextPageAvailable();
+
+ public boolean isPreviousPageAvailable();
+
+ public void destroy();
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.inventory;
+
+import org.jboss.seam.examples.booking.session.*;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logger;
+
+public
+ at Named("hotelSearch")
+ at Stateful
+ at SessionScoped
+class HotelSearchBean implements HotelSearch
+{
+ private @Logger Log log;
+
+ @PersistenceContext EntityManager em;
+
+ @Current SearchCriteria criteria;
+
+ private boolean nextPageAvailable = false;
+
+ private List<Hotel> hotels = new ArrayList<Hotel>();
+
+ public void find()
+ {
+ criteria.firstPage();
+ queryHotels(criteria);
+ }
+
+ public void nextPage()
+ {
+ criteria.nextPage();
+ queryHotels(criteria);
+ }
+
+ public void previousPage()
+ {
+ criteria.previousPage();
+ queryHotels(criteria);
+ }
+
+ public
+ @Produces
+ @Named
+ //@RequestScoped // if enabled, variable doesn't get updated after the action is executed w/o a redirect
+ List<Hotel> getHotels()
+ {
+ return hotels;
+ }
+
+ public boolean isNextPageAvailable()
+ {
+ return nextPageAvailable;
+ }
+
+ public boolean isPreviousPageAvailable()
+ {
+ return criteria.getPage() > 0;
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+
+ private void queryHotels(SearchCriteria criteria)
+ {
+ List<Hotel> results = 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").
+ setParameter("pattern", criteria.getSearchPattern()).setMaxResults(criteria.getPageSize() + 1).setFirstResult(criteria.getPage() * criteria.getPageSize()).
+ getResultList();
+
+ nextPageAvailable = results.size() > criteria.getPageSize();
+ if (nextPageAvailable)
+ {
+ hotels = new ArrayList<Hotel>(results.subList(0, criteria.getPageSize()));
+ }
+ else
+ {
+ hotels = results;
+ }
+ log.info("Found " + hotels.size() + " hotels matching search term '" + criteria.getSearchString() + "' (limit " + criteria.getPageSize() + ")");
+ }
+}
Copied: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java (from rev 10734, examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java)
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.examples.booking.inventory;
+
+import java.io.Serializable;
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+
+public
+ at Named
+ at SessionScoped
+class SearchCriteria implements Serializable
+{
+ private static final char SQL_WILDCARD_CHAR = '%';
+ private static final String SQL_WILDCARD_STR = String.valueOf(SQL_WILDCARD_CHAR);
+ private static final String REPEAT_SQL_WIDCARD_REGEX = SQL_WILDCARD_STR + "+";
+ private static final char HUMAN_WILDCARD_CHAR = '*';
+
+ private String searchString = "";
+ private int pageSize = 5;
+ private int page = 0;
+
+ public String getSearchPattern()
+ {
+ if (searchString == null || searchString.length() == 0)
+ {
+ return SQL_WILDCARD_STR;
+ }
+
+ StringBuilder pattern = new StringBuilder();
+ pattern.append(searchString.toLowerCase().replace(HUMAN_WILDCARD_CHAR, SQL_WILDCARD_CHAR).replaceAll(REPEAT_SQL_WIDCARD_REGEX, SQL_WILDCARD_STR));
+ if (pattern.length() == 0 || pattern.charAt(0) != SQL_WILDCARD_CHAR)
+ {
+ pattern.insert(0, SQL_WILDCARD_CHAR);
+ }
+ if (pattern.length() > 1 && pattern.charAt(pattern.length() - 1) != SQL_WILDCARD_CHAR)
+ {
+ pattern.append(SQL_WILDCARD_CHAR);
+ }
+ return pattern.toString();
+ }
+
+ public int getPage()
+ {
+ return page;
+ }
+
+ public void setPage(int page)
+ {
+ this.page = page;
+ }
+
+ public int getPageSize()
+ {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize)
+ {
+ this.pageSize = pageSize;
+ }
+
+ // QUESTION: rename to searchTerm?
+ public String getSearchString()
+ {
+ return searchString;
+ }
+
+ public void setSearchString(String searchString)
+ {
+ this.searchString = (searchString != null ? searchString.trim() : null);
+ }
+
+ public void nextPage()
+ {
+ page++;
+ }
+
+ public void previousPage()
+ {
+ if (page > 0)
+ {
+ page--;
+ }
+ }
+
+ public void firstPage()
+ {
+ page = 0;
+ }
+}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducer.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducer.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducer.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,17 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.model.User;
-
-/**
- * The <strong>AccountProducer</strong> produces the object that
- * represents the current user's account information. The account
- * information is represented by the {@link User} entity.
- *
- * @author Dan Allen
- */
-public
- at Local
-interface AccountProducer {
- User getCurrentAccount();
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducerBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducerBean.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducerBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,45 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import javax.annotation.Named;
-import javax.context.SessionScoped;
-import javax.ejb.Stateless;
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.Registered;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.examples.booking.security.Identity;
-
-/**
- * @author Dan Allen
- */
-public
- at Stateless
-class AccountProducerBean implements AccountProducer
-{
- @PersistenceContext EntityManager em;
-
- @Current Identity identity;
-
- public
- @Produces
- @Registered
- @Named("user")
- @SessionScoped
- User getCurrentAccount()
- {
- if (identity.isLoggedIn())
- {
- User user = em.find(User.class, identity.getUsername());
- if (user != null)
- {
- user.setPassword(null);
- return user;
- }
- }
-
- // TODO can't return null, but then we are not honoring the semantics of our binding type
- return new User();
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgent.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * $Id$
- */
-package org.jboss.seam.examples.booking.session;
-
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.model.Booking;
-import org.jboss.seam.examples.booking.model.Hotel;
-
-/**
- * @author Dan Allen
- */
-public
- at Local
-interface BookingAgent
-{
- void selectHotel(Hotel hotel);
-
- void bookHotel();
-
- void validateBooking();
-
- void cancel();
-
- void confirm();
-
- Hotel getHotelSelection();
-
- Booking getBooking();
-
- boolean isBookingValid();
-
- void destroy();
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,160 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * $Id$
- */
-package org.jboss.seam.examples.booking.session;
-
-import java.util.Calendar;
-import static javax.persistence.PersistenceContextType.EXTENDED;
-import javax.annotation.Named;
-import javax.context.Conversation;
-import javax.context.ConversationScoped;
-import javax.context.RequestScoped;
-import javax.ejb.Remove;
-import javax.ejb.Stateful;
-import javax.event.Event;
-import javax.event.Fires;
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.BookingEvent;
-import org.jboss.seam.examples.booking.Confirmed;
-import org.jboss.seam.examples.booking.Registered;
-import org.jboss.seam.examples.booking.model.Booking;
-import org.jboss.seam.examples.booking.model.Hotel;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.international.StatusMessages;
-import org.jboss.webbeans.log.Log;
-import org.jboss.webbeans.log.Logger;
-import ui.BookingFormControls;
-
-public
- at Named("bookingAgent")
- at Stateful
- at ConversationScoped
-class BookingAgentBean implements BookingAgent
-{
- private @Logger Log log;
-
- @PersistenceContext(type = EXTENDED) EntityManager em;
-
- @Current Conversation conversation;
-
- @Current StatusMessages statusMessages;
-
- @Current BookingFormControls formControls;
-
- @Registered User user;
-
- //@Fires @Confirmed Event<BookingEvent> bookingConfirmedEvent;
-
- private Hotel hotelSelection;
-
- private Booking booking;
-
- private boolean bookingValid;
-
- public void selectHotel(Hotel hotel)
- {
- // NOTE get a fresh reference that's managed by the conversational persistence context
- hotelSelection = em.find(Hotel.class, hotel.getId());
- log.info("Selected the " + hotelSelection.getName() + " in " + hotelSelection.getCity());
- conversation.begin();
- }
-
- public void bookHotel()
- {
- booking = new Booking(hotelSelection, user);
- // QUESTION push logic into Booking?
- Calendar calendar = Calendar.getInstance();
- booking.setCheckinDate(calendar.getTime());
- calendar.add(Calendar.DAY_OF_MONTH, 1);
- booking.setCheckoutDate(calendar.getTime());
- hotelSelection = null;
- statusMessages.add("You've initiated a booking at {0}.", booking.getHotel().getName());
- }
-
- public void validateBooking()
- {
- Calendar calendar = Calendar.getInstance();
- calendar.add(Calendar.DAY_OF_MONTH, -1);
- if (booking.getCheckinDate().before(calendar.getTime()))
- {
- statusMessages.addToControl(formControls.getCheckinDateControlId(), "Check in date must be a future date");
- bookingValid = false;
- }
- else if (!booking.getCheckinDate().before(booking.getCheckoutDate()))
- {
- statusMessages.addToControl(formControls.getCheckoutDateControlId(), "Check out date must be after check in date");
- bookingValid = false;
- }
- else
- {
- bookingValid = true;
- }
- }
-
- public void confirm()
- {
- em.persist(booking);
- //bookingConfirmedEvent.fire(new BookingEvent(booking));
- log.info("New booking at the " + booking.getHotel().getName() + " confirmed for " + booking.getUser().getName());
- statusMessages.add("You're booked!");
- conversation.end();
- }
-
- public void cancel()
- {
- booking = null;
- hotelSelection = null;
- conversation.end();
- }
-
- public
- @Produces
- @Named
- @ConversationScoped
- Booking getBooking()
- {
- return booking;
- }
-
- public
- @Produces
- @Named("hotel")
- @RequestScoped
- Hotel getHotelSelection()
- {
- return booking != null ? booking.getHotel() : hotelSelection;
- }
-
- public boolean isBookingValid()
- {
- return bookingValid;
- }
-
- @Remove
- public void destroy()
- {
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistory.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistory.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistory.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,22 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import java.util.List;
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.BookingEvent;
-import org.jboss.seam.examples.booking.model.Booking;
-
-/**
- * @author Dan Allen
- */
-public
- at Local
-interface BookingHistory
-{
- List<Booking> getBookingsForCurrentUser();
-
- void cancelBooking(Booking booking);
-
- void destroy();
-
- void afterBookingConfirmed(BookingEvent bookingEvent);
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistoryBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistoryBean.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistoryBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,85 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Named;
-import javax.annotation.PreDestroy;
-import javax.context.RequestScoped;
-import javax.context.SessionScoped;
-import javax.ejb.Stateful;
-import javax.event.Observes;
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.BookingEvent;
-import org.jboss.seam.examples.booking.Confirmed;
-import org.jboss.seam.examples.booking.Registered;
-import org.jboss.seam.examples.booking.model.Booking;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.international.StatusMessages;
-import org.jboss.webbeans.log.Log;
-import org.jboss.webbeans.log.Logger;
-
-/**
- * @author Dan Allen
- */
-public
- at Named("bookingHistory")
- at Stateful
- at SessionScoped
-class BookingHistoryBean implements BookingHistory {
-
- private @Logger Log log;
-
- @PersistenceContext EntityManager em;
-
- @Current StatusMessages statusMessages;
-
- @Registered User user;
-
- private List<Booking> bookingsForUser = new ArrayList<Booking>();
-
- public
- @Produces
- @Registered
- @Named("bookings")
- @SessionScoped
- List<Booking> getBookingsForCurrentUser()
- {
- bookingsForUser.clear();
- bookingsForUser.addAll(em.createQuery("select b from Booking b join fetch b.hotel where b.user.username = :username order by b.checkinDate")
- .setParameter("username", user.getUsername())
- .getResultList());
- return bookingsForUser;
- }
-
- // TODO should probably observe after transaction success
- public void afterBookingConfirmed(@Observes @Confirmed BookingEvent bookingEvent)
- {
- getBookingsForCurrentUser();
- }
-
- public void cancelBooking(Booking selectedBooking)
- {
- log.info("Canceling booking " + selectedBooking.getId() + " for " + user.getName());
- Booking booking = em.find(Booking.class, selectedBooking.getId());
- if (booking != null)
- {
- em.remove(booking);
- statusMessages.add("The booking at the {0} on {1,date} has been canceled.", selectedBooking.getHotel().getName(), selectedBooking.getCheckinDate());
- }
- else
- {
- statusMessages.add("Our records indicate that the booking you selected has already been canceled.");
- }
-
- bookingsForUser.remove(selectedBooking);
- }
-
- @PreDestroy
- public void destroy()
- {
- }
-
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearch.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * $Id$
- */
-package org.jboss.seam.examples.booking.session;
-
-import java.util.List;
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.model.Hotel;
-
-public
- at Local
-interface HotelSearch
-{
- public void find();
-
- public void previousPage();
-
- public void nextPage();
-
- public List<Hotel> getHotels();
-
- public boolean isNextPageAvailable();
-
- public boolean isPreviousPageAvailable();
-
- public void destroy();
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * $Id$
- */
-package org.jboss.seam.examples.booking.session;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Named;
-import javax.context.SessionScoped;
-import javax.ejb.Remove;
-import javax.ejb.Stateful;
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.model.Hotel;
-import org.jboss.webbeans.log.Log;
-import org.jboss.webbeans.log.Logger;
-
-public
- at Named("hotelSearch")
- at Stateful
- at SessionScoped
-class HotelSearchBean implements HotelSearch
-{
- private @Logger Log log;
-
- @PersistenceContext EntityManager em;
-
- @Current SearchCriteria criteria;
-
- private boolean nextPageAvailable = false;
-
- private List<Hotel> hotels = new ArrayList<Hotel>();
-
- public void find()
- {
- criteria.firstPage();
- queryHotels(criteria);
- }
-
- public void nextPage()
- {
- criteria.nextPage();
- queryHotels(criteria);
- }
-
- public void previousPage()
- {
- criteria.previousPage();
- queryHotels(criteria);
- }
-
- public
- @Produces
- @Named
- //@RequestScoped // if enabled, variable doesn't get updated after the action is executed w/o a redirect
- List<Hotel> getHotels()
- {
- return hotels;
- }
-
- public boolean isNextPageAvailable()
- {
- return nextPageAvailable;
- }
-
- public boolean isPreviousPageAvailable()
- {
- return criteria.getPage() > 0;
- }
-
- @Remove
- public void destroy()
- {
- }
-
- private void queryHotels(SearchCriteria criteria)
- {
- List<Hotel> results = 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").
- setParameter("pattern", criteria.getSearchPattern()).setMaxResults(criteria.getPageSize() + 1).setFirstResult(criteria.getPage() * criteria.getPageSize()).
- getResultList();
-
- nextPageAvailable = results.size() > criteria.getPageSize();
- if (nextPageAvailable)
- {
- hotels = new ArrayList<Hotel>(results.subList(0, criteria.getPageSize()));
- }
- else
- {
- hotels = results;
- }
- log.info("Found " + hotels.size() + " hotels matching search term '" + criteria.getSearchString() + "' (limit " + criteria.getPageSize() + ")");
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManager.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManager.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManager.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,26 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import javax.ejb.Local;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-/**
- *
- * @author Dan Allen
- */
-public
- at Local
-interface PasswordManager
-{
- void changePassword();
-
- boolean isChanged();
-
- void setConfirmPassword(String password);
-
- @NotNull
- @Size(min = 5, max = 15)
- String getConfirmPassword();
-
- void destroy();
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManagerBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManagerBean.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManagerBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,74 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import javax.annotation.Named;
-import javax.annotation.PreDestroy;
-import javax.context.RequestScoped;
-import javax.ejb.Stateful;
-import javax.inject.Current;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.Registered;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.international.StatusMessages;
-import ui.RegistrationFormControls;
-
-/**
- * @author Dan Allen
- */
-public
- at Named("passwordManager")
- at Stateful
- at RequestScoped
-class PasswordManagerBean implements PasswordManager
-{
- @PersistenceContext EntityManager em;
-
- @Current StatusMessages statusMessages;
-
- @Current RegistrationFormControls formControls;
-
- @Registered User user;
-
- private String confirmPassword;
-
- private boolean changed;
-
- public void changePassword()
- {
- if (user.getPassword().equals(confirmPassword))
- {
- // FIXME: dirty hack, can't merge a managed bean
- em.merge(new User(user.getName(), user.getUsername(), user.getPassword()));
- user.setPassword(null);
- statusMessages.add("Password successfully updated.");
- changed = true;
- }
- else
- {
- // FIME reverting isn't going to work here
- //revertUser();
- confirmPassword = null;
- statusMessages.addToControl(formControls.getConfirmPasswordControlId(), "Passwords do not match. Please re-type the new password.");
- }
- }
-
- public boolean isChanged()
- {
- return changed;
- }
-
- public void setConfirmPassword(String password)
- {
- this.confirmPassword = password;
- }
-
- public String getConfirmPassword()
- {
- return this.confirmPassword;
- }
-
- @PreDestroy
- public void destroy()
- {
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/Registrar.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/Registrar.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/Registrar.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,32 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import javax.ejb.Local;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-import org.jboss.seam.examples.booking.model.User;
-
-/**
- * @author Dan Allen
- */
-public
- at Local
-interface Registrar
-{
- void register();
-
- boolean isRegistrationInvalid();
-
- void notifyIfRegistrationIsInvalid(boolean validationFailed);
-
- User getNewUser();
-
- boolean isRegistered();
-
- @NotNull
- @Size(min = 5, max = 15)
- String getConfirmPassword();
-
- void setConfirmPassword(String password);
-
- void destroy();
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/RegistrarBean.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/RegistrarBean.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/RegistrarBean.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,131 +0,0 @@
-package org.jboss.seam.examples.booking.session;
-
-import javax.annotation.Named;
-import javax.annotation.PreDestroy;
-import javax.context.RequestScoped;
-import javax.ejb.Stateful;
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.examples.booking.security.Credentials;
-import org.jboss.seam.examples.booking.security.Identity;
-import org.jboss.seam.international.StatusMessage;
-import org.jboss.seam.international.StatusMessages;
-import ui.RegistrationFormControls;
-
-/**
- * @author Dan Allen
- */
-public
- at Named("registrar")
- at Stateful
- at RequestScoped
-class RegistrarBean implements Registrar
-{
- @PersistenceContext EntityManager em;
-
- @Current StatusMessages statusMessages;
-
- @Current RegistrationFormControls formControls;
-
- @Current Credentials credentials;
-
- @Current Identity identity;
-
- private User newUser;
-
- private String confirmPassword;
-
- private boolean registered;
-
- private boolean registrationInvalid;
-
- public void register()
- {
- if (verifyPasswordsMatch() && verifyUsernameIsAvailable())
- {
- em.persist(newUser);
- credentials.setUsername(newUser.getUsername());
- identity.autoLogin();
- registered = true;
- statusMessages.add("You have been successfully registered as the user {0}!", newUser.getUsername());
- }
- else
- {
- registrationInvalid = true;
- }
- }
-
- public boolean isRegistrationInvalid()
- {
- return registrationInvalid;
- }
-
- // TODO it would be nice to move the conditional to the UI but <f:event> doesn't support if=""
- public void notifyIfRegistrationIsInvalid(boolean validationFailed)
- {
- if (validationFailed || registrationInvalid)
- {
- statusMessages.add(StatusMessage.Severity.WARN, "Invalid registration. Please correct the errors and try again.");
- }
- }
-
- public
- @Produces
- @Named
- @RequestScoped
- User getNewUser()
- {
- newUser = new User();
- return newUser;
- }
-
- public boolean isRegistered()
- {
- return registered;
- }
-
- public String getConfirmPassword()
- {
- return confirmPassword;
- }
-
- public void setConfirmPassword(String password)
- {
- this.confirmPassword = password;
- }
-
- /**
- * Verify that the same password is entered twice.
- */
- private boolean verifyPasswordsMatch()
- {
- if (!newUser.getPassword().equals(confirmPassword))
- {
- statusMessages.addToControl(formControls.getConfirmPasswordControlId(), "Passwords do not match. Please re-type your password.");
- confirmPassword = null;
- return false;
- }
-
- return true;
- }
-
- private boolean verifyUsernameIsAvailable()
- {
- User existing = em.find(User.class, newUser.getUsername());
- if (existing != null)
- {
- statusMessages.addToControl(formControls.getUsernameControlId(), "The username '{0}' is already taken. Please choose another username.", newUser.getUsername());
- return false;
- }
-
- return true;
- }
-
- @PreDestroy
- public void destroy()
- {
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,112 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * $Id$
- */
-package org.jboss.seam.examples.booking.session;
-
-import java.io.Serializable;
-import javax.annotation.Named;
-import javax.context.SessionScoped;
-
-public
- at Named
- at SessionScoped
-class SearchCriteria implements Serializable
-{
- private static final char SQL_WILDCARD_CHAR = '%';
- private static final String SQL_WILDCARD_STR = String.valueOf(SQL_WILDCARD_CHAR);
- private static final String REPEAT_SQL_WIDCARD_REGEX = SQL_WILDCARD_STR + "+";
- private static final char HUMAN_WILDCARD_CHAR = '*';
-
- private String searchString = "";
- private int pageSize = 5;
- private int page = 0;
-
- public String getSearchPattern()
- {
- if (searchString == null || searchString.length() == 0)
- {
- return SQL_WILDCARD_STR;
- }
-
- StringBuilder pattern = new StringBuilder();
- pattern.append(searchString.toLowerCase().replace(HUMAN_WILDCARD_CHAR, SQL_WILDCARD_CHAR).replaceAll(REPEAT_SQL_WIDCARD_REGEX, SQL_WILDCARD_STR));
- if (pattern.length() == 0 || pattern.charAt(0) != SQL_WILDCARD_CHAR)
- {
- pattern.insert(0, SQL_WILDCARD_CHAR);
- }
- if (pattern.length() > 1 && pattern.charAt(pattern.length() - 1) != SQL_WILDCARD_CHAR)
- {
- pattern.append(SQL_WILDCARD_CHAR);
- }
- return pattern.toString();
- }
-
- public int getPage()
- {
- return page;
- }
-
- public void setPage(int page)
- {
- this.page = page;
- }
-
- public int getPageSize()
- {
- return pageSize;
- }
-
- public void setPageSize(int pageSize)
- {
- this.pageSize = pageSize;
- }
-
- // QUESTION: rename to searchTerm?
- public String getSearchString()
- {
- return searchString;
- }
-
- public void setSearchString(String searchString)
- {
- this.searchString = (searchString != null ? searchString.trim() : null);
- }
-
- public void nextPage()
- {
- page++;
- }
-
- public void previousPage()
- {
- if (page > 0)
- {
- page--;
- }
- }
-
- public void firstPage()
- {
- page = 0;
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,51 +0,0 @@
-package ui;
-
-import javax.annotation.Named;
-import javax.context.RequestScoped;
-import javax.faces.component.UIComponent;
-
-/**
- * A UI binding bean that can provide access to the local id and client id
- * of selected input components in the booking form.
- *
- * @author Dan Allen
- */
-public
- at Named
- at RequestScoped
-class BookingFormControls
-{
- private UIComponent checkinDate;
-
- private UIComponent checkoutDate;
-
- public UIComponent getCheckinDate()
- {
- return checkinDate;
- }
-
- public String getCheckinDateControlId()
- {
- return checkinDate.getClientId();
- }
-
- public void setCheckinDate(UIComponent checkinDate)
- {
- this.checkinDate = checkinDate;
- }
-
- public UIComponent getCheckoutDate()
- {
- return checkoutDate;
- }
-
- public void setCheckoutDate(UIComponent checkoutDate)
- {
- this.checkoutDate = checkoutDate;
- }
-
- public String getCheckoutDateControlId()
- {
- return checkoutDate.getClientId();
- }
-}
Deleted: examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java 2009-05-01 19:42:23 UTC (rev 10742)
+++ examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java 2009-05-01 19:49:27 UTC (rev 10743)
@@ -1,52 +0,0 @@
-package ui;
-
-import javax.annotation.Named;
-import javax.context.RequestScoped;
-import javax.faces.component.UIComponent;
-
-/**
- * A UI binding bean that can provide access to the local id and client id
- * of selected input components in the registration form.
- *
- * @author Dan Allen
- */
-public
- at Named
- at RequestScoped
-class RegistrationFormControls
-{
- private UIComponent username;
-
- private UIComponent confirmPassword;
-
- public UIComponent getConfirmPassword()
- {
- return confirmPassword;
- }
-
- public void setConfirmPassword(UIComponent confirmPassword)
- {
- this.confirmPassword = confirmPassword;
- }
-
- public String getConfirmPasswordControlId()
- {
- return confirmPassword.getClientId();
- }
-
- public UIComponent getUsername()
- {
- return username;
- }
-
- public void setUsername(UIComponent username)
- {
- this.username = username;
- }
-
- public String getUsernameControlId()
- {
- return username.getClientId();
- }
-
-}
More information about the seam-commits
mailing list