Author: akushunin
Date: 2007-07-12 11:42:13 -0400 (Thu, 12 Jul 2007)
New Revision: 1608
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:
currentDateEvent Added
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-12
14:56:06 UTC (rev 1607)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-12
15:42:13 UTC (rev 1608)
@@ -30,14 +30,12 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
@@ -51,6 +49,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.html.BaseGradient.Data;
@@ -91,6 +90,7 @@
// currentDate processing -------------------------------------------------
private Date currentDate = null;
+
public Converter getConverter(FacesContext context, UICalendar calendar) {
@@ -124,7 +124,14 @@
Date valueString = calendar.getCurrentDate();
return valueString.toString();
}
+
+ public void decode(FacesContext context) {
+
+ super.decode(context);
+
+ }
+
// --------------------------------------------------------
private int getLastDayOfWeek(Calendar calendar) {
@@ -186,9 +193,14 @@
FacesContext facesContext = FacesContext.getCurrentInstance();
AjaxContext ajaxContext = AjaxContext
.getCurrentInstance(facesContext);
-
- ajaxContext.setResponseData(getPreload());
+ ajaxContext.setResponseData(getPreload());
}
+
+ //added recently
+ if (event instanceof CurrentDateEvent){
+ event.getPhaseId();
+ event.getComponent();
+ }
}
public Object getPreload() {
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-12
14:56:06 UTC (rev 1607)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-12
15:42:13 UTC (rev 1608)
@@ -22,16 +22,15 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.AbstractCollection;
import java.util.Calendar;
import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
@@ -39,55 +38,70 @@
import org.ajax4jsf.framework.util.javascript.JSFunctionDefinition;
import org.ajax4jsf.framework.util.javascript.JSReference;
import org.ajax4jsf.framework.util.javascript.ScriptUtils;
-import org.richfaces.component.CalendarDataModel;
-import org.richfaces.component.CalendarDataModelItem;
import org.richfaces.component.UICalendar;
import org.richfaces.component.util.HtmlUtil;
/**
- * @author Nick Belaevski - mailto:nbelaevski@exadel.com
- * created 08.06.2007
- *
+ * @author Nick Belaevski - mailto:nbelaevski@exadel.com created 08.06.2007
+ *
*/
public class CalendarRendererBase extends TemplateEncoderRendererBase {
public static final String DATE_SCROLL = "DateScroll";
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.framework.renderer.RendererBase#getComponentClass()
*/
protected Class getComponentClass() {
return UICalendar.class;
}
-
+
public String qualifySize(Object size) {
if (size == null) {
return "";
}
return HtmlUtil.qualifySize(size.toString());
}
-
+ public Date convertCurrentDate(String currentDateString) {
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.clear();
+ calendar.set(Calendar.DATE, 1);
+ int idx = currentDateString.indexOf('/');
+ calendar.set(Calendar.MONTH, Integer.parseInt(currentDateString
+ .substring(0, idx)));
+ calendar.set(Calendar.YEAR, Integer.parseInt(currentDateString
+ .substring(idx + 1)));
+
+ return calendar.getTime();
+
+ }
+
protected void doDecode(FacesContext context, UIComponent component) {
// TODO Auto-generated method stub
super.doDecode(context, component);
String clientId = component.getClientId(context);
- Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
- String currentDateString = (String) requestParameterMap.get(clientId + DATE_SCROLL);
+ Map requestParameterMap = context.getExternalContext()
+ .getRequestParameterMap();
+
+ String currentDateString = (String) requestParameterMap.get(clientId
+ + DATE_SCROLL);
+
if (currentDateString != null) {
- Calendar calendar = Calendar.getInstance();
- calendar.clear();
- calendar.set(Calendar.DATE, 1);
- int idx = currentDateString.indexOf('/');
- calendar.set(Calendar.MONTH, Integer.parseInt(currentDateString.substring(0, idx)));
- calendar.set(Calendar.YEAR, Integer.parseInt(currentDateString.substring(idx + 1)));
-
- ((UICalendar) component).setCurrentDate(calendar.getTime());
+ ((UICalendar) component)
+ .setCurrentDate(convertCurrentDate(currentDateString));
+ }
- new AjaxEvent(component).queue();
- }
+ CurrentDateEvent ev = new CurrentDateEvent(component) ;
+ ev.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ ev.queue();
+
+ new AjaxEvent(component).queue();
+
}
public void encodeChildren(FacesContext context, UIComponent calendar)
@@ -95,15 +109,18 @@
}
- public void writeMarkupScriptBody(FacesContext context, UIComponent component, boolean
children) throws IOException {
+ public void writeMarkupScriptBody(FacesContext context,
+ UIComponent component, boolean children) throws IOException {
ResponseWriter responseWriter = context.getResponseWriter();
- responseWriter.write("function (context) { return
this.invoke('getContent', context).join('')");
+ responseWriter
+ .write("function (context) { return this.invoke('getContent',
context).join('')");
responseWriter.write("}.bind(");
writeScriptBody(context, component, children);
responseWriter.write(")");
}
-
- public void writePreloadBody(FacesContext context, UICalendar calendar) throws
IOException {
+
+ public void writePreloadBody(FacesContext context, UICalendar calendar)
+ throws IOException {
Object preload = calendar.getPreload();
if (preload != null) {
ResponseWriter writer = context.getResponseWriter();
@@ -111,19 +128,21 @@
}
}
- public void writeSubmitFunction(FacesContext context, UICalendar calendar) throws
IOException {
+ public void writeSubmitFunction(FacesContext context, UICalendar calendar)
+ throws IOException {
ResponseWriter writer = context.getResponseWriter();
- String clientId = calendar.getClientId(context);
+ String clientId = calendar.getClientId(context);
- JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(calendar, context,
- AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(calendar,
+ context, AjaxRendererUtils.AJAX_FUNCTION_NAME);
ajaxFunction.addParameter(JSReference.NULL);
Map options = AjaxRendererUtils.buildEventOptions(context, calendar);
options.put("calendar", JSReference.THIS);
- //ajax single
- options.put("control", new JSReference(JSReference.THIS.toScript(),
"id"));
-
+ // ajax single
+ options.put("control", new JSReference(JSReference.THIS.toScript(),
+ "id"));
+
String oncomplete = AjaxRendererUtils.getAjaxOncomplete(calendar);
JSFunctionDefinition oncompleteDefinition = new JSFunctionDefinition();
oncompleteDefinition.addParameter("request");
@@ -133,7 +152,7 @@
if (oncomplete != null) {
oncompleteDefinition.addToBody(oncomplete);
}
-
+
options.put("oncomplete", oncompleteDefinition);
Map parametersMap = (Map) options.get("parameters");
JSReference requestValue = new JSReference("requestValue");
@@ -145,7 +164,7 @@
definition.addToBody(ajaxFunction);
writer.write(definition.toScript());
}
-
+
public static Object formatDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
@@ -158,4 +177,3 @@
}
}
-