Author: nbelaevski
Date: 2007-07-30 19:06:53 -0400 (Mon, 30 Jul 2007)
New Revision: 1938
Modified:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
Log:
Calendar code review results commited
Modified:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java 2007-07-30
23:06:05 UTC (rev 1937)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java 2007-07-30
23:06:53 UTC (rev 1938)
@@ -8,19 +8,23 @@
public class CurrentDateChangeEvent extends FacesEvent {
- private Date currentDate = null;
- private String currentDateString = null;
-
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8169207286087810907L;
+ private Date currentDate = null;
+ private String currentDateString = null;
+
public CurrentDateChangeEvent(UIComponent component, Date curentDate) {
- super(component);
- this.currentDate = curentDate;
-
+ super(component);
+ this.currentDate = curentDate;
+
}
public CurrentDateChangeEvent(UIComponent component, String curentDateString) {
- super(component);
- this.currentDateString = curentDateString;
+ super(component);
+ this.currentDateString = curentDateString;
}
-
+
public boolean isAppropriateListener(FacesListener listener) {
return false;
}
@@ -33,9 +37,9 @@
public Date getCurrentDate() {
return currentDate;
}
-
+
public String getCurrentDateString() {
return currentDateString;
}
-
+
}
Modified: trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-30
23:06:05 UTC (rev 1937)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-30
23:06:53 UTC (rev 1938)
@@ -21,7 +21,6 @@
package org.richfaces.component;
-import java.io.IOException;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Calendar;
@@ -30,24 +29,19 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Set;
import java.util.TimeZone;
import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.DateTimeConverter;
import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import javax.faces.event.ValueChangeEvent;
-import javax.faces.render.Renderer;
-import org.ajax4jsf.component.AjaxChildrenEncoder;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
import org.richfaces.model.CalendarDataModel;
@@ -133,21 +127,21 @@
// currentDate processing -------------------------------------------------
- public String getValueAsString(FacesContext context, UIComponent component)
- throws IOException {
- UICalendar calendar = (UICalendar) component;
- Date valueString = calendar.getCurrentDate();
- return valueString.toString();
- }
+// public String getValueAsString(FacesContext context, UIComponent component)
+// throws IOException {
+// UICalendar calendar = (UICalendar) component;
+// Date valueString = calendar.getCurrentDate();
+// return valueString.toString();
+// }
public Calendar getCalendar() {
return Calendar.getInstance(getTimeZone(), getLocale());
}
- public Converter getDateConverter() {
- DateTimeConverter datetime = new DateTimeConverter();
- return datetime;
- }
+// public Converter getDateConverter() {
+// DateTimeConverter datetime = new DateTimeConverter();
+// return datetime;
+// }
public Date getConvertedValue(FacesContext context, String currentDateString)
throws ConverterException {
@@ -160,7 +154,11 @@
}
protected void validateValue(FacesContext context, Object newValue) {
+ //TODO nick - nick - do we need this?
+ //store converted value in submitted value to ease client-side code's life
+ //see org.richfaces.renderkit.CalendarRendererBase.getSelectedDate(FacesContext,
UICalendar) for more
setSubmittedValue(newValue);
+
super.validateValue(context, newValue);
}
@@ -178,7 +176,8 @@
setCurrentDate(currentDate);
}
} catch (Exception e) {
-
+ //TODO nick - kaa - missed setValid(false) !
+ //TODO nick - kaa - add log.debug(...)
String messageString = e.getMessage();
FacesMessage message = new FacesMessage(messageString);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
@@ -267,12 +266,19 @@
// if currentDateString is not null then event cames from
// apply request phase
try {
+ //TODO nick - kaa - we should use datePattern attribute-based converter only for
selectedDate
+ // current date string always has predefined format: m/y
+ // review
org.richfaces.renderkit.CalendarRendererBase.convertCurrentDate(String) method
+ // for more
Date currentDate = getConvertedValue(facesContext,
currentDateString);
CurrentDateChangeEvent newDateChangeEvent = new CurrentDateChangeEvent(
this, currentDate);
newDateChangeEvent.queue();
} catch (Exception e) {
+ //TODO nick - kaa - add log.debug(...)
+ //TODO nick - kaa - we should stop processing on exc. setValid(false) and then call
FacesContext.renderResponse(...)
+ // update model phase shouldn't start
String messageString = e.getMessage();
FacesMessage message = new FacesMessage(messageString);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
@@ -346,15 +352,15 @@
return (Date[]) dates.toArray(new Date[dates.size()]);
}
- public void encodeAjaxChild(FacesContext context, String path, Set ids,
- Set renderedAreas) throws IOException {
-
- Renderer renderer = this.getRenderer(context);
- if (renderer instanceof AjaxChildrenEncoder) {
- ((AjaxChildrenEncoder) renderer).encodeAjaxChild(context, path,
- ids, renderedAreas);
- }
- }
+// public void encodeAjaxChild(FacesContext context, String path, Set ids,
+// Set renderedAreas) throws IOException {
+//
+// Renderer renderer = this.getRenderer(context);
+// if (renderer instanceof AjaxChildrenEncoder) {
+// ((AjaxChildrenEncoder) renderer).encodeAjaxChild(context, path,
+// ids, renderedAreas);
+// }
+// }
}
class AdaptingCollection extends AbstractCollection {
Modified:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-30
23:06:05 UTC (rev 1937)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-30
23:06:53 UTC (rev 1938)
@@ -31,7 +31,6 @@
import java.util.Map;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
@@ -50,7 +49,6 @@
import org.richfaces.component.CurrentDateChangeEvent;
import org.richfaces.component.UICalendar;
import org.richfaces.component.util.ComponentUtil;
-import org.richfaces.component.util.HtmlUtil;
/**
* @author Nick Belaevski - mailto:nbelaevski@exadel.com created 08.06.2007
@@ -79,13 +77,6 @@
return UICalendar.class;
}
- public String qualifySize(Object size) {
- if (size == null) {
- return "";
- }
- return HtmlUtil.qualifySize(size.toString());
- }
-
public void addPopupToAjaxRendered(FacesContext context,
UICalendar component) {
@@ -148,6 +139,7 @@
ev.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
ev.queue();
+ //TODO nick - nick - queue this event when ValueChangeEvent is queued?
new AjaxEvent(component).queue();
}
@@ -228,6 +220,7 @@
public String getInputValue(FacesContext context, UIComponent component) {
UICalendar input = (UICalendar) component;
+ //TODO nick - nick - can contain either Date or String instance
String value = (String) input.getSubmittedValue();
if (value == null) {
Object curVal = input.getValue();
@@ -238,6 +231,7 @@
// Converter converter =
// SelectUtils.getConverterForProperty(context, input, "value");
+ //TODO nick - kaa - how could converter be null here?
if (converter != null) {
value = converter.getAsString(context, input, curVal);
} else {
@@ -262,7 +256,7 @@
while (entryIterator.hasNext()) {
Map.Entry entry = (Map.Entry) entryIterator.next();
- writer.writeText(entry.getKey(), null);
+ writer.writeText(ScriptUtils.toScript(entry.getKey()), null);
writer.writeText(": ", null);
writer.writeText(ScriptUtils.toScript(entry.getValue()), null);
@@ -294,7 +288,7 @@
int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK);
int firstDayOfWeek = cal.getFirstDayOfWeek();
- // .getInstance(locale) changet to new DateFormatSymbols(locale) by
+ // .getInstance(locale) changed to new DateFormatSymbols(locale) by
// Alexej Kushunin ;
DateFormatSymbols symbols = new DateFormatSymbols(locale);
String[] weekDayLabels = ComponentUtil.asArray(calendar