Author: abelevich
Date: 2011-01-24 10:25:54 -0500 (Mon, 24 Jan 2011)
New Revision: 21175
Modified:
trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
Log:
RF-10233 calendar: unexpected validation after month scrolling in ajax mode
Modified: trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2011-01-24 15:12:41
UTC (rev 21174)
+++ trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2011-01-24 15:25:54
UTC (rev 21175)
@@ -1,11 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:calendar="http://richfaces.org/input">
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:calendar="http://richfaces.org/input">
<!--
JBoss, Home of Professional Open Source
Copyright ${year}, Red Hat, Inc. and individual contributors
@@ -31,125 +31,134 @@
02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-->
<h:head>
- <title>Richfaces Calendar Demo</title>
- <script type="text/javascript">
- var myFunction = function(event) {
-
- }
- </script>
+ <title>Richfaces Calendar Demo</title>
+ <script>
+ var myFunction = function(event){
+ ;
+ }
+ </script>
</h:head>
<h:body>
- <h:form id="form">
- <a4j:outputPanel ajaxRendered="true">
- <h:messages />
- </a4j:outputPanel>
- <h:panelGrid id="panel" columns="3">
- <h:panelGroup layout="block">
- <calendar:calendar value="#{calendarBean.selectedDate}"
id="calendar"
- jointPoint="#{calendarBean.jointPoint}"
direction="#{calendarBean.direction}"
- locale="#{calendarBean.locale}"
popup="#{calendarBean.popup}"
- datePattern="#{calendarBean.pattern}"
- dataModel="#{calendarDataModel}"
- mode="#{calendarBean.mode}"
- disabled="false"
- cellWidth="24px"
- cellHeight="22px"
minDaysInFirstWeek="3"
- oncollapse="return onEvent.call(this,
event);"
- onexpand="return onEvent.call(this,
event);"
- oncurrentdateselect="return onEvent.call(this,
event);"
- oncurrentdateselected="return onEvent.call(this,
event);"
- ondateselect="return onEvent.call(this,
event);"
- ondateselected="return onEvent.call(this,
event);"
- ontimeselect="return onEvent.call(this,
event);"
- ontimeselected="return onEvent.call(this,
event);"
- oncomplete="return onEvent.call(this,
event);"
- onclean="return onEvent.call(this, event);"
- ondatemouseout="return onEvent.call(this,
event);"
- ondatemouseover="return onEvent.call(this,
event);"
- firstWeekDay="4"
-
horizontalOffset="#{calendarBean.horizontalOffset}"
-
verticalOffset="#{calendarBean.verticalOffset}"
defaultTime="11:22:01"
-
valueChangeListener="#{calendarBean.doValueChangeListener}"
-
currentDataChangeListener="#{calendarBean.doCurrentDataChangeListener}"
- onbeforedateselect="myFunction(event)"
- style="width:200px;border:10px solid
#000000"
- styleClass="hello"
- boundaryDatesMode="scroll"
- defaultLabel=""
- enableManualInput="false"
- >
+ <h:form id="form">
+ <h:panelGrid id="panel" columns="3">
+ <h:panelGroup layout="block">
+ <calendar:calendar value="#{calendarBean.selectedDate}"
id="calendar"
+ jointPoint="#{calendarBean.jointPoint}"
direction="#{calendarBean.direction}"
+ locale="#{calendarBean.locale}" popup="#{calendarBean.popup}"
+ datePattern="#{calendarBean.pattern}"
+ dataModel="#{calendarDataModel}"
+ mode="#{calendarBean.mode}"
+ disabled="false"
+ cellWidth="24px"
+ cellHeight="22px" minDaysInFirstWeek="3"
+ oncollapse="return onEvent.call(this, event);"
+ onexpand="return onEvent.call(this, event);"
+ oncurrentdateselect="return onEvent.call(this, event);"
+ oncurrentdateselected="return onEvent.call(this, event);"
+ ondateselect="return onEvent.call(this, event);"
+ ondateselected="return onEvent.call(this, event);"
+ ontimeselect="return onEvent.call(this, event);"
+ ontimeselected="return onEvent.call(this, event);"
+ oncomplete="return onEvent.call(this, event);"
+ onclean="return onEvent.call(this, event);"
+ ondatemouseout="return onEvent.call(this, event);"
+ ondatemouseover="return onEvent.call(this, event);"
+ firstWeekDay="4"
+ horizontalOffset="#{calendarBean.horizontalOffset}"
+ verticalOffset="#{calendarBean.verticalOffset}"
defaultTime="11:22:01"
+ valueChangeListener="#{calendarBean.doValueChangeListener}"
+ currentDataChangeListener="#{calendarBean.doCurrentDataChangeListener}"
+ onbeforedateselect="myFunction(event)"
+ style="width:200px;border:10px solid #000000"
+ styleClass="hello"
+ boundaryDatesMode = "scroll"
+ defaultLabel = "bla-bla-bla"
+ enableManualInput="false"
+ >
+
+ </calendar:calendar>
+ <h:outputText id="echo-text"
value="#{calendarBean.selectedDate}" />
+ </h:panelGroup>
+ <h:panelGrid columns="2">
+ <h:outputText value="Popup Mode:" />
+ <h:selectBooleanCheckbox value="#{calendarBean.popup}">
+ <f:ajax event="click" execute="@form" render="calendar
@this" />
+ </h:selectBooleanCheckbox>
+ <h:outputText value="Apply Button:" />
+ <h:selectBooleanCheckbox value="#{calendarBean.showApply}">
+ <f:ajax event="click" execute="@form" render="calendar
@this" />
+ </h:selectBooleanCheckbox>
+ <h:outputText value="Select Locale" />
+ <h:selectOneRadio value="en/US"
+ valueChangeListener="#{calendarBean.selectLocale}">
+ <f:ajax execute="@form" event="click" render="calendar
@this" />
+ <f:selectItem itemLabel="US" itemValue="en/US" />
+ <f:selectItem itemLabel="DE" itemValue="de/DE" />
+ <f:selectItem itemLabel="FR" itemValue="fr/FR" />
+ <f:selectItem itemLabel="RU" itemValue="ru/RU" />
+ </h:selectOneRadio>
- </calendar:calendar>
- <h:outputText id="echo-text"
value="#{calendarBean.selectedDate}"/>
- </h:panelGroup>
- <h:panelGrid columns="2">
- <h:outputText value="Popup Mode:"/>
- <h:selectBooleanCheckbox value="#{calendarBean.popup}">
- <f:ajax event="click" execute="@form"
render="calendar @this"/>
- </h:selectBooleanCheckbox>
- <h:outputText value="Apply Button:"/>
- <h:selectBooleanCheckbox
value="#{calendarBean.showApply}">
- <f:ajax event="click" execute="@form"
render="calendar @this"/>
- </h:selectBooleanCheckbox>
- <h:outputText value="Select Locale"/>
- <h:selectOneRadio value="en/US"
-
valueChangeListener="#{calendarBean.selectLocale}">
- <f:ajax execute="@form" event="click"
render="calendar @this"/>
- <f:selectItem itemLabel="US"
itemValue="en/US"/>
- <f:selectItem itemLabel="DE"
itemValue="de/DE"/>
- <f:selectItem itemLabel="FR"
itemValue="fr/FR"/>
- <f:selectItem itemLabel="RU"
itemValue="ru/RU"/>
- </h:selectOneRadio>
-
- <h:outputText value="Select Date Pattern:"/>
- <h:selectOneMenu value="#{calendarBean.pattern}">
- <f:ajax execute="@form" event="change"
render="calendar @this"/>
- <f:selectItem itemLabel="d/M/yy HH:mm"
itemValue="d/M/yy HH:mm"/>
- <f:selectItem itemLabel="dd/M/yy hh:mm a"
- itemValue="dd/M/yy hh:mm a"/>
- <f:selectItem itemLabel="dd/M/yy hh:mm:ss"
- itemValue="dd/M/yy hh:mm:ss"/>
- <f:selectItem itemLabel="d/MMM/y"
itemValue="d/MMM/y"/>
- <f:selectItem itemLabel="MMM d, yyyy"
itemValue="MMM d, yyyy"/>
- </h:selectOneMenu>
-
- <h:outputText value="Mode"/>
- <h:selectOneMenu value="#{calendarBean.mode}"
onchange="submit()">
- <f:selectItem itemValue="client"/>
- <f:selectItem itemValue="ajax"/>
- </h:selectOneMenu>
-
- <h:outputText value="Select joint point:"/>
- <h:selectOneMenu value="#{calendarBean.jointPoint}">
- <a4j:ajax execute="@form" event="change"
render="calendar, @this"/>
- <f:selectItems value="#{calendarBean.positioningValues}"
var="v" itemLabel="#{v}" itemValue="#{v}"/>
- </h:selectOneMenu>
- <h:outputText value="Select direction:"/>
- <h:selectOneMenu value="#{calendarBean.direction}">
- <f:ajax execute="@form" event="change"
reRender="calendar, @this"/>
- <f:selectItems value="#{calendarBean.positioningValues}"
var="v" itemLabel="#{v}" itemValue="#{v}"/>
- </h:selectOneMenu>
- <h:outputText value="Horisontal offset:"/>
- <h:inputText value="#{calendarBean.horizontalOffset}">
- <f:ajax execute="@form" event="change"
render="calendar @this"/>
- </h:inputText>
- <h:outputText value="Vertical offset:"/>
- <h:inputText value="#{calendarBean.verticalOffset}">
- <f:ajax execute="@form" event="change"
render="calendar @this"/>
- </h:inputText>
- </h:panelGrid>
- </h:panelGrid>
- <br/>
-
- <div>
- <a4j:log/>
- </div>
- <script type="text/javascript">
- onEvent = function(event, element, data) {
- RichFaces.log.info("jQuery Event: " + (event instanceof
jQuery.Event) + "; event: " + event.type + "; data:" + (data ||
(event['rich'] || {})['data']) + "; this.id:" + this.id +
"; component:" + (event['rich'] || {})['component'] ||
RichFaces.$(this.id));
- };
- //RichFaces.Event.bindById("form:calendar", "dateselect
dateselected currentdateselect currentdateselected timeselect timeselected changed clean
collapse expand complete datemouseout datemouseout", onEvent);
- </script>
- </h:form>
+ <h:outputText value="Select Date Pattern:" />
+ <h:selectOneMenu value="#{calendarBean.pattern}">
+ <f:ajax execute="@form" event="change" render="calendar
@this" />
+ <f:selectItem itemLabel="d/M/yy HH:mm" itemValue="d/M/yy
HH:mm" />
+ <f:selectItem itemLabel="dd/M/yy hh:mm a"
+ itemValue="dd/M/yy hh:mm a" />
+ <f:selectItem itemLabel="dd/M/yy hh:mm:ss"
+ itemValue="dd/M/yy hh:mm:ss" />
+ <f:selectItem itemLabel="d/MMM/y" itemValue="d/MMM/y" />
+ <f:selectItem itemLabel="MMM d, yyyy" itemValue="MMM d, yyyy"
/>
+ </h:selectOneMenu>
+
+ <h:outputText value="Mode" />
+ <h:selectOneMenu value="#{calendarBean.mode}"
onchange="submit()">
+ <f:selectItem itemValue="client"/>
+ <f:selectItem itemValue="ajax"/>
+ </h:selectOneMenu>
+
+ <h:outputText value="Select joint point:" />
+ <h:selectOneMenu value="#{calendarBean.jointPoint}">
+ <f:ajax execute="@form" event="change" render="calendar
@this" />
+ <f:selectItem itemLabel="auto" itemValue="auto" />
+ <f:selectItem itemLabel="top-left" itemValue="top-left"
/>
+ <f:selectItem itemLabel="top-right" itemValue="top-right"
/>
+ <f:selectItem itemLabel="bottom-left" itemValue="bottom-left"
/>
+ <f:selectItem itemLabel="bottom-right"
itemValue="bottom-right" />
+ </h:selectOneMenu>
+ <h:outputText value="Select direction:" />
+ <h:selectOneMenu value="#{calendarBean.direction}">
+ <f:ajax execute="@form" event="change" render="calendar
@this" />
+ <f:selectItem itemLabel="auto" itemValue="auto" />
+ <f:selectItem itemLabel="top-left" itemValue="top-left"
/>
+ <f:selectItem itemLabel="top-right" itemValue="top-right"
/>
+ <f:selectItem itemLabel="bottom-left" itemValue="bottom-left"
/>
+ <f:selectItem itemLabel="bottom-right"
itemValue="bottom-right" />
+ </h:selectOneMenu>
+ <h:outputText value="Horisontal offset:" />
+ <h:inputText value="#{calendarBean.horizontalOffset}">
+ <f:ajax execute="@form" event="change" render="calendar
@this" />
+ </h:inputText>
+ <h:outputText value="Vertical offset:" />
+ <h:inputText value="#{calendarBean.verticalOffset}">
+ <f:ajax execute="@form" event="change" render="calendar
@this" />
+ </h:inputText>
+ </h:panelGrid>
+ <h:panelGroup layout="block">
+ <div>
+ <a4j:log mode="inline"></a4j:log>
+ </div>
+ <script type="text/javascript">
+ onEvent = function(event, element, data){
+ RichFaces.log.info("jQuery Event: "+(event instanceof
jQuery.Event)+"; event: "+event.type+"; data:"+(data ||
(event['rich']||{})['data'])+"; this.id:"+this.id+";
component:"+
(event['rich']||{})['component']||RichFaces.$(this.id));
+ };
+ //RichFaces.Event.bindById("form:calendar", "dateselect dateselected
currentdateselect currentdateselected timeselect timeselected changed clean collapse
expand complete datemouseout datemouseout", onEvent);
+ </script>
+ </h:panelGroup>
+ <br/>
+ <a4j:outputPanel ajaxRendered="true">
+ <h:messages />
+ </a4j:outputPanel>
+ </h:panelGrid>
+ </h:form>
</h:body>
</html>
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2011-01-24
15:12:41 UTC (rev 21174)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2011-01-24
15:25:54 UTC (rev 21175)
@@ -43,7 +43,8 @@
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
-import javax.faces.event.PhaseId;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
@@ -93,8 +94,6 @@
ajax
}
- private Object submittedCurrentDate = null;
-
@Attribute
public abstract String getDatePattern();
@@ -331,48 +330,37 @@
public void setLocale(Object locale) {
getStateHelper().put(PropertyKeys.locale, locale);
}
-
- public Object getSubmittedCurrentDate() {
- return submittedCurrentDate;
- }
- public void setSubmittedCurrentDate(Object submittedCurrentDate) {
- this.submittedCurrentDate = submittedCurrentDate;
- }
-
@Override
- public void validate(FacesContext context) {
- super.validate(context);
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ if (event instanceof CurrentDateChangeEvent) {
+ FacesContext facesContext = getFacesContext();
+ CurrentDateChangeEvent currentDateChangeEvent = (CurrentDateChangeEvent)
event;
+ String currentDateString = currentDateChangeEvent.getCurrentDateString();
+ try {
+ // we should use datePattern attribute-based converter only for
+ // selectedDate
+ // current date string always has predefined format: m/y
+ Date currentDate = CalendarHelper.getAsDate(facesContext, this,
getCurrentDate());
+ Date submittedCurrentDate =
CalendarHelper.convertCurrentDate(currentDateString);
+ currentDateChangeEvent.setCurrentDate(submittedCurrentDate);
- try {
- // we should use datePattern attribute-based converter only for
- // selectedDate
- // current date string always has predefined format: m/y
- String submittedCurrentDateString = (String) this.getSubmittedCurrentDate();
- Date currentDate = CalendarHelper.getAsDate(context, this,
getCurrentDate());
- Date submittedCurrentDate =
CalendarHelper.convertCurrentDate(submittedCurrentDateString);
-
- if (!submittedCurrentDate.equals(currentDate)) {
- updateCurrentDate(context, submittedCurrentDate);
+ if (!submittedCurrentDate.equals(currentDate)) {
+ updateCurrentDate(facesContext, submittedCurrentDate);
+ }
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.debug(" currentDate convertion fails with following
exception: " + e.toString(), e);
+ }
+ setValid(false);
+ String messageString = e.toString();
+ FacesMessage message = new FacesMessage(messageString);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ facesContext.addMessage(getClientId(facesContext), message);
+ facesContext.renderResponse();
}
-
- CurrentDateChangeEvent currentDateChangeEvent = new
CurrentDateChangeEvent(this, submittedCurrentDateString);
- currentDateChangeEvent.setCurrentDate(submittedCurrentDate);
- currentDateChangeEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
- queueEvent(currentDateChangeEvent);
-
- } catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.debug(" currentDate convertion fails with following exception:
" + e.toString(), e);
- }
- setValid(false);
- String messageString = e.toString();
- FacesMessage message = new FacesMessage(messageString);
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- context.renderResponse();
- }
-
+ }
+ super.broadcast(event);
}
public void updateCurrentDate(FacesContext facesContext, Object currentDate) {
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2011-01-24
15:12:41 UTC (rev 21174)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2011-01-24
15:25:54 UTC (rev 21175)
@@ -54,6 +54,7 @@
import org.richfaces.component.util.MessageUtil;
import org.richfaces.component.util.SelectUtils;
import org.richfaces.context.ExtendedPartialViewContext;
+import org.richfaces.event.CurrentDateChangeEvent;
import org.richfaces.utils.CalendarHelper;
/**
@@ -163,8 +164,10 @@
Map<String, String> requestParameterMap =
context.getExternalContext().getRequestParameterMap();
String clientId = calendar.getClientId(context);
- String currentDateString = requestParameterMap.get(clientId +
CURRENT_DATE_INPUT);
- calendar.setSubmittedCurrentDate(currentDateString);
+ String currentDateString = (String) requestParameterMap.get(clientId +
CURRENT_DATE_INPUT);
+ if (currentDateString != null) {
+ calendar.queueEvent(new CurrentDateChangeEvent(calendar,
currentDateString));
+ }
String selectedDateString = requestParameterMap.get(clientId +
"InputDate");
if (selectedDateString != null) {
@@ -176,6 +179,8 @@
pvc.getRenderIds().add(
component.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
+ AbstractCalendar.DAYSDATA_META_COMPONENT_ID);
+
+ context.renderResponse();
}
}
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2011-01-24
15:12:41 UTC (rev 21174)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2011-01-24
15:25:54 UTC (rev 21175)
@@ -1449,6 +1449,11 @@
{
var dataDays=event.componentData[_this.id]
_this.load(dataDays, true);
+ } else {
+ //
https://issues.jboss.org/browse/RF-10233
+ // if calendar DataModel is empty and month is scrolled, so
+ // calendar should be rendered
+ _this.render();
}
}
var ajaxError = function (event) {