You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2005/07/27 14:15:35 UTC
svn commit: r225496 - in /myfaces: examples/trunk/sandbox/
examples/trunk/sandbox/WEB-INF/
examples/trunk/sandbox/src/java/org/apache/myfaces/examples/schedule/
sandbox/trunk/src/java/org/apache/myfaces/custom/schedule/model/
Author: mbr
Date: Wed Jul 27 05:15:23 2005
New Revision: 225496
URL: http://svn.apache.org/viewcvs?rev=225496&view=rev
Log:
supplied patch for x:schedule. Thanks to Jurgen Lust
Modified:
myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml
myfaces/examples/trunk/sandbox/schedule.jsp
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/schedule/SimpleScheduleBackingBean.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/schedule/model/SimpleScheduleModel.java
Modified: myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml?rev=225496&r1=225495&r2=225496&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml (original)
+++ myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml Wed Jul 27 05:15:23 2005
@@ -254,5 +254,15 @@
<managed-bean-class>org.apache.myfaces.examples.schedule.SimpleScheduleBackingBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+
+ <managed-bean>
+ <managed-bean-name>simpleAppointment</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.examples.schedule.SimpleAppointmentBackingBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>scheduleBean</property-name>
+ <value>#{simpleSchedule}</value>
+ </managed-property>
+ </managed-bean>
</faces-config>
Modified: myfaces/examples/trunk/sandbox/schedule.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/schedule.jsp?rev=225496&r1=225495&r2=225496&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/schedule.jsp (original)
+++ myfaces/examples/trunk/sandbox/schedule.jsp Wed Jul 27 05:15:23 2005
@@ -1,6 +1,7 @@
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
-<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="x"%>
+<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
+<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
<!--
/*
@@ -21,33 +22,151 @@
//-->
<html>
- <%@include file="inc/head.inc" %>
+ <%@include file="inc/head.inc" %>
- <body>
- <f:view>
- <h:form>
- <br/>
- <h:panelGroup>
- <h:outputLabel for="modeInput">
- <h:outputText value="mode: " />
- </h:outputLabel>
- <h:selectOneRadio id="modeInput" layout="lineDirection"
- binding="#{simpleSchedule.modeInput}" immediate="true"
- valueChangeListener="#{simpleSchedule.modeChanged}"
- onchange="this.form.submit();" value="#{simpleSchedule.mode}">
- <f:selectItems id="modeItems" value="#{simpleSchedule.modeItems}" />
- </h:selectOneRadio>
-
- </h:panelGroup>
-
- <x:schedule value="#{simpleSchedule.model}" id="schedule1"
- rendered="true" visibleEndHour="18" visibleStartHour="8"
- workingEndHour="17" workingStartHour="9" readonly="false"
- actionListener="#{simpleSchedule.actionPerformed}" tooltip="true"/>
- </h:form>
- </f:view>
- </body>
+ <body>
+ <f:view>
+ <h:form>
+ <h:messages
+ tooltip="true"
+ id="scheduleMessages"
+ layout="table"
+ globalOnly="false"/>
+
+ <table cellpadding="5" border="0">
+ <tr>
+ <td valign="top">
+ <h:panelGrid cellpadding="0" cellspacing="15" columns="1">
+ <x:inputCalendar
+ id="scheduleNavigator"
+ monthYearRowClass="yearMonthHeader"
+ weekRowClass="weekHeader"
+ currentDayCellClass="currentDayCell"
+ value="#{simpleSchedule.date}"
+ valueChangeListener="#{simpleSchedule.calendarValueChanged}"
+ binding="#{simpleSchedule.dateInput}"/>
+ <h:outputLabel
+ for="modeInput"
+ id="modeLabel"
+ value="mode:"/>
+ <h:selectOneMenu
+ id="modeInput"
+ binding="#{simpleSchedule.modeInput}"
+ immediate="true"
+ valueChangeListener="#{simpleSchedule.modeValueChanged}"
+ onchange="this.form.submit();"
+ value="#{simpleSchedule.mode}">
+ <f:selectItems
+ id="modeItems"
+ value="#{simpleSchedule.modeItems}"/>
+ </h:selectOneMenu>
+ </h:panelGrid>
+ </td>
+ <td width="100%">
+ <s:schedule
+ value="#{simpleSchedule.model}"
+ id="schedule1"
+ rendered="true"
+ visibleEndHour="18"
+ visibleStartHour="8"
+ workingEndHour="17"
+ workingStartHour="9"
+ readonly="false"
+ actionListener="#{simpleSchedule.scheduleActionPerformed}"
+ tooltip="true"/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ <h3><h:outputText value="add appointment"/></h3>
+ </td>
+ <td>
+ <h:panelGrid cellpadding="0" cellspacing="0" columns="2">
+ <h:outputLabel
+ for="appStart"
+ value="start:"/>
+ <x:inputDate
+ id="appStart"
+ value="#{simpleAppointment.appointmentStart}"
+ type="both"/>
+ <h:outputLabel
+ for="appEnd"
+ value="end:"/>
+ <x:inputDate
+ id="appEnd"
+ value="#{simpleAppointment.appointmentEnd}"
+ type="both"/>
+ <h:outputLabel
+ for="appTitle"
+ value="title:"/>
+ <h:inputText
+ size="60"
+ id="appTitle"
+ value="#{simpleAppointment.appointmentTitle}"/>
+ <h:outputLabel
+ for="appLocation"
+ value="location:"/>
+ <h:inputText
+ size="60"
+ id="appLocation"
+ value="#{simpleAppointment.appointmentLocation}"/>
+ <h:outputLabel
+ for="appComments"
+ value="comments:"/>
+ <h:inputTextarea
+ cols="60"
+ rows="5"
+ id="appComments"
+ value="#{simpleAppointment.appointmentComments}"/>
+ <h:commandButton
+ value="Add appointment"
+ actionListener="#{simpleAppointment.addAppointment}"/>
+ </h:panelGrid>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ <h3><h:outputText value="remove appointment"/></h3>
+ </td>
+ <td>
+ <h:commandButton
+ value="Remove selected appointment"
+ actionListener="#{simpleAppointment.removeAppointment}"
+ disabled="#{!simpleSchedule.entrySelected}"/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ <h3><h:outputText value="add holiday"/></h3>
+ </td>
+ <td>
+ <h:panelGrid cellpadding="0" cellspacing="0" columns="2">
+ <h:outputLabel
+ for="holidayDate"
+ value="date:"/>
+ <x:inputDate
+ id="holidayDate"
+ value="#{simpleAppointment.holidayDate}"
+ type="date"/>
+ <h:outputLabel
+ for="holidayName"
+ value="name:"/>
+ <h:inputText
+ size="60"
+ id="holidayName"
+ value="#{simpleAppointment.holidayName}"/>
+ <h:commandButton
+ value="Add holiday"
+ actionListener="#{simpleAppointment.addHoliday}"/>
+ </h:panelGrid>
+ </td>
+ </tr>
+ </table>
- <%@include file="inc/page_footer.jsp" %>
+ </h:form>
+ </f:view>
+ </body>
+
+ <%@include file="inc/page_footer.jsp" %>
</html>
Modified: myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/schedule/SimpleScheduleBackingBean.java
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/schedule/SimpleScheduleBackingBean.java?rev=225496&r1=225495&r2=225496&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/schedule/SimpleScheduleBackingBean.java (original)
+++ myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/schedule/SimpleScheduleBackingBean.java Wed Jul 27 05:15:23 2005
@@ -1,254 +1,246 @@
package org.apache.myfaces.examples.schedule;
-import org.apache.myfaces.custom.calendar.HtmlInputCalendar;
-import org.apache.myfaces.custom.schedule.model.DefaultScheduleEntry;
-import org.apache.myfaces.custom.schedule.model.ScheduleModel;
-import org.apache.myfaces.custom.schedule.model.SimpleScheduleModel;
-
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
-import javax.faces.component.html.HtmlSelectOneRadio;
+import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
+import org.apache.myfaces.custom.calendar.HtmlInputCalendar;
+import org.apache.myfaces.custom.schedule.model.ScheduleModel;
+import org.apache.myfaces.custom.schedule.model.SimpleScheduleModel;
+import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
+
/**
-* This is an extremely simple demo of the Schedule component. The entries are
-* actually hardcoded. A real application would typically use a custom implementation
-* of the SimpleScheduleModel.
-*/
-public class SimpleScheduleBackingBean {
-
- //~ Instance fields --------------------------------------------------------
-
- private Date date = new Date();
- private HtmlInputCalendar dateInput;
- private HtmlSelectOneRadio modeInput;
- private Integer mode = new Integer(ScheduleModel.WORKWEEK);
- private SimpleScheduleModel model;
-
- //~ Constructors -----------------------------------------------------------
-
- /**
- * Creates a new SimpleScheduleBackingBean object.
- */
- public SimpleScheduleBackingBean() {
- super();
- initModel();
- }
-
- //~ Methods ----------------------------------------------------------------
-
- /**
- * @param date The date to set.
- */
- public void setDate(Date date) {
- this.date = date;
- }
-
- /**
- * @return Returns the date.
- */
- public Date getDate() {
- return date;
- }
-
- /**
- * @param dateInput The dateInput to set.
- */
- public void setDateInput(HtmlInputCalendar dateInput) {
- this.dateInput = dateInput;
- }
-
- /**
- * @return Returns the dateInput.
- */
- public HtmlInputCalendar getDateInput() {
- return dateInput;
- }
-
- /**
- * @param mode The mode to set.
- */
- public void setMode(Integer mode) {
- this.mode = mode;
- }
-
- /**
- * @return Returns the mode.
- */
- public Integer getMode() {
- return mode;
- }
-
- /**
- * @param modeInput The modeInput to set.
- */
- public void setModeInput(HtmlSelectOneRadio modeInput) {
- this.modeInput = modeInput;
- }
-
- /**
- * @return Returns the modeInput.
- */
- public HtmlSelectOneRadio getModeInput() {
- return modeInput;
- }
-
- /**
- * <p>
- * get the SelectItems for the mode SelectOneRadio
- * </p>
- *
- * @return an ArrayList of SelectItems
- */
- public ArrayList getModeItems() {
- ArrayList items = new ArrayList();
- items.add(new SelectItem(new Integer(ScheduleModel.DAY), "day"));
- items.add(
- new SelectItem(new Integer(ScheduleModel.WORKWEEK), "workweek")
- );
- items.add(new SelectItem(new Integer(ScheduleModel.WEEK), "week"));
- items.add(new SelectItem(new Integer(ScheduleModel.MONTH), "month"));
-
- return items;
- }
-
- /**
- * @param model The model to set.
- */
- public void setModel(SimpleScheduleModel model) {
- this.model = model;
- }
-
- /**
- * @return Returns the model.
- */
- public ScheduleModel getModel() {
- return model;
- }
-
- /**
- * <p>
- * a String describing the selected entry on the schedule
- * </p>
- *
- * @return the entry as a string
- */
- public String getSelectedEntry() {
- if ((model == null) || (model.getSelectedEntry() == null)) {
- return "no entry selected";
- }
-
- StringBuffer entry = new StringBuffer();
- entry.append(model.getSelectedEntry().getTitle());
- entry.append(": ");
- entry.append(model.getSelectedEntry().getStartTime());
- entry.append(" - ");
- entry.append(model.getSelectedEntry().getEndTime());
-
- String returnString = entry.toString();
-
- return returnString;
- }
-
- /**
- * <p>
- * action listener for the schedule component.
- * </p>
- *
- * @param actionEvent the action event
- */
- public void actionPerformed(ActionEvent actionEvent) {
- }
-
- /**
- * <p>
- * When the date of the calendar component changes, navigate to that date
- * in the schedule component.
- * </p>
- *
- * @param event the change event
- */
- public void dateChanged(ValueChangeEvent event) {
- this.date = (Date) dateInput.getValue();
- model.setSelectedDate(date);
- model.refresh();
- }
-
- /**
- * <p>
- * When a different mode is selected, apply this mode to the schedule
- * component.
- * </p>
- *
- * @param event the change event
- */
- public void modeChanged(ValueChangeEvent event) {
- if (mode == null) {
- return;
- }
-
- this.mode = (Integer) modeInput.getValue();
- model.setMode(mode.intValue());
-
- model.refresh();
- }
-
- /**
- * Initialize the demo: We're just adding 3 appointments here, it would
- * be easy to do this from a form on the page.
- */
- private void initModel() {
- if (model == null) {
- model = new SimpleScheduleModel();
- }
-
- Date today = new Date();
-
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(new Date());
- cal.set(Calendar.HOUR_OF_DAY, 11);
- cal.set(Calendar.MINUTE, 30);
- cal.set(Calendar.SECOND, 00);
- cal.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
-
- DefaultScheduleEntry entry1 = new DefaultScheduleEntry();
- entry1.setStartTime(cal.getTime());
- cal.add(Calendar.HOUR_OF_DAY, 2);
- entry1.setEndTime(cal.getTime());
- entry1.setId("1");
- entry1.setTitle("Meeting with portal developers");
- entry1.setSubtitle("Meeting room 1");
-
- DefaultScheduleEntry entry2 = new DefaultScheduleEntry();
- cal.add(Calendar.HOUR_OF_DAY, -1);
- entry2.setStartTime(cal.getTime());
- cal.add(Calendar.HOUR, 4);
- entry2.setEndTime(cal.getTime());
- entry2.setId("2");
- entry2.setTitle("work on MyFaces components");
- entry2.setSubtitle("");
- entry2.setDescription("I should create a more elaborate demo");
-
- DefaultScheduleEntry entry3 = new DefaultScheduleEntry();
- cal.add(Calendar.HOUR_OF_DAY, -48);
- entry3.setStartTime(cal.getTime());
- cal.add(Calendar.HOUR_OF_DAY, 48);
- entry3.setEndTime(cal.getTime());
- entry3.setId("3");
- entry3.setTitle("Business trip");
- entry3.setSubtitle("Paris");
- entry3.setDescription("Better brush up on my French before I leave...");
- model.addEntry(entry1);
- model.addEntry(entry2);
- model.addEntry(entry3);
-
- model.setMode(mode.intValue());
+ * This is a simple demo of the Schedule component.
+ * The entries are stored in the session.
+ * A real application would typically use a custom implementation
+ * of the ScheduleModel.
+ */
+public class SimpleScheduleBackingBean
+{
+
+ //~ Instance fields --------------------------------------------------------
+
+ private Date date = new Date();
+ private HtmlInputCalendar dateInput;
+ private HtmlSelectOneMenu modeInput;
+ private Integer mode = new Integer(ScheduleModel.WORKWEEK);
+ private SimpleScheduleModel model;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Creates a new SimpleScheduleBackingBean object.
+ */
+ public SimpleScheduleBackingBean()
+ {
+ super();
+ initModel();
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @param date The date to set.
+ */
+ public void setDate(Date date)
+ {
+ this.date = date;
+ }
+
+ /**
+ * @return Returns the date.
+ */
+ public Date getDate()
+ {
+ return date;
+ }
+
+ /**
+ * @param dateInput The dateInput to set.
+ */
+ public void setDateInput(HtmlInputCalendar dateInput)
+ {
+ this.dateInput = dateInput;
+ }
+
+ /**
+ * @return Returns the dateInput.
+ */
+ public HtmlInputCalendar getDateInput()
+ {
+ return dateInput;
+ }
+
+ /**
+ * @param mode The mode to set.
+ */
+ public void setMode(Integer mode)
+ {
+ this.mode = mode;
+ }
+
+ /**
+ * @return Returns the mode.
+ */
+ public Integer getMode()
+ {
+ return mode;
+ }
+
+ /**
+ * @param modeInput The modeInput to set.
+ */
+ public void setModeInput(HtmlSelectOneMenu modeInput)
+ {
+ this.modeInput = modeInput;
+ }
+
+ /**
+ * @return Returns the modeInput.
+ */
+ public HtmlSelectOneMenu getModeInput()
+ {
+ return modeInput;
+ }
+
+ /**
+ * <p>
+ * get the SelectItems for the mode SelectOneRadio
+ * </p>
+ *
+ * @return an ArrayList of SelectItems
+ */
+ public ArrayList getModeItems()
+ {
+ ArrayList items = new ArrayList();
+ items.add(new SelectItem(new Integer(ScheduleModel.DAY), "day"));
+ items.add(new SelectItem(new Integer(ScheduleModel.WORKWEEK),
+ "workweek"));
+ items.add(new SelectItem(new Integer(ScheduleModel.WEEK), "week"));
+ items.add(new SelectItem(new Integer(ScheduleModel.MONTH), "month"));
+
+ return items;
+ }
+
+ /**
+ * @param model The model to set.
+ */
+ public void setModel(SimpleScheduleModel model)
+ {
+ this.model = model;
+ }
+
+ /**
+ * @return Returns the model.
+ */
+ public ScheduleModel getModel()
+ {
+ return model;
+ }
+
+ /**
+ * <p>
+ * a String describing the selected entry on the schedule
+ * </p>
+ *
+ * @return the entry as a string
+ */
+ public String getSelectedEntry()
+ {
+ if ((model == null) || (model.getSelectedEntry() == null))
+ {
+ return "no entry selected";
+ }
+
+ StringBuffer entry = new StringBuffer();
+ entry.append(model.getSelectedEntry().getTitle());
+ entry.append(": ");
+ entry.append(model.getSelectedEntry().getStartTime());
+ entry.append(" - ");
+ entry.append(model.getSelectedEntry().getEndTime());
+
+ String returnString = entry.toString();
+
+ return returnString;
+ }
+
+ /**
+ * Is there an entry currently selected?
+ *
+ * @return if an entry is currently selected
+ */
+ public boolean isEntrySelected()
+ {
+ return model != null && model.getSelectedEntry() != null;
+ }
+
+ /**
+ * <p>
+ * action listener for the schedule component.
+ * </p>
+ *
+ * @param actionEvent the action event
+ */
+ public void scheduleActionPerformed(ActionEvent actionEvent)
+ {
+ }
+
+ /**
+ * <p>
+ * When a date is selected in the calendar component, navigate to that date
+ * in the schedule component.
+ * </p>
+ *
+ * @param event the action event
+ */
+ public void calendarValueChanged(ValueChangeEvent event)
+ {
+ if (date != null
+ && ScheduleUtil.truncate(date).equals(
+ ScheduleUtil.truncate((Date) dateInput.getValue())))
+ return;
+ this.date = (Date) dateInput.getValue();
+ model.setSelectedDate(date);
+ model.refresh();
+ }
+
+ /**
+ * <p>
+ * When a different mode is selected, apply this mode to the schedule
+ * component.
+ * </p>
+ *
+ * @param event the action event
+ */
+ public void modeValueChanged(ValueChangeEvent event)
+ {
+ if (mode != null && mode.equals((Integer) modeInput.getValue()))
+ return;
+ this.mode = (Integer) modeInput.getValue();
+ model.setMode(mode.intValue());
+ model.refresh();
+ this.date = model.getSelectedDate();
+ dateInput.setValue(model.getSelectedDate());
+ }
+
+ /**
+ * Initialize the demo
+ */
+ private void initModel()
+ {
+ if (model == null)
+ {
+ model = new SimpleScheduleModel();
+ }
+
+ this.date = new Date();
+
+ model.setMode(mode.intValue());
- model.setSelectedDate(today);
- }
+ model.setSelectedDate(this.date);
+ }
}
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/schedule/model/SimpleScheduleModel.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/schedule/model/SimpleScheduleModel.java?rev=225496&r1=225495&r2=225496&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/schedule/model/SimpleScheduleModel.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/schedule/model/SimpleScheduleModel.java Wed Jul 27 05:15:23 2005
@@ -87,12 +87,22 @@
* </p>
*
* @param entry the entry to add
- *
- * @return true if successful
*/
public void addEntry(ScheduleEntry entry)
{
entries.add(entry);
+ }
+
+ /**
+ * <p>
+ * Remove an entry from the model
+ * </p>
+ *
+ * @param entry the entry to remove
+ */
+ public void removeEntry(ScheduleEntry entry)
+ {
+ entries.remove(entry);
}
/**