Author: Alex.Kolonitsky
Date: 2009-11-09 03:44:51 -0500 (Mon, 09 Nov 2009)
New Revision: 15852
Added:
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/webapp/pages/RF-8001.jsp
Modified:
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
Log:
calendar: initialization failed if any facet defined and day markup is default(not
redefined).
https://jira.jboss.org/jira/browse/RF-8001
Modified:
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java
===================================================================
---
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java 2009-11-06
19:18:31 UTC (rev 15851)
+++
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java 2009-11-09
08:44:51 UTC (rev 15852)
@@ -31,257 +31,265 @@
/**
* 20/07/2007
- *
+ *
* @author Alexej Kushunin
* @mailto: akushunin(a)exadel.com
- *
*/
public class CalendarBean {
- private static final String[] WEEK_DAY_LABELS = new String[] { "Sun *",
- "Mon +", "Tue +", "Wed +", "Thu +", "Fri
+", "Sat *" };
- private Locale locale;
+ private static final String[] WEEK_DAY_LABELS = new String[]{"Sun *",
+ "Mon +", "Tue +", "Wed +", "Thu +",
"Fri +", "Sat *"};
+ private Locale locale;
- private boolean popup;
- private boolean readonly;
- private boolean showInput;
- private boolean enableManualInput;
- private boolean disabled;
- private boolean showApplyButton;
- private String pattern;
- private Date currentDate;
- private Date selectedDate;
- private String jointPoint;
- private String direction;
- private String boundary;
- private String todayControlMode;
- private boolean showHeader;
- private boolean showFooter;
- private boolean resetTimeOnDateSelect;
+ private boolean popup;
+ private boolean readonly;
+ private boolean showInput;
+ private boolean enableManualInput;
+ private boolean disabled;
+ private boolean showApplyButton;
+ private String pattern;
+ private Date currentDate;
+ private Date selectedDate;
+ private String jointPoint;
+ private String direction;
+ private String boundary;
+ private String todayControlMode;
+ private boolean showApply;
+ private boolean showHeader;
+ private boolean showFooter;
+ private boolean resetTimeOnDateSelect;
- private int counter;
-
-
-
-
- private boolean useCustomDayLabels;
+ private int counter;
- public Locale getLocale() {
- return locale;
- }
- public void setLocale(Locale locale) {
- this.locale = locale;
- }
+ private boolean useCustomDayLabels;
- public boolean isPopup() {
- return popup;
- }
+ public Locale getLocale() {
+ return locale;
+ }
- public void setPopup(boolean popup) {
- this.popup = popup;
- }
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
- public String getPattern() {
- return pattern;
- }
+ public boolean isPopup() {
+ return popup;
+ }
- public void setPattern(String pattern) {
-
- this.pattern = pattern;
- }
+ public void setPopup(boolean popup) {
+ this.popup = popup;
+ }
- public void selectPattern(ValueChangeEvent event) {
- String tPatern = (String) event.getNewValue();
- if (tPatern != null) {
- pattern = tPatern;
- }
- }
+ public String getPattern() {
+ return pattern;
+ }
- public CalendarBean() {
+ public void setPattern(String pattern) {
- locale = Locale.US;
- popup = true;
- pattern = "MMM d, yyyy";
- jointPoint = "bottom-left";
- direction = "bottom-right";
- readonly = true;
- enableManualInput=false;
- showInput=true;
- boundary = "inactive";
- disabled = false;
- todayControlMode = "select";
- resetTimeOnDateSelect = false;
-
- }
-
-
- public boolean isShowInput() {
- return showInput;
- }
+ this.pattern = pattern;
+ }
- public void setShowInput(boolean showInput) {
- this.showInput = showInput;
- }
+ public void selectPattern(ValueChangeEvent event) {
+ String tPatern = (String) event.getNewValue();
+ if (tPatern != null) {
+ pattern = tPatern;
+ }
+ }
- public boolean isEnableManualInput() {
- return enableManualInput;
- }
+ public CalendarBean() {
- public void setEnableManualInput(boolean enableManualInput) {
- this.enableManualInput = enableManualInput;
- }
+ locale = Locale.US;
+ popup = true;
+ pattern = "MMM d, yyyy";
+ jointPoint = "bottom-left";
+ direction = "bottom-right";
+ readonly = true;
+ enableManualInput = false;
+ showInput = true;
+ boundary = "inactive";
+ disabled = false;
+ todayControlMode = "select";
+ resetTimeOnDateSelect = false;
- public boolean isReadonly() {
- return readonly;
- }
+ }
- public void setReadonly(boolean readonly) {
- this.readonly = readonly;
- }
- public void selectLocale(ValueChangeEvent event) {
+ public boolean isShowInput() {
+ return showInput;
+ }
- String tLocale = (String) event.getNewValue();
- if (tLocale != null) {
- String lang = tLocale.substring(0, 2);
- String country = tLocale.substring(3);
- locale = new Locale(lang, country, "");
- }
- }
+ public void setShowInput(boolean showInput) {
+ this.showInput = showInput;
+ }
- public boolean isUseCustomDayLabels() {
- return useCustomDayLabels;
- }
+ public boolean isEnableManualInput() {
+ return enableManualInput;
+ }
- public void setUseCustomDayLabels(boolean useCustomDayLabels) {
- this.useCustomDayLabels = useCustomDayLabels;
- }
+ public void setEnableManualInput(boolean enableManualInput) {
+ this.enableManualInput = enableManualInput;
+ }
- public Object getWeekDayLabelsShort() {
- if (isUseCustomDayLabels()) {
- return WEEK_DAY_LABELS;
- } else {
- return null;
- }
- }
+ public boolean isReadonly() {
+ return readonly;
+ }
- public String getCurrentDateAsText() {
- Date currentDate = getCurrentDate();
- if (currentDate != null) {
- return DateFormat.getDateInstance(DateFormat.FULL).format(
- currentDate);
- }
+ public void setReadonly(boolean readonly) {
+ this.readonly = readonly;
+ }
- return null;
- }
+ public void selectLocale(ValueChangeEvent event) {
- public Date getCurrentDate() {
- return currentDate;
- }
+ String tLocale = (String) event.getNewValue();
+ if (tLocale != null) {
+ String lang = tLocale.substring(0, 2);
+ String country = tLocale.substring(3);
+ locale = new Locale(lang, country, "");
+ }
+ }
- public void setCurrentDate(Date currentDate) {
- this.currentDate = currentDate;
- }
+ public boolean isUseCustomDayLabels() {
+ return useCustomDayLabels;
+ }
- public Date getSelectedDate() {
- return selectedDate;
- }
+ public void setUseCustomDayLabels(boolean useCustomDayLabels) {
+ this.useCustomDayLabels = useCustomDayLabels;
+ }
- public void setSelectedDate(Date selectedDate) {
- this.selectedDate = selectedDate;
- }
+ public Object getWeekDayLabelsShort() {
+ if (isUseCustomDayLabels()) {
+ return WEEK_DAY_LABELS;
+ } else {
+ return null;
+ }
+ }
- public String getJointPoint() {
- return jointPoint;
- }
+ public String getCurrentDateAsText() {
+ Date currentDate = getCurrentDate();
+ if (currentDate != null) {
+ return DateFormat.getDateInstance(DateFormat.FULL).format(
+ currentDate);
+ }
- public void setJointPoint(String jointPoint) {
- this.jointPoint = jointPoint;
- }
+ return null;
+ }
- public void selectJointPoint(ValueChangeEvent event) {
- jointPoint = (String) event.getNewValue();
- }
+ public Date getCurrentDate() {
+ return currentDate;
+ }
- public String getDirection() {
- return direction;
- }
+ public void setCurrentDate(Date currentDate) {
+ this.currentDate = currentDate;
+ }
- public void setDirection(String direction) {
- this.direction = direction;
- }
+ public Date getSelectedDate() {
+ return selectedDate;
+ }
- public void selectDirection(ValueChangeEvent event) {
- direction = (String) event.getNewValue();
- }
+ public void setSelectedDate(Date selectedDate) {
+ this.selectedDate = selectedDate;
+ }
- public String getBoundary() {
- return boundary;
- }
+ public String getJointPoint() {
+ return jointPoint;
+ }
- public void setBoundary(String boundary) {
- this.boundary = boundary;
- }
- public void dcl(CurrentDateChangeEvent event){
- System.out.println(event.getCurrentDateString());
- System.out.println("ajvhckndskncs");
- }
- public void ddd(ValueChangeEvent event){
- System.out.println(event.getOldValue());
- System.out.println(event.getNewValue());
-
- }
+ public void setJointPoint(String jointPoint) {
+ this.jointPoint = jointPoint;
+ }
- public int getCounter() {
- return counter++;
- }
+ public void selectJointPoint(ValueChangeEvent event) {
+ jointPoint = (String) event.getNewValue();
+ }
- public boolean isDisabled() {
- return disabled;
- }
+ public String getDirection() {
+ return direction;
+ }
- public void setDisabled(boolean disabled) {
- this.disabled = disabled;
- }
+ public void setDirection(String direction) {
+ this.direction = direction;
+ }
- public boolean isShowApplyButton() {
- return showApplyButton;
- }
+ public void selectDirection(ValueChangeEvent event) {
+ direction = (String) event.getNewValue();
+ }
- public void setShowApplyButton(boolean showApplyButton) {
- this.showApplyButton = showApplyButton;
- }
+ public String getBoundary() {
+ return boundary;
+ }
- public String getTodayControlMode() {
- return todayControlMode;
- }
+ public void setBoundary(String boundary) {
+ this.boundary = boundary;
+ }
- public void setTodayControlMode(String todayControlMode) {
- this.todayControlMode = todayControlMode;
- }
+ public void dcl(CurrentDateChangeEvent event) {
+ System.out.println(event.getCurrentDateString());
+ System.out.println("ajvhckndskncs");
+ }
- public boolean isShowHeader() {
- return showHeader;
- }
+ public void ddd(ValueChangeEvent event) {
+ System.out.println(event.getOldValue());
+ System.out.println(event.getNewValue());
- public void setShowHeader(boolean showHeader) {
- this.showHeader = showHeader;
- }
+ }
- public boolean isShowFooter() {
- return showFooter;
- }
+ public int getCounter() {
+ return counter++;
+ }
- public void setShowFooter(boolean showFooter) {
- this.showFooter = showFooter;
- }
+ public boolean isDisabled() {
+ return disabled;
+ }
- public boolean isResetTimeOnDateSelect() {
- return resetTimeOnDateSelect;
- }
+ public void setDisabled(boolean disabled) {
+ this.disabled = disabled;
+ }
- public void setResetTimeOnDateSelect(boolean resetTimeOnDateSelect) {
- this.resetTimeOnDateSelect = resetTimeOnDateSelect;
- }
+ public boolean isShowApplyButton() {
+ return showApplyButton;
+ }
+
+ public void setShowApplyButton(boolean showApplyButton) {
+ this.showApplyButton = showApplyButton;
+ }
+
+ public String getTodayControlMode() {
+ return todayControlMode;
+ }
+
+ public void setTodayControlMode(String todayControlMode) {
+ this.todayControlMode = todayControlMode;
+ }
+
+ public boolean isShowHeader() {
+ return showHeader;
+ }
+
+ public void setShowHeader(boolean showHeader) {
+ this.showHeader = showHeader;
+ }
+
+ public boolean isShowFooter() {
+ return showFooter;
+ }
+
+ public void setShowFooter(boolean showFooter) {
+ this.showFooter = showFooter;
+ }
+
+ public boolean isResetTimeOnDateSelect() {
+ return resetTimeOnDateSelect;
+ }
+
+ public void setResetTimeOnDateSelect(boolean resetTimeOnDateSelect) {
+ this.resetTimeOnDateSelect = resetTimeOnDateSelect;
+ }
+
+ public boolean isShowApply() {
+ return showApply;
+ }
+
+ public void setShowApply(boolean showApply) {
+ this.showApply = showApply;
+ }
}
\ No newline at end of file
Added:
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/webapp/pages/RF-8001.jsp
===================================================================
--- branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/webapp/pages/RF-8001.jsp
(rev 0)
+++
branches/sandbox/3.3.X_JSF2/samples/calendar-sample/src/main/webapp/pages/RF-8001.jsp 2009-11-09
08:44:51 UTC (rev 15852)
@@ -0,0 +1,27 @@
+<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/calendar"
prefix="rich" %>
+<html>
+<head>
+ <title></title>
+</head>
+<body dir="rtl">
+<f:view>
+ <h:form id="f">
+ <rich:calendar value="#{calendarBean.selectedDate}"
+ locale="#{calendarBean.locale}"
+ popup="#{calendarBean.popup}"
+ datePattern="#{calendarBean.pattern}"
+ showApplyButton="#{calendarBean.showApply}">
+
+ <f:facet name="weekDay">
+ <h:outputText value="{weekDayLabelShort}"/>
+ </f:facet>
+ <f:facet name="weekNumber">
+ <h:outputText value="1"/>
+ </f:facet>
+ </rich:calendar>
+ </h:form>
+</f:view>
+</body>
+</html>
\ No newline at end of file
Modified:
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2009-11-06
19:18:31 UTC (rev 15851)
+++
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2009-11-09
08:44:51 UTC (rev 15852)
@@ -21,32 +21,6 @@
package org.richfaces.renderkit;
-import java.io.IOException;
-import java.text.DateFormatSymbols;
-import java.text.Format;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.TimeZone;
-
-import javax.el.ValueExpression;
-import javax.faces.application.Application;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.convert.DateTimeConverter;
-import javax.faces.event.PhaseId;
-
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.javascript.JSFunction;
@@ -57,12 +31,31 @@
import org.ajax4jsf.renderkit.RendererUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.richfaces.component.TemplateComponent;
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;
+import org.richfaces.json.JSONObject;
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.DateTimeConverter;
+import javax.faces.event.PhaseId;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.text.DateFormatSymbols;
+import java.text.Format;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
/**
* @author Nick Belaevski - mailto:nbelaevski@exadel.com created 08.06.2007
*
@@ -187,7 +180,7 @@
* Returns hours and minutes from "defaultTime" attribute as a String with
* special format: hours:"value_hours",minutes:"value_minutes"
*
- * @param calendar - UICalendar
+ * @param component - UICalendar
*
* @return hours and minutes from "defaultTime" attribute
*/
@@ -286,7 +279,6 @@
/**
* Creates default <code>DateTimeConverter</code> for the calendar
- * @param calendar - calendar component
*
* @return created converter
*/
@@ -317,7 +309,8 @@
return converter;
}
- protected void doDecode(FacesContext context, UIComponent component) {
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
// TODO Auto-generated method stub
super.doDecode(context, component);
@@ -353,7 +346,8 @@
}
}
- public void encodeChildren(FacesContext context, UIComponent calendar)
+ @Override
+ public void encodeChildren(FacesContext context, UIComponent calendar)
throws IOException {
}
@@ -378,24 +372,54 @@
}
return null;
- }
-
- public void writeMarkupScriptBody(FacesContext context,
- UIComponent component, boolean children) throws IOException {
- writeScriptBody(context, component, children);
}
- public void writeOptionalFacetMarkupScriptBody(FacesContext context,
- UIComponent component, String facetName) throws IOException {
+ public String getMarkupScriptBody(FacesContext context, UIComponent component,
boolean children)
+ throws IOException {
- UIComponent facet = component.getFacet(facetName);
- if (facet != null && facet.isRendered()) {
- ResponseWriter writer = context.getResponseWriter();
- writer.writeText(",\n " + facetName + MARKUP_SUFFIX + ": ",
null);
- writeMarkupScriptBody(context, facet, false);
- }
- }
+ ResponseWriter writer = context.getResponseWriter();
+ Writer dumpingWriter = new StringWriter();
+ ResponseWriter clonedWriter = writer.cloneWithWriter(dumpingWriter);
+ context.setResponseWriter(clonedWriter);
+ TemplateComponent templateComponent = null;
+ if (component instanceof TemplateComponent) {
+ templateComponent = (TemplateComponent) component;
+ }
+
+ try {
+ if (templateComponent != null) {
+ templateComponent.startTemplateEncode();
+ }
+
+ if (children) {
+ this.renderChildren(context, component);
+ } else {
+ this.renderChild(context, component);
+ }
+ } finally {
+ if (templateComponent != null) {
+ templateComponent.endTemplateEncode();
+ }
+
+ clonedWriter.flush();
+ context.setResponseWriter(writer);
+ }
+
+ return dumpingWriter.toString();
+ }
+
+ public String getOptionalFacetMarkupScriptBody(FacesContext context,
+ UIComponent component, String facetName) throws IOException {
+
+ UIComponent facet = component.getFacet(facetName);
+ if (facet != null && facet.isRendered()) {
+ return getMarkupScriptBody(context, facet, false);
+ }
+
+ return null;
+ }
+
public void dayCellClass(FacesContext context, UIComponent component)
throws IOException {
// if cellWidth/Height is set send dayCellClass to script
@@ -443,18 +467,31 @@
return null;
}
- public void writeFacetMarkupScriptBody(FacesContext context,
- UIComponent component, String facetName) throws IOException {
+ public void writeFacetMarkup(FacesContext context, UIComponent component) throws
IOException {
+ Map<String, String> jsonMap = new HashMap();
+ if (component.getChildCount() != 0) {
+ jsonMap.put("dayListMarkup", getMarkupScriptBody(context,
component, true));
+ }
- UIComponent facet = component.getFacet(facetName);
- if (facet != null && facet.isRendered()) {
- ResponseWriter writer = context.getResponseWriter();
- writer.writeText(",\n " + facetName + MARKUP_SUFFIX + ": ",
null);
- writeMarkupScriptBody(context, facet, false);
- }
- }
+ addFacetMarkupScriptBody(context, component, jsonMap,
"optionalHeader");
+ addFacetMarkupScriptBody(context, component, jsonMap,
"optionalFooter");
- public void writePreloadBody(FacesContext context, UICalendar calendar)
+ addFacetMarkupScriptBody(context, component, jsonMap, "weekDay");
+ addFacetMarkupScriptBody(context, component, jsonMap, "weekNumber");
+ addFacetMarkupScriptBody(context, component, jsonMap, "header");
+ addFacetMarkupScriptBody(context, component, jsonMap, "footer");
+
+ context.getResponseWriter().write(new JSONObject(jsonMap).toString());
+ }
+
+ private void addFacetMarkupScriptBody(FacesContext context, UIComponent component,
Map<String, String> jsonMap, String facetName) throws IOException {
+ String res = getOptionalFacetMarkupScriptBody(context, component, facetName);
+ if (res != null) {
+ jsonMap.put(facetName, res);
+ }
+ }
+
+ public void writePreloadBody(FacesContext context, UICalendar calendar)
throws IOException {
Object preload = calendar.getPreload();
if (preload != null) {
Modified:
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
---
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2009-11-06
19:18:31 UTC (rev 15851)
+++
branches/sandbox/3.3.X_JSF2/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2009-11-09
08:44:51 UTC (rev 15852)
@@ -193,24 +193,9 @@
</c:if>
<c:if test="#{empty options}">
{}
- </c:if>, {
- <jsp:scriptlet>/*<![CDATA[*/
- if (component.getChildCount() != 0) {
- /*]]>*/</jsp:scriptlet>
- \n dayListMarkup:
- <jsp:scriptlet>/*<![CDATA[*/
- writeMarkupScriptBody(context, component, true);
- }
- /*]]>*/</jsp:scriptlet>
-
- <f:call name="writeOptionalFacetMarkupScriptBody"><f:parameter
value="optionalHeader" /></f:call>
- <f:call name="writeOptionalFacetMarkupScriptBody"><f:parameter
value="optionalFooter" /></f:call>
-
- <f:call name="writeFacetMarkupScriptBody"><f:parameter
value="weekDay" /></f:call>
- <f:call name="writeFacetMarkupScriptBody"><f:parameter
value="weekNumber" /></f:call>
- <f:call name="writeFacetMarkupScriptBody"><f:parameter
value="header" /></f:call>
- <f:call name="writeFacetMarkupScriptBody"><f:parameter
value="footer" /></f:call>
- }).load(
+ </c:if>,
+ <f:call name="writeFacetMarkup" />
+ ).load(
<jsp:scriptlet>/*<![CDATA[*/
writePreloadBody(context, component);
/*]]>*/</jsp:scriptlet>