Author: akushunin
Date: 2007-07-18 11:35:33 -0400 (Wed, 18 Jul 2007)
New Revision: 1678
Removed:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CurrentDateEvent.java
Modified:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
Log:
Added currentDateString to CurrentDateEvent
Added CurrentDateEvent handling
Added updateCurrentDate method
Removed updateModel method
Modified:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-18
15:28:21 UTC (rev 1677)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-18
15:35:33 UTC (rev 1678)
@@ -34,6 +34,8 @@
import java.util.Set;
import java.util.TimeZone;
+import javax.faces.application.FacesMessage;
+//import javax.faces.component.MessageFactory;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
@@ -52,7 +54,7 @@
import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.richfaces.renderkit.CalendarDataModelItemAdaptor;
import org.richfaces.renderkit.CalendarRendererBase;
-import org.richfaces.renderkit.CurrentDateEvent;
+import org.richfaces.renderkit.CurrentDateChangeEvent;
// import org.richfaces.renderkit.html.BaseGradient.Data;
@@ -103,58 +105,33 @@
public Date getConvertedValue(FacesContext context, String currentDateString)
throws ConverterException {
-
+
DateTimeConverter datetime = new DateTimeConverter();
datetime.setPattern("MM/yyyy");
Date newCurrentDate = (Date) datetime.getAsObject(context, this,
currentDateString);
return newCurrentDate;
}
+ public void updateCurrentDate(FacesContext context, Date currentDate) {
- public void updateModel(FacesContext context) {
-
if (context == null) {
throw new NullPointerException();
}
+ try{
ValueBinding vb = getValueBinding("currentDate");
if (vb != null) {
- vb.setValue(context, getLocalCurrentDate());
- //setValue(null);
- //setLocalValueSet(false);
+ vb.setValue(context, currentDate);
return;
+ }else{ setCurrentDate(currentDate);}
+ }catch (Exception e) {
+//TODO Add Exceptionhandling String messageStr = e.getMessage();
+// FacesMessage message = MessageFactory.getMessage(context, CONVERSION_MESSAGE_ID);
+// message.setSeverity(FacesMessage.SEVERITY_ERROR);
+// context.addMessage(getClientId(context), message);
}
}
-
- protected Date getLocalCurrentDate() {
-
- return this.currentDate;
- }
- protected void setLocalCurrentDate(Date currentDate){
-
- this.currentDate = currentDate;
- }
- public Object saveState(FacesContext context) {
-
- Object values[] = new Object[2];
- values[0] = super.saveState(context);
- values[1] = saveAttachedState(context, currentDate);
- return (values);
-
- }
-
- public void restoreState(FacesContext context, Object state) {
-
- Object values[] = (Object[]) state;
- super.restoreState(context, values[0]);
- currentDate = (Date) restoreAttachedState(context, values[1]);
-
- }
-
-
-
- // --------------------------------------------------------
private int getLastDayOfWeek(Calendar calendar) {
int i = calendar.getFirstDayOfWeek();
if (i == calendar.getActualMinimum(Calendar.DAY_OF_WEEK)) {
@@ -209,20 +186,43 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
// TODO Auto-generated method stub
- super.broadcast(event);
if (event instanceof AjaxEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
AjaxContext ajaxContext = AjaxContext
.getCurrentInstance(facesContext);
ajaxContext.setResponseData(getPreload());
+ } else {
+ if (event instanceof CurrentDateChangeEvent) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ CurrentDateChangeEvent dateChangeEvent = (CurrentDateChangeEvent) event;
+ String currentDateString = dateChangeEvent.getCurrentDateString();
+
+ if (currentDateString != null) {
+ // if currentDateString is not null then event cames from apply request phase
+ try {
+ Date currentDate = getConvertedValue(facesContext, currentDateString);
+ CurrentDateChangeEvent newDateChangeEvent = new CurrentDateChangeEvent(this,
currentDate);
+ newDateChangeEvent.queue();
+ } catch (Exception e) {
+ //TODO Add Exception Handling
+ }
+ }
+ else{
+ Date currentDate1 = dateChangeEvent.getCurrentDate();
+ Date currentDate2 = getCurrentDate();
+ if(!currentDate1.equals(currentDate2)){
+ updateCurrentDate(facesContext, currentDate1);
+ //TODO Add ValueChange Events for currentDate
+
+ }
+
+ }
+ } else {
+ super.broadcast(event);
+ }
+
}
- /* added recently
- if (event instanceof CurrentDateEvent) {
- event.getPhaseId();
- event.getComponent();
- }
- */
}
public Object getPreload() {
@@ -236,7 +236,8 @@
HashMap args = new HashMap();
args.put("startDate", CalendarRendererBase
.formatDate(preloadDateRange[0]));
- args.put("days", new AdaptingCollection(
+ args
+ .put("days", new AdaptingCollection(
calendarDataModelItems));
return args;
}
Modified:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-18
15:28:21 UTC (rev 1677)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-18
15:35:33 UTC (rev 1678)
@@ -94,18 +94,15 @@
+ DATE_SCROLL);
if (currentDateString != null) {
- ((UICalendar) component)
- .setCurrentDate(convertCurrentDate(currentDateString));
+// ((UICalendar) component)
+// .setCurrentDate(convertCurrentDate(currentDateString));
+ CurrentDateChangeEvent ev = new CurrentDateChangeEvent(component, currentDateString)
;
+ ev.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ ev.queue();
+
+ new AjaxEvent(component).queue();
}
-
-
-
-// CurrentDateEvent ev = new CurrentDateEvent(component) ;
-// ev.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
-// ev.queue();
-
- new AjaxEvent(component).queue();
}
Deleted:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CurrentDateEvent.java
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CurrentDateEvent.java 2007-07-18
15:28:21 UTC (rev 1677)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CurrentDateEvent.java 2007-07-18
15:35:33 UTC (rev 1678)
@@ -1,23 +0,0 @@
-package org.richfaces.renderkit;
-
-import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-
-public class CurrentDateEvent extends FacesEvent {
-
-
- public CurrentDateEvent(UIComponent component) {
- super(component);
- }
-
- public boolean isAppropriateListener(FacesListener listener) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void processListener(FacesListener listener) {
- // TODO Auto-generated method stub
- }
-
-}
Show replies by date