[jboss-cvs] JBossAS SVN: r100750 - in projects/snowdrop/examples/trunk/sportsclub: sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 9 08:38:06 EST 2010


Author: lvlcek at redhat.com
Date: 2010-02-09 08:38:06 -0500 (Tue, 09 Feb 2010)
New Revision: 100750

Modified:
   projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java
   projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationService.java
   projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationServiceImpl.java
   projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationSearch.java
   projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/spring-beans.xml
   projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/searchReservation.xhtml
Log:
Edit capability in Reservation search form, JBQA-3033

Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java	2010-02-09 13:31:44 UTC (rev 100749)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/entity/Reservation.java	2010-02-09 13:38:06 UTC (rev 100750)
@@ -2,7 +2,11 @@
 
 import java.util.Date;
 
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
 
 /**
  * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
@@ -21,10 +25,10 @@
    @Column(name = "toDT", nullable = false)
    private Date to;
 
-   @ManyToOne(fetch = FetchType.LAZY)
+   @ManyToOne
    private Equipment equipment;
 
-   @ManyToOne(fetch = FetchType.LAZY)
+   @ManyToOne
    private Account account;
 
 

Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationService.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationService.java	2010-02-09 13:31:44 UTC (rev 100749)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationService.java	2010-02-09 13:38:06 UTC (rev 100750)
@@ -16,4 +16,8 @@
    Long countReservationsForRange(Date fromDate, Date toDate, List<EquipmentType> types);
 
    void create(Reservation reservation);
+
+   public void delete(Reservation reservation);
+
+   public Reservation updateReservation(Reservation reservation);
 }

Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationServiceImpl.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationServiceImpl.java	2010-02-09 13:31:44 UTC (rev 100749)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationServiceImpl.java	2010-02-09 13:38:06 UTC (rev 100750)
@@ -54,6 +54,20 @@
       reservationRepository.save(reservation);
    }
 
+   @Transactional(readOnly = false)
+   public void delete(Reservation reservation)
+   {
+      Reservation r = reservationRepository.findById(reservation.getId());
+      reservationRepository.delete(r);
+   }
+
+   @Transactional(readOnly = false)
+   public Reservation updateReservation(Reservation reservation)
+   {
+      reservationRepository.save(reservation);
+      return null;
+   }
+
    public ReservationRepository getReservationRepository()
    {
       return reservationRepository;

Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationSearch.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationSearch.java	2010-02-09 13:31:44 UTC (rev 100749)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationSearch.java	2010-02-09 13:38:06 UTC (rev 100750)
@@ -1,17 +1,19 @@
 package org.jboss.snowdrop.samples.sportsclub.jsf.beans;
 
-import org.jboss.snowdrop.samples.sportsclub.service.ReservationService;
-import org.jboss.snowdrop.samples.sportsclub.service.EquipmentService;
-import org.jboss.snowdrop.samples.sportsclub.domain.entity.Reservation;
-import org.jboss.snowdrop.samples.sportsclub.domain.entity.EquipmentType;
+import org.ajax4jsf.model.DataVisitor;
 import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.DataVisitor;
 import org.ajax4jsf.model.Range;
 import org.ajax4jsf.model.SequenceRange;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Reservation;
+import org.jboss.snowdrop.samples.sportsclub.service.ReservationService;
+import org.richfaces.model.selection.Selection;
+import org.richfaces.model.selection.SimpleSelection;
 
 import javax.faces.context.FacesContext;
-import java.util.*;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:lvlcek at redhat.com">Lukas Vlcek</a>
@@ -31,6 +33,8 @@
    private Long rowCount;
 
    private ReservationTableState tableState;
+   private Selection selection;
+   private boolean editing;
 
    public   ReservationSearch() {
       super();
@@ -163,4 +167,54 @@
    {
       this.reservationSearchOptions = reservationSearchOptions;
    }
+   
+   public void setSelection(Selection selection)
+   {
+      this.selection = selection;
+   }
+
+   public Selection getSelection()
+   {
+      return selection;
+   }
+
+   private Long getSelectedKey()
+   {
+      if (selection == null || selection.size() == 0)
+         return null;
+      else
+         return ((Long) selection.getKeys().next());
+   }
+
+   public Reservation getCurrentReservation()
+   {
+      if (selection != null && selection.size() > 0)
+         return reservationsMap.get(getSelectedKey());
+      else
+         return null;
+   }
+
+   public String deleteReservation()
+   {
+      reservationService.delete(getCurrentReservation());
+      selection = new SimpleSelection();
+      rowCount = null;
+      return "closed";
+   }
+
+   public void saveCurrent()
+   {
+      System.out.println("save current " + getCurrentReservation());
+      reservationService.updateReservation(getCurrentReservation());
+   }
+
+   public void setEditing(boolean editing)
+   {
+      this.editing = editing;
+   }
+
+   public boolean isEditing()
+   {
+      return editing;
+   }
 }

Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/spring-beans.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/spring-beans.xml	2010-02-09 13:31:44 UTC (rev 100749)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/spring-beans.xml	2010-02-09 13:38:06 UTC (rev 100750)
@@ -14,12 +14,6 @@
     <import resource="classpath*:spring-converterHelpers.xml"/>
     
     <!-- Request scoped beans -->
-    <bean id="reservationSearch" class="org.jboss.snowdrop.samples.sportsclub.jsf.beans.ReservationSearch" scope="request">
-        <property name="reservationService" ref="reservationService"/>
-        <property name="tableState" ref="reservationSearchTableState"/>
-        <property name="reservationSearchOptions" ref="reservationSearchOptions"/>
-    </bean>
-
     <bean id="reservationCreate" class="org.jboss.snowdrop.samples.sportsclub.jsf.beans.ReservationCreate" scope="request" init-method="init">
         <property name="reservationService" ref="reservationService"/>
         <property name="accountService" ref="accountService"/>
@@ -27,6 +21,12 @@
 
 
     <!-- Session scoped beans -->
+    <bean id="reservationSearch" class="org.jboss.snowdrop.samples.sportsclub.jsf.beans.ReservationSearch" scope="session">
+        <property name="reservationService" ref="reservationService"/>
+        <property name="tableState" ref="reservationSearchTableState"/>
+        <property name="reservationSearchOptions" ref="reservationSearchOptions"/>
+    </bean>
+    
     <bean id="reservationSearchTableState" class="org.jboss.snowdrop.samples.sportsclub.jsf.beans.ReservationTableState" scope="session"/>
 
     <bean id="reservationSearchOptions" class="org.jboss.snowdrop.samples.sportsclub.jsf.beans.ReservationSearchOptions" scope="session" init-method="init">

Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/searchReservation.xhtml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/searchReservation.xhtml	2010-02-09 13:31:44 UTC (rev 100749)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/searchReservation.xhtml	2010-02-09 13:38:06 UTC (rev 100750)
@@ -37,7 +37,7 @@
                     </tr>
                 </table>
                 <br/>
-                <a4j:status id="commonstatus" startText="Retrieving data..." stopText=""/>
+                <!--<a4j:status id="commonstatus" startText="Retrieving data..." stopText=""/>-->
 
             </h:form>
         </rich:panel>
@@ -46,13 +46,14 @@
             <h:form>
                 <rich:panel header="Search results">
 
-                    <rich:extendedDataTable id="searchResultsTable" value="#{reservationSearch}"
-                                            var="reservation" selectionMode="single"
+                    <rich:extendedDataTable id="searchResultsTable" value="#{reservationSearch}" var="reservation"
+                                            selectionMode="single"
+                                            selection="#{reservationSearch.selection}"
                                             enableContextMenu="true"
                                             height="250px"
                                             rows="5"
                                             tableState="#{reservationSearch.tableState.tableState}">
-
+                        <a4j:support event="onselectionchange" reRender="reservationData"/>
                         <rich:column label="Reservation #">
                             <f:facet name="header">
                                 <h:outputText value="Reservation #"/>
@@ -96,12 +97,44 @@
                             <rich:datascroller id="scroller" for="searchResultsTable" maxPages="5"
                                                page="#{reservationSearch.currentPage}"/>
                         </f:facet>
-
                     </rich:extendedDataTable>
+                    <rich:componentControl attachTo="deleteRsrvBtn" event="onclick" operation="selectionchange"
+                                           for="searchResults"/>
                 </rich:panel>
             </h:form>
         </a4j:outputPanel>
 
+        <a4j:outputPanel id="reservationData">
+            <rich:panel rendered="#{reservationSearch.currentReservation != null}" >
+                <h:form>
+                    <h:panelGrid columns="2">
+
+                        <h:outputLabel value="Equipment"/>
+                        <h:outputText value="#{reservationSearch.currentReservation.equipment}" converter="#{equipmentConverter}"/>
+
+                        <h:outputLabel value="Account"/>
+                        <h:outputText value="#{reservationSearch.currentReservation.account}" converter="#{accountConverter}"/>
+
+                        <h:outputLabel value="From"/>
+                        <h:outputText value="#{reservationSearch.currentReservation.from}"/>
+
+                        <h:outputLabel value="To"/>
+                        <h:outputText value="#{reservationSearch.currentReservation.to}"/>
+
+                        <a4j:commandButton id="deleteRsrvBtn" value="Delete" action="#{reservationSearch.deleteReservation}" reRender="searchResults,reservationData" rendered="#{!reservationSearch.editing}"/>
+                        <a4j:commandButton id="editRsrvBtn" value="Edit" reRender="reservationData" rendered="#{!reservationSearch.editing}">
+                            <f:setPropertyActionListener value="#{true}" target="#{reservationSearch.editing}"/>
+                        </a4j:commandButton>
+
+                        <a4j:commandButton id="cancelRsrvBtn" value="Cancel" rendered="#{reservationSearch.editing}" reRender="reservationData">
+                            <f:setPropertyActionListener value="#{false}" target="#{reservationSearch.editing}"/>
+                        </a4j:commandButton>
+                        <a4j:commandButton id="saveRsrvBtn" value="Save" action="#{reservationSearch.saveCurrent}" reRender="reservationData" rendered="#{reservationSearch.editing}"/>
+
+                    </h:panelGrid>
+                </h:form>
+            </rich:panel>
+        </a4j:outputPanel>
     </ui:define>
 
 </ui:composition>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list