[seam-commits] Seam SVN: r13168 - in examples/trunk/booking-simplified: src/main/java/org/jboss/seam/examples/booking/booking and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 15 17:55:12 EDT 2010


Author: lincolnthree
Date: 2010-06-15 17:55:11 -0400 (Tue, 15 Jun 2010)
New Revision: 13168

Added:
   examples/trunk/booking-simplified/src/main/webapp/WEB-INF/pretty-config.xml
Modified:
   examples/trunk/booking-simplified/pom.xml
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java
   examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml
   examples/trunk/booking-simplified/src/main/webapp/search.xhtml
Log:
Changed hotel view to use s:viewAction
Added prettyfaces

Modified: examples/trunk/booking-simplified/pom.xml
===================================================================
--- examples/trunk/booking-simplified/pom.xml	2010-06-15 21:29:48 UTC (rev 13167)
+++ examples/trunk/booking-simplified/pom.xml	2010-06-15 21:55:11 UTC (rev 13168)
@@ -38,7 +38,7 @@
       <jboss-as-client.version>6.0.0.20100216-M2</jboss-as-client.version>
       <jboss-javaee6-spec.version>1.0.0.Beta4</jboss-javaee6-spec.version>
       <jboss-server-manager.version>1.0.3.GA</jboss-server-manager.version>
-      <seam-faces.version>3.0.0.Alpha3</seam-faces.version>
+      <seam-faces.version>3.0.0-SNAPSHOT</seam-faces.version>
    </properties>
 
    <repositories>
@@ -92,6 +92,12 @@
       </dependency>
 
       <dependency>
+         <groupId>com.ocpsoft</groupId>
+         <artifactId>prettyfaces-jsf2</artifactId>
+         <version>3.0.1</version>
+      </dependency>
+
+      <dependency>
          <groupId>org.jboss.seam.xml</groupId>
          <artifactId>seam-xml-config</artifactId>
          <exclusions>

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java	2010-06-15 21:29:48 UTC (rev 13167)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java	2010-06-15 21:55:11 UTC (rev 13168)
@@ -24,6 +24,7 @@
 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;
 
@@ -33,7 +34,7 @@
 @Local
 public interface BookingAgent
 {
-   void selectHotel(Hotel hotel);
+   void selectHotel(Long hotelId);
 
    void bookHotel();
 

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java	2010-06-15 21:29:48 UTC (rev 13167)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java	2010-06-15 21:55:11 UTC (rev 13168)
@@ -60,8 +60,8 @@
    @PersistenceContext(type = EXTENDED)
    private EntityManager em;
 
-//   @Inject
-//   private Conversation conversation;
+   // @Inject
+   // private Conversation conversation;
 
    @Inject
    private MessageFactory mf;
@@ -87,13 +87,16 @@
    private boolean bookingValid;
 
    @Begin
-   public void selectHotel(final Hotel hotel)
+   public void selectHotel(final Long id)
    {
       // NOTE get a fresh reference that's managed by the conversational
       // persistence context
-      hotelSelection = em.find(Hotel.class, hotel.getId());
-      log.info(mf.info("Selected the {0} in {1}").textParams(hotelSelection.getName(), hotelSelection.getCity()).build().getText());
-      //conversation.begin();
+      if (id != null)
+      {
+         hotelSelection = em.find(Hotel.class, id);
+         log.info(mf.info("Selected the {0} in {1}").textParams(hotelSelection.getName(), hotelSelection.getCity()).build().getText());
+      }
+      // conversation.begin();
    }
 
    public void bookHotel()
@@ -136,7 +139,7 @@
       manager.fireEvent(new BookingEvent(booking), ConfirmedLiteral.INSTANCE);
       log.info(mf.info("New booking at the {0} confirmed for {1}").textParams(booking.getHotel().getName(), booking.getUser().getName()).build().getText());
       messages.info(new BundleKey("messages.properties", "booking.confirmed")).textDefault("Booking confirmed.");
-      //conversation.end();
+      // conversation.end();
    }
 
    @End
@@ -144,7 +147,7 @@
    {
       booking = null;
       hotelSelection = null;
-      //conversation.end();
+      // conversation.end();
    }
 
    @Produces
@@ -160,7 +163,12 @@
    @RequestScoped
    public Hotel getHotelSelection()
    {
-      return booking != null ? booking.getHotel() : hotelSelection;
+      Hotel hotel = booking != null ? booking.getHotel() : hotelSelection;
+      if (hotel == null)
+      {
+         hotel = new Hotel();
+      }
+      return hotel;
    }
 
    public boolean isBookingValid()

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java	2010-06-15 21:29:48 UTC (rev 13167)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java	2010-06-15 21:55:11 UTC (rev 13168)
@@ -27,10 +27,11 @@
 import java.util.List;
 
 import javax.ejb.Stateful;
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.enterprise.inject.Produces;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.criteria.CriteriaBuilder;
@@ -41,21 +42,23 @@
 import org.jboss.seam.examples.booking.model.Hotel_;
 import org.jboss.seam.international.status.MessageFactory;
 import org.slf4j.Logger;
-//import org.jboss.seam.international.status.MessageFactory;
-//import org.slf4j.Logger;
 
 @Named("hotelSearch")
 @Stateful
 @SessionScoped
 public class HotelSearchBean implements HotelSearch
 {
-   @Inject private Logger log;
+   @Inject
+   private Logger log;
 
-   @PersistenceContext private EntityManager em;
+   @PersistenceContext
+   private EntityManager em;
 
-   @Inject private SearchCriteria criteria;
+   @Inject
+   private SearchCriteria criteria;
 
-   @Inject private MessageFactory mf;
+   @Inject
+   private MessageFactory mf;
 
    private boolean nextPageAvailable = false;
 
@@ -79,10 +82,11 @@
       queryHotels(criteria);
    }
 
-   public
-   @Produces
+   public @Produces
    @Named
-   //@RequestScoped // if enabled, variable doesn't get updated after the action is executed w/o a redirect
+   @Dependent
+   // @RequestScoped // if enabled, variable doesn't get updated after the
+   // action is executed w/o a redirect
    List<Hotel> getHotels()
    {
       return hotels;
@@ -98,24 +102,15 @@
       return criteria.getPage() > 0;
    }
 
-   private void queryHotels(SearchCriteria criteria)
+   private void queryHotels(final SearchCriteria criteria)
    {
       CriteriaBuilder builder = em.getCriteriaBuilder();
       CriteriaQuery<Hotel> cquery = builder.createQuery(Hotel.class);
       Root<Hotel> hotel = cquery.from(Hotel.class);
       // QUESTION can like create the pattern for us?
-      cquery.select(hotel)
-            .where(builder.or(
-               builder.like(builder.lower(hotel.get(Hotel_.name)), criteria.getSearchPattern()),
-               builder.like(builder.lower(hotel.get(Hotel_.city)), criteria.getSearchPattern()),
-               builder.like(builder.lower(hotel.get(Hotel_.zip)), criteria.getSearchPattern()),
-               builder.like(builder.lower(hotel.get(Hotel_.address)), criteria.getSearchPattern())
-               ));
+      cquery.select(hotel).where(builder.or(builder.like(builder.lower(hotel.get(Hotel_.name)), criteria.getSearchPattern()), builder.like(builder.lower(hotel.get(Hotel_.city)), criteria.getSearchPattern()), builder.like(builder.lower(hotel.get(Hotel_.zip)), criteria.getSearchPattern()), builder.like(builder.lower(hotel.get(Hotel_.address)), criteria.getSearchPattern())));
 
-      List<Hotel> results = em.createQuery(cquery)
-            .setMaxResults(criteria.getFetchSize())
-            .setFirstResult(criteria.getFetchOffset())
-            .getResultList();
+      List<Hotel> results = em.createQuery(cquery).setMaxResults(criteria.getFetchSize()).setFirstResult(criteria.getFetchOffset()).getResultList();
 
       nextPageAvailable = results.size() > criteria.getPageSize();
       if (nextPageAvailable)
@@ -127,7 +122,6 @@
       {
          hotels = results;
       }
-      log.info(mf.info("Found {0} hotel(s) matching search term ''{1}'' (limit {2})")
-            .textParams(hotels.size(), criteria.getQuery(), criteria.getPageSize()).build().getText());
+      log.info(mf.info("Found {0} hotel(s) matching search term ''{1}'' (limit {2})").textParams(hotels.size(), criteria.getQuery(), criteria.getPageSize()).build().getText());
    }
 }

Added: examples/trunk/booking-simplified/src/main/webapp/WEB-INF/pretty-config.xml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/WEB-INF/pretty-config.xml	                        (rev 0)
+++ examples/trunk/booking-simplified/src/main/webapp/WEB-INF/pretty-config.xml	2010-06-15 21:55:11 UTC (rev 13168)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<pretty-config xmlns="http://ocpsoft.com/prettyfaces/2.0.4" 
+               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+               xsi:schemaLocation="http://ocpsoft.com/prettyfaces/2.0.4
+                                   		http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd">
+
+	<url-mapping>
+		<pattern value="/"></pattern>
+		<view-id>/home.seam</view-id>
+	</url-mapping>
+
+</pretty-config>
\ No newline at end of file

Modified: examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml	2010-06-15 21:29:48 UTC (rev 13167)
+++ examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml	2010-06-15 21:55:11 UTC (rev 13168)
@@ -4,8 +4,14 @@
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
+   xmlns:s="http://jboss.org/seam/faces"
    template="/WEB-INF/layout/template.xhtml">
 
+	<f:metadata>
+		<f:viewParam name="id" value="#{_hotel}" />
+		<s:viewAction action="#{bookingAgent.selectHotel(_hotel)}" />
+	</f:metadata>
+
    <ui:define name="content">
 
       <div class="section">

Modified: examples/trunk/booking-simplified/src/main/webapp/search.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/search.xhtml	2010-06-15 21:29:48 UTC (rev 13167)
+++ examples/trunk/booking-simplified/src/main/webapp/search.xhtml	2010-06-15 21:55:11 UTC (rev 13168)
@@ -77,7 +77,10 @@
                   </h:column>
                   <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;"/>
+                     <h:link id="view" value="View" outcome="hotel" style="white-space: nowrap;">
+                     	<f:param name="id" value="#{_hotel.id}" />
+                     </h:link>
+                     
                      <ui:remove><!--
                      <h:commandButton id="view" value="View" action="#{bookingAgent.selectHotel(_hotel)}"/>
                      --></ui:remove>



More information about the seam-commits mailing list