[jboss-cvs] JBossAS SVN: r97995 - in projects/snowdrop/examples/trunk/sportsclub: sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 18 12:16:55 EST 2009
Author: lvlcek at redhat.com
Date: 2009-12-18 12:16:54 -0500 (Fri, 18 Dec 2009)
New Revision: 97995
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/ReservationServiceImpl.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationCreate.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverter.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverterHelper.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverter.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverterHelper.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/faces-config.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/createReservation.xhtml
Log:
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 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationService.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -15,5 +15,5 @@
Integer countReservationsForRange(Date fromDate, Date toDate, List<EquipmentType> types);
- void create();
+ void create(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 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-spring/src/main/java/org/jboss/snowdrop/samples/sportsclub/service/ReservationServiceImpl.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -49,9 +49,9 @@
}
@Transactional(readOnly = false)
- public void create()
+ public void create(Reservation reservation)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ reservationRepository.save(reservation);
}
public ReservationRepository getReservationRepository()
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationCreate.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationCreate.java 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/ReservationCreate.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -7,6 +7,7 @@
import org.jboss.snowdrop.samples.sportsclub.domain.entity.Account;
import org.jboss.snowdrop.samples.sportsclub.domain.entity.Equipment;
+import javax.faces.model.SelectItem;
import java.util.Date;
import java.util.Calendar;
import java.util.Locale;
@@ -36,25 +37,44 @@
to = cal.getTime();
reservation = new Reservation();
- reservation.setAccount(new Account());
- reservation.setEquipment(new Equipment());
+ reservation.setAccount(null);
+ reservation.setEquipment(null);
reservation.setFrom(from);
reservation.setTo(to);
}
- public Collection<Equipment> getAllEquipments()
+ public SelectItem[] getAllEquipments()
{
- return equipmentService.getAllEquipments();
+ Collection<Equipment> equipments = equipmentService.getAllEquipments();
+ SelectItem[] items = new SelectItem[equipments.size()];
+ int i = 0;
+ for (Equipment e : equipments)
+ {
+ String label = e.getEquipmentType().name() + ", " + e.getDescription();
+ items[i++] = new SelectItem(e, label);
+ }
+ return items;
}
- public Collection<Account> getAllAccounts()
+ public SelectItem[] getAllAccounts()
{
- return accountService.getAllAccounts();
+ Collection<Account> accounts = accountService.getAllAccounts();
+ SelectItem[] items = new SelectItem[accounts.size()];
+ int i = 0;
+ for (Account a : accounts)
+ {
+ String label = a.getSubscriber().getName().getFirstName() + " " +
+ a.getSubscriber().getName().getLastName() + " (" +
+ a.getSubscriber().getAddress().getCity() + ", " +
+ a.getSubscriber().getAddress().getCountry() + ")";
+ items[i++] = new SelectItem(a, label);
+ }
+ return items;
}
public String create()
{
- reservationService.create();
+ reservationService.create(reservation);
return "success";
}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverter.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverter.java 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverter.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -1,6 +1,9 @@
package org.jboss.snowdrop.samples.sportsclub.jsf.beans.converter;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Account;
+
import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
import javax.faces.context.FacesContext;
import javax.faces.component.UIComponent;
@@ -14,15 +17,35 @@
public AccountConverter()
{
}
-
+
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ if (s == null || "".equals(s.trim())) return null;
+ Account a;
+ try
+ {
+ a = accountConverterHelper.getAsAccount(s);
+ } catch (RuntimeException e)
+ {
+ throw new ConverterException(e);
+ }
+ return a;
}
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ if (o == null) return null;
+ String s;
+ try
+ {
+ Account a = (Account) o;
+ s = accountConverterHelper.getAsString(a);
+ }
+ catch (RuntimeException e)
+ {
+ throw new ConverterException(e);
+ }
+ return s;
}
public AccountConverterHelper getAccountConverterHelper()
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverterHelper.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverterHelper.java 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/AccountConverterHelper.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -13,17 +13,12 @@
public String getAsString(Account a)
{
- String s = a.getId() + " " + a.getSubscriber().getName().getFirstName() + " " +
- a.getSubscriber().getName().getLastName() + " (" +
- a.getSubscriber().getAddress().getCity() + ", " +
- a.getSubscriber().getAddress().getCountry() + ")";
- return s;
+ return String.valueOf(a.getId());
}
public Account getAsAccount(String s)
{
- String[] items = s.split(" ",2);
- Account a = accountService.getAccountById(Long.decode(items[0]));
+ Account a = accountService.getAccountById(Long.decode(s));
return a;
}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverter.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverter.java 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverter.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -40,8 +40,7 @@
try {
Equipment e = (Equipment)o;
s = equipmentConverterHelper.getAsString(e);
- }
- catch (RuntimeException e)
+ } catch (RuntimeException e)
{
throw new ConverterException(e);
}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverterHelper.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverterHelper.java 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/java/org/jboss/snowdrop/samples/sportsclub/jsf/beans/converter/EquipmentConverterHelper.java 2009-12-18 17:16:54 UTC (rev 97995)
@@ -13,14 +13,12 @@
public String getAsString(Equipment e) throws RuntimeException
{
- String s = e.getId() + " " + e.getName();
- return s;
+ return String.valueOf(e.getId());
}
public Equipment getAsEquipment(String s) throws RuntimeException
{
- String[] items = s.split(" ",2);
- Equipment e = getEquipmentService().findEquipmentById(Long.valueOf(items[0]));
+ Equipment e = getEquipmentService().findEquipmentById(Long.valueOf(s));
return e;
}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/faces-config.xml 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/WEB-INF/faces-config.xml 2009-12-18 17:16:54 UTC (rev 97995)
@@ -20,5 +20,12 @@
<to-view-id>/searchReservation.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
+ <navigation-rule>
+ <from-view-id>/createReservation.xhtml</from-view-id>
+ <navigation-case>
+ <from-action>#{reservationCreate.create}</from-action>
+ <to-view-id>/createResult.xhtml</to-view-id>
+ </navigation-case>
+ </navigation-rule>
</faces-config>
\ No newline at end of file
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/createReservation.xhtml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/createReservation.xhtml 2009-12-18 17:14:12 UTC (rev 97994)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-reservations-web/src/main/webapp/createReservation.xhtml 2009-12-18 17:16:54 UTC (rev 97995)
@@ -11,16 +11,14 @@
<h:panelGrid columns="2" >
<h:outputLabel value="Equipment"/>
- <rich:inplaceInput defaultLabel="Click to enter" value="#{reservationCreate.reservation.equipment}">
- <f:converter converterId="#{equipmentConverter}"/>
+ <rich:inplaceSelect defaultLabel="Click to enter" value="#{reservationCreate.reservation.equipment}" converter="#{equipmentConverter}">
<f:selectItems value="#{reservationCreate.allEquipments}"/>
- </rich:inplaceInput>
+ </rich:inplaceSelect>
<h:outputLabel value="Account"/>
- <rich:inplaceInput defaultLabel="Click to enter" value="#{reservationCreate.reservation.account}">
- <f:converter converterId="#{accountConverter}"/>
+ <rich:inplaceSelect defaultLabel="Click to enter" value="#{reservationCreate.reservation.account}" converter="#{accountConverter}">
<f:selectItems value="#{reservationCreate.allAccounts}"/>
- </rich:inplaceInput>
+ </rich:inplaceSelect>
<h:outputLabel value="From"/>
<rich:calendar id="from" value="#{reservationCreate.reservation.from}"/>
More information about the jboss-cvs-commits
mailing list