Author: konstantin.mishin
Date: 2009-07-02 11:29:54 -0400 (Thu, 02 Jul 2009)
New Revision: 14770
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
Log:
RF-7332
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-07-02
15:29:54 UTC (rev 14770)
@@ -25,6 +25,7 @@
import org.ajax4jsf.templatecompiler.builder.CompilationContext;
import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
import org.apache.velocity.VelocityContext;
@@ -44,6 +45,8 @@
private String variableName;
+ private String base;
+
private static final Class<?> VARIABLE_TYPE = HashMap.class;
public ScriptObjectTemplateElement(final Node element,
@@ -58,6 +61,13 @@
variableName = varNode.getNodeValue();
+ Node baseNode = nnm.getNamedItem("base");
+ if (baseNode != null) {
+ base = ELParser.compileEL(baseNode.getNodeValue(), componentBean);
+ } else {
+ base = "";
+ }
+
try {
this.getComponentBean().addVariable(variableName, VARIABLE_TYPE.getName());
} catch (CompilationException e) {
@@ -76,6 +86,7 @@
VelocityContext context = new VelocityContext();
context.put("variable", this.variableName);
context.put("type", VARIABLE_TYPE.getName().replace('$',
'.'));
+ context.put("base", this.base);
return this.getComponentBean().processTemplate(getTemplateName(), context);
}
Modified:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm 2009-07-02
15:29:54 UTC (rev 14770)
@@ -1 +1 @@
-$type $variable = new $type();
\ No newline at end of file
+$type $variable = new $type($base);
\ No newline at end of file
Modified:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm 2009-07-02
15:29:54 UTC (rev 14770)
@@ -1 +1 @@
-$type $variable = new $type();
\ No newline at end of file
+$type $variable = new $type($base);
\ No newline at end of file
Modified:
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
---
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2009-07-02
15:29:54 UTC (rev 14770)
@@ -54,7 +54,6 @@
import org.ajax4jsf.event.AjaxEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.richfaces.component.util.MessageUtil;
import org.richfaces.event.CurrentDateChangeEvent;
import org.richfaces.event.CurrentDateChangeListener;
import org.richfaces.model.CalendarDataModel;
@@ -95,25 +94,10 @@
public static final String COMPONENT_FAMILY = "org.richfaces.Calendar";
/**
- * Default value of "defaultTime" attribute
- */
- private static String DEFAULT_TIME_VALUE = "hours:12,minutes:0";
-
- /**
* Default pattern for defaultTime
*/
private static String DEFAULT_TIME_PATTERN = "HH:mm";
- /**
- * Constant "hours"
- */
- private static String HOURS_VALUE = "hours";
-
- /**
- * Constant "minutes"
- */
- private static String MINUTES_VALUE = "minutes";
-
public static final String AJAX_MODE = "ajax";
public static final String CLIENT_MODE = "client";
@@ -213,6 +197,10 @@
public abstract void setVerticalOffset(int verticalOffset);
+ public abstract int getFirstWeekDay();
+
+ public abstract void setFirstWeekDay(int firstWeekDay);
+
public abstract int getHorizontalOffset();
public abstract void setHorizontalOffset(int horizontalOffset);
@@ -331,34 +319,6 @@
return result;
}
- /**
- * Returns hours and minutes from "defaultTime" attribute as a String
- * with special format:
- * hours:"value_hours",minutes:"value_minutes"
- *
- * @return hours and minutes from "defaultTime" attribute
- */
- public String getPreparedDefaultTime() {
- Date date = getFormattedDefaultTime();
-
- if (date == null) {
- return DEFAULT_TIME_VALUE;
- }
- StringBuilder result = new StringBuilder();
-
- Calendar calendar = getCalendar();
- calendar.setTime(date);
-
- result.append("{").append(HOURS_VALUE).append(":");
- result.append(calendar.get(Calendar.HOUR_OF_DAY));
- result.append(",");
- result.append(MINUTES_VALUE).append(":");
- result.append(calendar.get(Calendar.MINUTE)).append("}");
-
- return result.toString();
-
- }
-
public void updateCurrentDate(FacesContext context, Object currentDate) {
if (context == null) {
@@ -705,6 +665,10 @@
}
}
+ public Locale getAsLocale() {
+ return getAsLocale(getLocale());
+ }
+
public Locale getAsLocale(Object locale) {
if (locale instanceof Locale) {
@@ -730,91 +694,6 @@
}
}
- protected int getDefaultFirstWeekDay() {
- Calendar cal = getCalendar();
- return cal.getFirstDayOfWeek() - cal.getActualMinimum(Calendar.DAY_OF_WEEK);
- }
-
- protected int getDefaultMinDaysInFirstWeek() {
- return getCalendar().getMinimalDaysInFirstWeek();
- }
- /**
- * Gets what the minimal days required in the first week of the year
- are; e.g., if the first week is defined as one that contains the first
- day of the first month of a year, this method returns 1. If the
- minimal days required must be a full week, this method returns 7.
- * Setter for minDaysInFirstWeek
- * @param minDaysInFirstWeek - new value
- */
- public void setMinDaysInFirstWeek( int __minDaysInFirstWeek ){
- this._minDaysInFirstWeek = __minDaysInFirstWeek;
- this._minDaysInFirstWeekSet = true;
- }
-
-
- /**
- * Gets what the minimal days required in the first week of the year
- are; e.g., if the first week is defined as one that contains the first
- day of the first month of a year, this method returns 1. If the
- minimal days required must be a full week, this method returns 7.
- * Getter for minDaysInFirstWeek
- * @return minDaysInFirstWeek value from local variable or value bindings
- */
- public int getMinDaysInFirstWeek( ){
- if(this._minDaysInFirstWeekSet){
- return this._minDaysInFirstWeek;
- }
- ValueExpression ve = getValueExpression("minDaysInFirstWeek");
- if (ve != null) {
- Integer value = (Integer) ve.getValue(getFacesContext().getELContext());
- if (null == value) {
- return getDefaultMinDaysInFirstWeek();
- }
- return (value.intValue());
- } else {
- return getDefaultMinDaysInFirstWeek();
- }
- }
- /**
- * Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
- * Setter for firstWeekDay
- * @param firstWeekDay - new value
- */
- public void setFirstWeekDay( int __firstWeekDay ){
- this._firstWeekDay = __firstWeekDay;
- this._firstWeekDaySet = true;
- }
-
-
- /**
- * Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
- * Getter for firstWeekDay
- * @return firstWeekDay value from local variable or value bindings
- */
- public int getFirstWeekDay( ){
- int result;
- if (this._firstWeekDaySet) {
- result = this._firstWeekDay;
- }else{
- ValueExpression ve = getValueExpression("firstWeekDay");
- if (ve != null) {
-
- Integer value = (Integer) ve.getValue(getFacesContext().getELContext());
- result = (value.intValue());
- } else {
- result = getDefaultFirstWeekDay();
- }
- }
- if (result < 0 || result > 6) {
- getFacesContext().getExternalContext()
- .log(result + " value of firstWeekDay attribute is not a legal one for
component: "
- + MessageUtil.getLabel(getFacesContext(), this)
- + ". Default value was applied.");
- result = getDefaultFirstWeekDay();
- }
- return result;
- }
-
public Object saveState(FacesContext context) {
return new Object [] {
super.saveState(context),
Modified:
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2009-07-02
15:29:54 UTC (rev 14770)
@@ -28,7 +28,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
@@ -59,6 +59,8 @@
import org.apache.commons.logging.LogFactory;
import org.richfaces.component.UICalendar;
import org.richfaces.component.util.ComponentUtil;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.context.RequestContext;
import org.richfaces.event.CurrentDateChangeEvent;
/**
@@ -76,6 +78,16 @@
protected static final String WEEK_DAY_LABELS = "weekDayLabels";
/**
+ * Constant "hours"
+ */
+ private static String HOURS_VALUE = "hours";
+
+ /**
+ * Constant "minutes"
+ */
+ private static String MINUTES_VALUE = "minutes";
+
+ /**
* The constant used to resolve id of hidden input placed on the page
* for storing current date in "MM/yyyy" format.
* Actual id of hidden input used on the page is #{clientId}InputCurrentDate
@@ -88,6 +100,7 @@
public static final String CALENDAR_BUNDLE =
"org.richfaces.renderkit.calendar";
+ private static final String LOCALES_KEY = "rich:locales";
private final static Log log = LogFactory
.getLog(CalendarRendererBase.class);
@@ -178,8 +191,24 @@
*
* @return hours and minutes from "defaultTime" attribute
*/
- public String getPreparedDefaultTime(UICalendar calendar) {
- return calendar.getPreparedDefaultTime();
+ public String getPreparedDefaultTime(UICalendar component) {
+ Date date = component.getFormattedDefaultTime();
+ StringBuilder result = new StringBuilder();
+ if (date != null) {
+ Calendar calendar = component.getCalendar();
+ calendar.setTime(date);
+ int hours = calendar.get(Calendar.HOUR_OF_DAY);
+ int minutes = calendar.get(Calendar.MINUTE);
+
+ if (hours != 12 || minutes != 0) {
+ result.append("{").append(HOURS_VALUE).append(":");
+ result.append(hours);
+ result.append(",");
+ result.append(MINUTES_VALUE).append(":");
+ result.append(minutes).append("}");
+ }
+ }
+ return result.toString();
}
/**
@@ -492,23 +521,22 @@
return returnValue;
}
- public void writeSymbols(FacesContext facesContext, UICalendar calendar)
+ public void writeDefaultSymbols(FacesContext facesContext, UICalendar calendar)
throws IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
- Map<String, String[]> symbolsMap = getSymbolsMap(facesContext, calendar);
- Iterator<Map.Entry<String, String[]>> entryIterator =
symbolsMap.entrySet().iterator();
- writer.writeText(",\n", null);
- while (entryIterator.hasNext()) {
- Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>)
entryIterator.next();
-
- /*writer.writeText(ScriptUtils.toScript(entry.getKey()), null);
- writer.writeText(": ", null);*/
- writer.writeText(ScriptUtils.toScript(entry.getValue()), null);
-
- if (entryIterator.hasNext()) {
- writer.writeText(",\n", null);
- }
+ RequestContext context = RequestContext.getInstance(facesContext);
+ Set<String> locales = (Set<String>)context.getAttribute(LOCALES_KEY);
+ if (locales == null) {
+ locales = new HashSet<String>(1);
+ context.setAttribute(LOCALES_KEY, locales);
}
+ String locale = calendar.getAsLocale().toString();
+ if (!locales.contains(locale)) {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.writeText("Richfaces.Calendar.addLocale('" + locale +
"', ", null);
+ writer.writeText(ScriptUtils.toScript(getDefaultSymbolsMap(calendar)), null);
+ writer.writeText(");\n", null);
+ locales.add(locale);
+ }
}
private static String[] shiftDates(int minimum, int maximum, String[] labels) {
@@ -523,10 +551,29 @@
return shiftedLabels;
}
- protected Map<String, String[]> getSymbolsMap(FacesContext facesContext,
UICalendar calendar) {
- Map<String, String[]> map = new LinkedHashMap<String, String[]>();
+ protected Map<String, Object> getSymbolsMap(FacesContext facesContext, UICalendar
calendar) {
+ Map<String, Object> map = new LinkedHashMap<String, Object>();
+ RendererUtils utils = getUtils();
+ utils.addToScriptHash(map, WEEK_DAY_LABELS,
ComponentUtil.asArray(calendar.getWeekDayLabels()));
+ utils.addToScriptHash(map, WEEK_DAY_LABELS_SHORT,
ComponentUtil.asArray(calendar.getWeekDayLabelsShort()));
+ utils.addToScriptHash(map, MONTH_LABELS,
ComponentUtil.asArray(calendar.getMonthLabels()));
+ utils.addToScriptHash(map, MONTH_LABELS_SHORT,
ComponentUtil.asArray(calendar.getMonthLabelsShort()));
+ int day = calendar.getFirstWeekDay();
+ if (0 <= day && day <= 6) {
+ utils.addToScriptHash(map, "firstWeekDay", day);
+ } else if (day != Integer.MIN_VALUE) {
+ facesContext.getExternalContext()
+ .log(day + " value of firstWeekDay attribute is not a legal one for component:
"
+ + MessageUtil.getLabel(facesContext, calendar) + ". Default value was
applied.");
+ }
- Locale locale = calendar.getAsLocale(calendar.getLocale());
+ return map;
+ }
+
+ protected Map<String, Object> getDefaultSymbolsMap(UICalendar calendar) {
+ Map<String, Object> map = new LinkedHashMap<String, Object>();
+
+ Locale locale = calendar.getAsLocale();
Calendar cal = calendar.getCalendar();
int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK);
int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK);
@@ -535,52 +582,28 @@
int monthMin = cal.getActualMinimum(Calendar.MONTH);
DateFormatSymbols symbols = new DateFormatSymbols(locale);
- String[] weekDayLabels = ComponentUtil.asArray(calendar
- .getWeekDayLabels());
- if (weekDayLabels == null) {
- weekDayLabels = symbols.getWeekdays();
- weekDayLabels = shiftDates(minimum, maximum, weekDayLabels);
- }
+ String[] weekDayLabels = symbols.getWeekdays();
+ weekDayLabels = shiftDates(minimum, maximum, weekDayLabels);
- String[] weekDayLabelsShort = ComponentUtil.asArray(calendar
- .getWeekDayLabelsShort());
- if (weekDayLabelsShort == null) {
- weekDayLabelsShort = symbols.getShortWeekdays();
- weekDayLabelsShort = shiftDates(minimum, maximum,
- weekDayLabelsShort);
- }
+ String[] weekDayLabelsShort = symbols.getShortWeekdays();
+ weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort);
- String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels());
- if (monthLabels == null) {
- monthLabels = symbols.getMonths();
- monthLabels = shiftDates(monthMin, monthMax, monthLabels);
- }
+ String[] monthLabels = symbols.getMonths();
+ monthLabels = shiftDates(monthMin, monthMax, monthLabels);
- String[] monthLabelsShort = ComponentUtil.asArray(calendar
- .getMonthLabelsShort());
- if (monthLabelsShort == null) {
- monthLabelsShort = symbols.getShortMonths();
- monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort);
- }
+ String[] monthLabelsShort = symbols.getShortMonths();
+ monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort);
map.put(WEEK_DAY_LABELS, weekDayLabels);
map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort);
map.put(MONTH_LABELS, monthLabels);
map.put(MONTH_LABELS_SHORT, monthLabelsShort);
+ map.put("minDaysInFirstWeek", cal.getMinimalDaysInFirstWeek());
+ map.put("firstWeekDay", cal.getFirstDayOfWeek() -
cal.getActualMinimum(Calendar.DAY_OF_WEEK));
return map;
}
- public String getFirstWeekDay(FacesContext context, UICalendar calendar)
- throws IOException {
- return String.valueOf(calendar.getFirstWeekDay());
- }
-
- public String getMinDaysInFirstWeek(FacesContext context,
- UICalendar calendar) throws IOException {
- return String.valueOf(calendar.getMinDaysInFirstWeek());
- }
-
public String getCurrentDateAsString(FacesContext context,
UICalendar calendar, Date date) throws IOException {
Modified:
branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2009-07-02
15:29:54 UTC (rev 14770)
@@ -333,6 +333,12 @@
:
['January','February','March','April','May','June','July','August','September','October','November','December']);
};
+Richfaces.Calendar.addLocale = function (locale, symbols) {
+ if (!Richfaces.Calendar[locale]) {
+ Richfaces.Calendar[locale] = symbols;
+ }
+};
+
/*Richfaces.Calendar.getDefaultWeekDayNames = function(shortNames)
{
return (shortNames
@@ -529,7 +535,7 @@
Calendar = Class.create();
Object.extend(Calendar.prototype, {
- initialize: function(id, defaultTime, minDaysInFirstWeek, firstWeekDay,
weekDayLabels, weekDayLabelsShort, monthLabels, monthLabelsShort, options, markups) {
+ initialize: function(id, locale, options, markups) {
// dayListMarkup - day cell markup
// context: {day, date, weekNumber, weekDayNumber, isWeekend, isCurrentMonth,
elementId, component}
// weekNumberMarkup - week number cell markup
@@ -585,6 +591,7 @@
this.id = id;
this.params = Object.clone(Richfaces.Calendar.defaultOptions);
+ Object.extend(this.params, Richfaces.Calendar[locale]);
Object.extend(this.params, options);
Object.extend(this.params, markups);
// labels
@@ -595,13 +602,6 @@
if (!value[name]) value[name] = defaultLabels[name];
}
this.params.labels = value;
- this.params.firstWeekDay = firstWeekDay;
- this.params.minDaysInFirstWeek = minDaysInFirstWeek;
- this.params.defaultTime = defaultTime;
- this.params.weekDayLabels = weekDayLabels;
- this.params.weekDayLabelsShort = weekDayLabelsShort;
- this.params.monthLabels = monthLabels;
- this.params.monthLabelsShort = monthLabelsShort;
this.popupOffset = {dx:this.params.horizontalOffset, dy:this.params.verticalOffset};
@@ -2408,7 +2408,8 @@
style: "z-index: 3;",
showApplyButton: false,
selectedDate: null,
- currentDate: null
+ currentDate: null,
+ defaultTime: {hours:12,minutes:0}
};
// must be :defaultTime, minDaysInFirstWeek, firstWeekday, weekDayLabels,
weekDayLabelsShort, monthLabels, monthLabelsShort
\ No newline at end of file
Modified:
branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
---
branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2009-07-02
15:13:23 UTC (rev 14769)
+++
branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2009-07-02
15:29:54 UTC (rev 14770)
@@ -155,8 +155,8 @@
</div>
<div style="display: none;" id="#{clientId}Script">
- <c:scriptObject var="options">
- <c:scriptOption attributes="enableManualInput, disabled, readonly,
resetTimeOnDateSelect, showApplyButton, styleClass" />
+ <c:scriptObject var="options" base="#{this:getSymbolsMap(context,
component)}">
+ <c:scriptOption attributes="enableManualInput, disabled, readonly,
resetTimeOnDateSelect, showApplyButton, styleClass, minDaysInFirstWeek" />
<c:scriptOption attributes="popup" defaultValue="true" />
<c:scriptOption attributes="showInput" defaultValue="true"
/>
<c:scriptOption attributes="ajaxSingle" defaultValue="true"
/>
@@ -182,14 +182,12 @@
<c:scriptOption attributes="ondateselected, ondateselect, ontimeselect,
ontimeselected, onchanged, ondatemouseover, ondatemouseout, onexpand, oncollapse,
oncurrentdateselect, oncurrentdateselected" wrapper="eventHandler" />
<c:scriptOption name="labels" value="#{this:getLabels(context,
component)}" />
+ <c:scriptOption name="defaultTime"
value="#{this:getPreparedDefaultTime(component)}" />
</c:scriptObject>
<script type="text/javascript">
+ <f:call name="writeDefaultSymbols" />
new Calendar('#{clientId}',
- #{this:getPreparedDefaultTime(component)},
- #{this:getMinDaysInFirstWeek(context, component)},
- #{this:getFirstWeekDay(context, component)}
- <f:call name="writeSymbols" />,
-
+ "#{component.asLocale}",
<c:if test="#{not empty options}">
<f:writeAsScript value="#{options}" />
</c:if>