[seam-commits] Seam SVN: r10734 - in examples/trunk/booking: ejb-jar/src/main/java/org/jboss/seam/examples/booking and 8 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Apr 30 16:26:53 EDT 2009
Author: dan.j.allen
Date: 2009-04-30 16:26:53 -0400 (Thu, 30 Apr 2009)
New Revision: 10734
Added:
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/security/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/security/Identity.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/ui/
examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java
examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java
Modified:
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/model/Booking.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.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/BookingAgentBean.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/RegistrarBean.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java
examples/trunk/booking/war/src/main/webapp/WEB-INF/faces-config.xml
examples/trunk/booking/war/src/main/webapp/WEB-INF/layout/template.xhtml
examples/trunk/booking/war/src/main/webapp/css/screen.css
examples/trunk/booking/war/src/main/webapp/home.xhtml
examples/trunk/booking/war/src/main/webapp/main.xhtml
examples/trunk/booking/war/src/main/webapp/password.xhtml
Log:
add hotel booking history
add temporary identity component to simulate authentication and current user
add @Registered binding type for registered User
finish change password screen
stub out event to be fired when booking is confirmed (not working yet)
get @Logger annotation working
fix ajax pagination (was executing action method twice)
Added: 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 (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/BookingEvent.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,25 @@
+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;
+ }
+}
Added: 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 (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Confirmed.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,30 @@
+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
+{
+}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/Registered.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -11,7 +11,7 @@
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
-import javax.inject.DeploymentType;
+import javax.inject.BindingType;
import org.jboss.seam.examples.booking.model.User;
/**
@@ -28,7 +28,7 @@
})
@Retention(RUNTIME)
@Documented
- at DeploymentType
+ at BindingType
@Inherited
@interface Registered
{
Modified: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Booking.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -73,6 +73,7 @@
{
this.hotel = hotel;
this.user = user;
+ this.creditCardName = user.getName();
}
@Id
Modified: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -31,6 +31,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -148,6 +149,12 @@
this.price = price;
}
+ @Transient
+ public String getLocation()
+ {
+ return city + ", " + state + ", " + country;
+ }
+
@Override
public String toString()
{
Modified: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/model/User.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -49,11 +49,11 @@
private String password;
private String name;
- public User(String name, String password, String username)
+ public User(String name, String username, String password)
{
this.name = name;
+ this.username = username;
this.password = password;
- this.username = username;
}
public User()
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/security/Identity.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/security/Identity.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/security/Identity.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,74 @@
+package org.jboss.seam.examples.booking.security;
+
+import java.io.Serializable;
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+import javax.faces.context.FacesContext;
+import javax.inject.manager.Manager;
+
+/**
+ * @author Dan Allen
+ */
+public
+ at Named
+ at SessionScoped
+class Identity implements Serializable
+{
+ private String username;
+
+ private String password;
+
+ private boolean loggedIn;
+
+ public boolean isLoggedIn()
+ {
+ return loggedIn;
+ }
+
+ public void setLoggedIn(boolean loggedIn)
+ {
+ this.loggedIn = loggedIn;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ public boolean login()
+ {
+ if (username != null && username.length() > 0)
+ {
+ password = null;
+ loggedIn = true;
+ return true;
+ }
+
+ return false;
+ }
+
+ Manager manager;
+
+ public void logout()
+ {
+ username = null;
+ loggedIn = false;
+ // FIXME this is a dirty hack to reset a producer
+ FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
+ }
+}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/AccountProducerBean.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -3,11 +3,13 @@
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
@@ -16,16 +18,28 @@
@Stateless
class AccountProducerBean implements AccountProducer
{
- private @PersistenceContext EntityManager em;
+ @PersistenceContext EntityManager em;
+ @Current Identity identity;
+
public
@Produces
-// @Registered // FIXME not resolving"user" variable if binding type is present
+ @Registered
@Named("user")
@SessionScoped
User getCurrentAccount()
{
- // FIXME provide a real implementation
- return em.find(User.class, "dan");
+ 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();
}
}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingAgentBean.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -31,10 +31,15 @@
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;
@@ -49,7 +54,7 @@
@ConversationScoped
class BookingAgentBean implements BookingAgent
{
- //private @Logger Log log;
+ private @Logger Log log;
@PersistenceContext(type = EXTENDED) EntityManager em;
@@ -59,6 +64,10 @@
@Current BookingFormControls formControls;
+ @Registered User user;
+
+ //@Fires @Confirmed Event<BookingEvent> bookingConfirmedEvent;
+
private Hotel hotelSelection;
private Booking booking;
@@ -67,17 +76,16 @@
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();
- // get a fresh reference that's managed by the conversational persistence context
- hotelSelection = em.find(Hotel.class, hotel.getId());
}
public void bookHotel()
{
- // FIXME use current user
- User user = em.find(User.class, "dan");
booking = new Booking(hotelSelection, user);
- // push logic into Booking?
+ // QUESTION push logic into Booking?
Calendar calendar = Calendar.getInstance();
booking.setCheckinDate(calendar.getTime());
calendar.add(Calendar.DAY_OF_MONTH, 1);
@@ -109,7 +117,8 @@
public void confirm()
{
em.persist(booking);
- //log.info("New booking confirmed for...");
+ //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();
}
Added: 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 (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistory.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,22 @@
+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);
+}
Added: 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 (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/BookingHistoryBean.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,85 @@
+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()
+ {
+ }
+
+}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/HotelSearchBean.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -31,10 +31,11 @@
import javax.ejb.Stateful;
import javax.inject.Current;
import javax.inject.Produces;
-import javax.inject.manager.Manager;
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
@Named("hotelSearch")
@@ -42,11 +43,14 @@
@SessionScoped
class HotelSearchBean implements HotelSearch
{
- @Current Manager manager;
+ private @Logger Log log;
+
+ @PersistenceContext EntityManager em;
+
@Current SearchCriteria criteria;
- private @PersistenceContext EntityManager em;
private boolean nextPageAvailable = false;
+
private List<Hotel> hotels = new ArrayList<Hotel>();
public void find()
@@ -98,7 +102,6 @@
setParameter("pattern", criteria.getSearchPattern()).setMaxResults(criteria.getPageSize() + 1).setFirstResult(criteria.getPage() * criteria.getPageSize()).
getResultList();
- System.out.println("Found " + results.size() + " hotels");
nextPageAvailable = results.size() > criteria.getPageSize();
if (nextPageAvailable)
{
@@ -108,5 +111,6 @@
{
hotels = results;
}
+ log.info("Found " + hotels.size() + " hotels matching search term '" + criteria.getSearchString() + "' (limit " + criteria.getPageSize() + ")");
}
}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManager.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -1,6 +1,8 @@
package org.jboss.seam.examples.booking.session;
import javax.ejb.Local;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
/**
*
@@ -8,10 +10,17 @@
*/
public
@Local
-interface PasswordManager {
+interface PasswordManager
+{
void changePassword();
+
boolean isChanged();
+
void setConfirmPassword(String password);
+
+ @NotNull
+ @Size(min = 5, max = 15)
String getConfirmPassword();
+
void destroy();
}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/PasswordManagerBean.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -1,5 +1,6 @@
package org.jboss.seam.examples.booking.session;
+import javax.annotation.Named;
import javax.annotation.PreDestroy;
import javax.context.RequestScoped;
import javax.ejb.Stateful;
@@ -12,21 +13,21 @@
import ui.RegistrationFormControls;
/**
- *
* @author Dan Allen
*/
public
+ at Named("passwordManager")
@Stateful
@RequestScoped
class PasswordManagerBean implements PasswordManager
{
- private @PersistenceContext EntityManager em;
+ @PersistenceContext EntityManager em;
- private @Current StatusMessages statusMessages;
+ @Current StatusMessages statusMessages;
- private @Current RegistrationFormControls formControls;
+ @Current RegistrationFormControls formControls;
- private @Registered User user;
+ @Registered User user;
private String confirmPassword;
@@ -36,7 +37,9 @@
{
if (user.getPassword().equals(confirmPassword))
{
- user = em.merge(user);
+ // 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;
}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/RegistrarBean.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -9,6 +9,7 @@
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.examples.booking.security.Identity;
import org.jboss.seam.international.StatusMessage;
import org.jboss.seam.international.StatusMessages;
import ui.RegistrationFormControls;
@@ -22,18 +23,14 @@
@RequestScoped
class RegistrarBean implements Registrar
{
- private
- @PersistenceContext
- EntityManager em;
+ @PersistenceContext EntityManager em;
- private
- @Current
- StatusMessages statusMessages;
+ @Current StatusMessages statusMessages;
- private
- @Current
- RegistrationFormControls formControls;
+ @Current RegistrationFormControls formControls;
+ @Current Identity identity;
+
private User newUser;
private String confirmPassword;
@@ -47,6 +44,8 @@
if (verifyPasswordsMatch() && verifyUsernameIsAvailable())
{
em.persist(newUser);
+ identity.setUsername(newUser.getUsername());
+ identity.login();
registered = true;
statusMessages.add("You have been successfully registered as the user {0}!", newUser.getUsername());
}
Modified: 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-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/session/SearchCriteria.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -81,6 +81,7 @@
this.pageSize = pageSize;
}
+ // QUESTION: rename to searchTerm?
public String getSearchString()
{
return searchString;
Added: examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/ui/BookingFormControls.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,51 @@
+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();
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/ui/RegistrationFormControls.java 2009-04-30 20:26:53 UTC (rev 10734)
@@ -0,0 +1,52 @@
+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();
+ }
+
+}
Modified: examples/trunk/booking/war/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- examples/trunk/booking/war/src/main/webapp/WEB-INF/faces-config.xml 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/war/src/main/webapp/WEB-INF/faces-config.xml 2009-04-30 20:26:53 UTC (rev 10734)
@@ -8,6 +8,13 @@
<from-view-id>*</from-view-id>
<navigation-case>
+ <from-action>#{identity.logout}</from-action>
+ <if>#{true}</if>
+ <to-view-id>/home.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
+
+ <navigation-case>
<from-action>#{bookingAgent.cancel}</from-action>
<if>#{true}</if>
<to-view-id>/main.xhtml</to-view-id>
@@ -17,6 +24,18 @@
</navigation-rule>
<navigation-rule>
+ <from-view-id>/home.xhtml</from-view-id>
+
+ <navigation-case>
+ <from-action>#{identity.login}</from-action>
+ <if>#{identity.loggedIn}</if>
+ <to-view-id>/main.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
+
+ </navigation-rule>
+
+ <navigation-rule>
<from-view-id>/main.xhtml</from-view-id>
<!-- navigation rules are required to reset request-scoped producer variables -->
@@ -87,9 +106,21 @@
<from-action>#{registrar.register}</from-action>
<if>#{registrar.registered}</if>
<to-view-id>/account.xhtml</to-view-id>
- <!--<redirect/> disabled until messages can be kept over redirect -->
+ <redirect/>
</navigation-case>
</navigation-rule>
+ <navigation-rule>
+ <from-view-id>/password.xhtml</from-view-id>
+
+ <navigation-case>
+ <from-action>#{passwordManager.changePassword}</from-action>
+ <if>#{passwordManager.changed}</if>
+ <to-view-id>/account.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
+
+ </navigation-rule>
+
</faces-config>
Modified: examples/trunk/booking/war/src/main/webapp/WEB-INF/layout/template.xhtml
===================================================================
--- examples/trunk/booking/war/src/main/webapp/WEB-INF/layout/template.xhtml 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/war/src/main/webapp/WEB-INF/layout/template.xhtml 2009-04-30 20:26:53 UTC (rev 10734)
@@ -18,17 +18,21 @@
<div id="document">
<div id="header">
<div id="title"><h:graphicImage value="/img/hdr.title.gif" alt="JBoss Suites: seam framework demo"/></div>
- <div id="status">
- <h:link id="about" outcome="/home.xhtml" value="About"/>
- #{' | '}
- <h:link id="search" outcome="/main.xhtml" value="Search"/>
- <ui:remove><!--
- Welcome #{user.name} or use (#{user.name})
- | <h:link id="search" outcome="/main.xhtml" value="Search"/>
- | <h:link id="settings" outcome="/password.xhtml" value="Settings"/>
- | <s:link id="logout" action="#{identity.logout}" value="Logout"/>
- --></ui:remove>
- </div>
+ <h:form id="menuForm">
+ <div id="status">
+ <h:outputText value="(#{user.name})" rendered="#{identity.loggedIn}" styleClass="user"/>
+ #{' '}
+ <h:link id="about" outcome="/home.xhtml" value="About"/>
+ #{' | '}
+ <h:link id="search" outcome="/main.xhtml" value="Search"/>
+ <h:panelGroup rendered="#{identity.loggedIn}">
+ #{' | '}
+ <h:link id="settings" outcome="/password.xhtml" value="Settings"/>
+ #{' | '}
+ <h:commandLink id="logout" action="#{identity.logout}" value="Logout"/>
+ </h:panelGroup>
+ </div>
+ </h:form>
</div>
<div id="container">
<div id="sidebar">
Modified: examples/trunk/booking/war/src/main/webapp/css/screen.css
===================================================================
--- examples/trunk/booking/war/src/main/webapp/css/screen.css 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/war/src/main/webapp/css/screen.css 2009-04-30 20:26:53 UTC (rev 10734)
@@ -269,6 +269,11 @@
color: #C7B299;
text-decoration: none;
}
+#status span.user {
+ padding-right: 5px;
+ color: #FFFDFB;
+ font-weight: normal;
+}
/* Homepage Modifications
----------------------------------------------- */
body.home #container {
Modified: examples/trunk/booking/war/src/main/webapp/home.xhtml
===================================================================
--- examples/trunk/booking/war/src/main/webapp/home.xhtml 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/war/src/main/webapp/home.xhtml 2009-04-30 20:26:53 UTC (rev 10734)
@@ -39,23 +39,20 @@
</ui:define>
<ui:define name="sidebar">
- <h:form id="login">
+ <h:form id="login" rendered="#{not identity.loggedIn}">
<fieldset>
- <ui:remove>
<div>
- <h:outputLabel id="UsernameLabel" for="username">Login Name</h:outputLabel>
+ <h:outputLabel for="username" value="Login name"/>
<h:inputText id="username" value="#{identity.username}" style="width: 175px;"/>
- <div class="errors"><h:message id="UsernameMessage" for="username"/></div>
+ <div class="errors"><h:message for="username"/></div>
</div>
<div>
- <h:outputLabel id="PasswordLabel" for="password">Password</h:outputLabel>
+ <h:outputLabel for="password" value="Password"/>
<h:inputSecret id="password" value="#{identity.password}" style="width: 175px;"/>
</div>
<div class="errors"><h:messages id="messages" globalOnly="true"/></div>
<div class="buttonBox"><h:commandButton id="login" action="#{identity.login}" value="Account Login"/></div>
- </ui:remove>
<div class="notes"><h:link id="register" outcome="/register.xhtml" value="Register New User"/></div>
- <ui:remove>
<div class="subnotes">
Or use a demo account:
<ul>
@@ -65,7 +62,6 @@
<li>dan/maryland</li>
</ul>
</div>
- </ui:remove>
</fieldset>
</h:form>
</ui:define>
Modified: examples/trunk/booking/war/src/main/webapp/main.xhtml
===================================================================
--- examples/trunk/booking/war/src/main/webapp/main.xhtml 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/war/src/main/webapp/main.xhtml 2009-04-30 20:26:53 UTC (rev 10734)
@@ -40,7 +40,7 @@
</h:inputText>
#{' '}
<h:commandButton id="findHotels" value="Find Hotels" action="#{hotelSearch.find}">
- <f:ajax listener="#{hotelSearch.find}" execute="searchString" render="searchResults" onevent="controlSpinner"/>
+ <f:ajax execute="searchString" render="searchResults" onevent="controlSpinner"/>
</h:commandButton>
#{' '}
<span id="activity" style="display: none;"><h:graphicImage id="spinner" value="/img/spinner.gif"/></span>
@@ -48,6 +48,7 @@
<h:outputLabel id="lblPageSize" for="pageSize" value="Maximum results:"/>
#{' '}
<h:selectOneMenu id="pageSize" value="#{searchCriteria.pageSize}">
+ <f:ajax listener="#{hotelSearch.find}" render="searchResults" onevent="controlSpinner"/>
<f:selectItem itemLabel="5" itemValue="5"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="20" itemValue="20"/>
@@ -63,23 +64,23 @@
<h:dataTable id="hotels" value="#{hotels}" var="_hotel" rendered="#{not empty hotels}"
columnClasses=",,,,action">
<h:column id="nameCol">
- <f:facet id="nameFct" name="header">Name</f:facet>
+ <f:facet id="nameFct" name="header">Hotel name</f:facet>
#{_hotel.name}
</h:column>
- <h:column id="addressCol">
- <f:facet id="addressFct" name="header">Address</f:facet>
+ <h:column id="addrCol">
+ <f:facet id="addrFct" name="header">Address</f:facet>
#{_hotel.address}
</h:column>
- <h:column id="locationCol">
- <f:facet id="locationFct" name="header">Location</f:facet>
- #{_hotel.city}, #{_hotel.state}, #{_hotel.country}
+ <h:column id="locCol">
+ <f:facet id="locFct" name="header">Location</f:facet>
+ #{_hotel.location}
</h:column>
<h:column id="zipCol">
<f:facet id="zipFct" name="header">Zip</f:facet>
#{_hotel.zip}
</h:column>
- <h:column id="actionCol">
- <f:facet id="actionFct" name="header">Action</f:facet>
+ <h:column id="actCol">
+ <f:facet id="actFct" name="header">Action</f:facet>
<h:commandLink id="view" value="View" action="#{bookingAgent.selectHotel(_hotel)}" style="white-space: nowrap;"/>
<ui:remove>
<h:commandButton id="view" value="View" action="#{bookingAgent.selectHotel(_hotel)}"/>
@@ -88,64 +89,73 @@
</h:dataTable>
</h:form>
<h:form id="paginationForm">
- <h:commandButton id="previousResults" value="Previous page" action="#{hotelSearch.previousPage}" rendered="#{hotelSearch.previousPageAvailable}"/>
+ <h:commandButton id="previousResults" value="Previous page" action="#{hotelSearch.previousPage}" rendered="#{hotelSearch.previousPageAvailable}">
+ <f:ajax render="searchResults" onevent="controlSpinner"/>
+ </h:commandButton>
#{' '}
- <h:commandButton id="moreResults" value="More results" action="#{hotelSearch.nextPage}" rendered="#{hotelSearch.nextPageAvailable}"/>
+ <h:commandButton id="moreResults" value="More results" action="#{hotelSearch.nextPage}" rendered="#{hotelSearch.nextPageAvailable}">
+ <f:ajax render="searchResults" onevent="controlSpinner"/>
+ </h:commandButton>
<ui:remove>
- <!-- links in Mojarra are broken -->
- <h:commandLink id="previousResults" value="More results" action="#{hotelSearch.previousPage}" rendered="#{hotelSearch.previousPageAvailable}">
- <f:ajax listener="#{hotelSearch.previousPage}" render="searchResults"/>
+ <h:commandLink id="previousResults" value="Previous page" action="#{hotelSearch.previousPage}" rendered="#{hotelSearch.previousPageAvailable}">
+ <f:ajax render="searchResults" onevent="controlSpinner"/>
</h:commandLink>
+ #{' '}
<h:commandLink id="moreResults" value="More results" action="#{hotelSearch.nextPage}" rendered="#{hotelSearch.nextPageAvailable}">
- <f:ajax listener="#{hotelSearch.nextPage}" render="searchResults"/>
+ <f:ajax render="searchResults" onevent="controlSpinner"/>
</h:commandLink>
</ui:remove>
</h:form>
</div>
- </h:panelGroup>
+ </h:panelGroup>
-<ui:remove>
-<!--
-<div class="section">
- <h1>Current Hotel Bookings</h1>
-</div>
-<div class="section">
- <h:form id="bookings">
- <h:outputText id="NoBookingsFoundMessage" value="No Bookings Found" rendered="#{bookings.rowCount==0}"/>
- <h:dataTable id="bookings" value="#{bookings}" var="book" rendered="#{bookings.rowCount>0}">
- <h:column id="column1">
- <f:facet id="NameFacet" name="header">Name</f:facet>
- #{book.hotel.name}
- </h:column>
- <h:column id="column2">
- <f:facet id="AddressFacet" name="header">Address</f:facet>
- #{book.hotel.address}
- </h:column>
- <h:column id="column3">
- <f:facet id="CityStateFacet" name="header">City, State</f:facet>
- #{book.hotel.city}, #{book.hotel.state}
- </h:column>
- <h:column id="column4">
- <f:facet id="CheckInDateFacet" name="header">Check in date</f:facet>
- <h:outputText id="BookingCheckInDate" value="#{book.checkinDate}"/>
- </h:column>
- <h:column id="column5">
- <f:facet id="CheckOutDateFacet" name="header">Check out date</f:facet>
- <h:outputText id="BookingCheckOutDate" value="#{book.checkoutDate}"/>
- </h:column>
- <h:column id="column6">
- <f:facet id="ConfNumberFacet" name="header">Confirmation number</f:facet>
- #{book.id}
- </h:column>
- <h:column id="column7">
- <f:facet id="ActionFacet" name="header">Action</f:facet>
- <h:commandLink id="cancel" value="Cancel" action="#{bookingList.cancel}"/>
- </h:column>
- </h:dataTable>
- </h:form>
-</div>
--->
-</ui:remove>
+ <div class="section">
+ <h1>Current Hotel Bookings</h1>
+ </div>
+ <div class="section">
+ <h:panelGroup rendered="#{not identity.loggedIn}">
+ You must be logged in to see the list of your hotel bookings.
+ </h:panelGroup>
+ <h:form id="bookings" rendered="#{identity.loggedIn}">
+ <h:outputText value="No bookings found." rendered="#{bookings.size == 0}"/>
+ <h:dataTable id="bookings" value="#{bookings}" var="_booking" rendered="#{bookings.size gt 0}">
+ <ui:remove>
+ <h:column id="nameCol">
+ <f:facet id="nameFct" name="header">Hotel name</f:facet>
+ #{_booking.hotel}
+ </h:column>
+ <h:column id="addrCol">
+ <f:facet id="addrCol" name="header">Address</f:facet>
+ #{_booking.hotel.address}
+ </h:column>
+ <h:column id="locCol">
+ <f:facet id="locFct" name="header">Location</f:facet>
+ #{_booking.hotel.location}
+ </h:column>
+ </ui:remove>
+ <h:column id="inCol">
+ <f:facet id="inCol" name="header">Check-in date</f:facet>
+ <h:outputText value="#{_booking.checkinDate}">
+ <f:convertDateTime type="date" pattern="MM/dd/yyyy"/>
+ </h:outputText>
+ </h:column>
+ <h:column id="outCol">
+ <f:facet id="outFct" name="header">Check-out date</f:facet>
+ <h:outputText value="#{_booking.checkoutDate}">
+ <f:convertDateTime type="date" pattern="MM/dd/yyyy"/>
+ </h:outputText>
+ </h:column>
+ <h:column id="idCol">
+ <f:facet id="idFct" name="header">Confirmation number</f:facet>
+ #{_booking.id}
+ </h:column>
+ <h:column id="actCol">
+ <f:facet id="ActFct" name="header">Action</f:facet>
+ <h:commandLink id="cancel" value="Cancel" action="#{bookingHistory.cancelBooking(_booking)}"/>
+ </h:column>
+ </h:dataTable>
+ </h:form>
+ </div>
</ui:define>
Modified: examples/trunk/booking/war/src/main/webapp/password.xhtml
===================================================================
--- examples/trunk/booking/war/src/main/webapp/password.xhtml 2009-04-30 18:42:29 UTC (rev 10733)
+++ examples/trunk/booking/war/src/main/webapp/password.xhtml 2009-04-30 20:26:53 UTC (rev 10734)
@@ -24,11 +24,11 @@
<fieldset>
<p:edit id="password" label="Password">
- <h:inputSecret id="password" value="#{user.password}" redisplay="true"/>
+ <h:inputSecret id="input" value="#{user.password}" redisplay="true"/>
</p:edit>
<p:edit id="confirmPassword" label="Confirm password">
- <h:inputSecret id="password" value="#{passwordManager.confirmPassword}" redisplay="true"
+ <h:inputSecret id="input" value="#{passwordManager.confirmPassword}" redisplay="true"
binding="#{registrationFormControls.confirmPassword}"/>
</p:edit>
More information about the seam-commits
mailing list