Author: ppitonak(a)redhat.com
Date: 2010-12-20 11:41:24 -0500 (Mon, 20 Dec 2010)
New Revision: 20695
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java
Log:
* sample for calendar fixed
* added test for valueChangeListener
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java 2010-12-20
16:04:36 UTC (rev 20694)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java 2010-12-20
16:41:24 UTC (rev 20695)
@@ -22,11 +22,14 @@
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.TimeZone;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.event.ValueChangeEvent;
import org.richfaces.component.UICalendar;
import org.richfaces.tests.metamer.Attributes;
@@ -47,6 +50,7 @@
private static Logger logger;
private Attributes attributes;
private Date date = new Date();
+ private TimeZone timeZone = TimeZone.getTimeZone("UTC");
/**
* Initializes the managed bean.
@@ -75,6 +79,7 @@
attributes.remove("dataModel");
attributes.remove("validator");
attributes.remove("valueChangeListener");
+ attributes.remove("timeZone");
}
public Attributes getAttributes() {
@@ -92,4 +97,35 @@
public void setDate(Date date) {
this.date = date;
}
+
+ public TimeZone getTimeZone() {
+ return timeZone;
+ }
+
+ public void setTimeZone(TimeZone timeZone) {
+ this.timeZone = timeZone;
+ }
+
+ /**
+ * A value change listener that logs to the page old and new value.
+ *
+ * @param event
+ * an event representing the activation of a user interface component
+ */
+ public void valueChangeListener(ValueChangeEvent event) {
+ SimpleDateFormat sdf = new
SimpleDateFormat(attributes.get("datePattern").getValue().toString());
+ sdf.setTimeZone(timeZone);
+
+ String oldDate = "null";
+ String newDate = "null";
+
+ if (event.getOldValue() != null) {
+ oldDate = sdf.format((Date) event.getOldValue());
+ }
+ if (event.getNewValue() != null) {
+ newDate = sdf.format((Date) event.getNewValue());
+ }
+
+ RichBean.logToPage("* value changed: " + oldDate + " -> "
+ newDate);
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml 2010-12-20
16:04:36 UTC (rev 20694)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml 2010-12-20
16:41:24 UTC (rev 20695)
@@ -151,11 +151,11 @@
showWeeksBar="#{richCalendarBean.attributes['showWeeksBar'].value}"
style="#{richCalendarBean.attributes['style'].value}"
tabindex="#{richCalendarBean.attributes['tabindex'].value}"
-
timeZone="#{richCalendarBean.attributes['timeZone'].value}"
+ timeZone="#{richCalendarBean.timeZone}"
todayControlMode="#{richCalendarBean.attributes['todayControlMode'].value}"
validatorMessage="#{richCalendarBean.attributes['validatorMessage'].value}"
value="#{richCalendarBean.attributes['value'].value}"
-
valueChangeListener="#{richBean.valueChangeListener}"
+
valueChangeListener="#{richCalendarBean.valueChangeListener}"
verticalOffset="#{richCalendarBean.attributes['verticalOffset'].value}"
zindex="#{richCalendarBean.attributes['zindex'].value}"
@@ -165,7 +165,11 @@
<br/><br/>
- output: <h:outputText id="output"
value="#{richCalendarBean.attributes['value'].value}"/>
+ output:
+ <h:outputText id="output"
value="#{richCalendarBean.attributes['value'].value}">
+ <f:convertDateTime
pattern="#{richCalendarBean.attributes['datePattern'].value}"
+
timeZone="#{richCalendarBean.timeZone}"/>
+ </h:outputText>
</ui:define>
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java 2010-12-20
16:04:36 UTC (rev 20694)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java 2010-12-20
16:41:24 UTC (rev 20695)
@@ -21,6 +21,8 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richCalendar;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+
import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
@@ -86,4 +88,7 @@
protected JQueryLocator minutesInputDown =
pjq("div[id$=calendarTimeMinutesBtnDown]");
protected JQueryLocator okButton = pjq("td.rf-ca-time-layout-ok >
div");
protected JQueryLocator cancelButton = pjq("td.rf-ca-time-layout-cancel >
div");
+
+ protected JQueryLocator output = pjq("span[id$=output]");
+ JQueryLocator time = jq("span[id$=requestTime]");
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java 2010-12-20
16:04:36 UTC (rev 20694)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java 2010-12-20
16:41:24 UTC (rev 20695)
@@ -23,6 +23,7 @@
import static
org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
@@ -651,6 +652,22 @@
}
}
+ @Test
+ public void testValueChangeListener() {
+ String time1Value = selenium.getText(time);
+ selenium.click(input);
+ selenium.click(cellDay.format(6));
+ guardXhr(selenium).click(applyButton);
+ waitGui.failWith("Page was not updated").waitForChange(time1Value,
retrieveText.locator(time));
+
+ String selectedDate1 = selenium.getValue(input);
+ String selectedDate2 = selenium.getText(output);
+ String listenerOutput = selenium.getText(jq("ul.phases-list
li:eq(3)"));
+
+ assertEquals(selectedDate1, selectedDate2, "Output and calendar's input
should be the same.");
+ assertEquals(listenerOutput, "* value changed: null -> " +
selectedDate1);
+ }
+
/**
* Checks that no date in the open month is selected.
*/