[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui ...
Shane Bryzak
sbryzak at redhat.com
Tue Mar 13 09:13:19 EDT 2007
User: sbryzak2
Date: 07/03/13 09:13:19
Modified: src/ui/org/jboss/seam/ui UISelectDate.java
Log:
JBSEAM-928
Revision Changes Path
1.3 +146 -92 jboss-seam/src/ui/org/jboss/seam/ui/UISelectDate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UISelectDate.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/UISelectDate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UISelectDate.java 4 Mar 2007 08:48:59 -0000 1.2
+++ UISelectDate.java 13 Mar 2007 13:13:19 -0000 1.3
@@ -1,50 +1,87 @@
package org.jboss.seam.ui;
+
import java.io.IOException;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
+
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;
+
import org.jboss.seam.ui.resource.WebResource;
+
public class UISelectDate extends UIComponentBase
{
public static final String COMPONENT_TYPE = "org.jboss.seam.ui.UISelectDate";
+
public static final String COMPONENT_FAMILY = "org.jboss.seam.ui.SelectDate";
+
private String forField;
+
private String dateFormat = "MM/dd/yyyy";
+ private int startYear = -1;
+
+ private int endYear = -1;
+
public String getDateFormat()
{
ValueBinding vb = getValueBinding("dateFormat");
return (vb != null) ? JSF.getStringValue(getFacesContext(), vb) : dateFormat;
}
+
public void setDateFormat(String dateFormat)
{
this.dateFormat = dateFormat;
}
+
public String getFor()
{
ValueBinding vb = getValueBinding("for");
return (vb != null) ? JSF.getStringValue(getFacesContext(), vb) : forField;
}
+
public void setFor(String forField)
{
this.forField = forField;
}
+
+ public int getStartYear()
+ {
+ return startYear;
+ }
+
+ public void setStartYear(int startYear)
+ {
+ this.startYear = startYear;
+ }
+
+ public int getEndYear()
+ {
+ return endYear;
+ }
+
+ public void setEndYear(int endYear)
+ {
+ this.endYear = endYear;
+ }
+
@Override
public String getFamily()
{
return COMPONENT_FAMILY;
}
+
@Override
public boolean getRendersChildren()
{
return false;
}
+
@Override
public void restoreState(FacesContext context, Object state)
{
@@ -53,6 +90,7 @@
forField = (String) values[1];
dateFormat = (String) values[2];
}
+
@Override
public Object saveState(FacesContext context)
{
@@ -70,11 +108,10 @@
writeScript(context);
ResponseWriter response = context.getResponseWriter();
response.startElement("span", this);
- response.writeAttribute("onclick",
- "__selectDate('" + forComponent.getClientId(context) +
- "', '" + forComponent.getClientId(context) + "');",
- null);
+ response.writeAttribute("onclick", "__selectDate('" + forComponent.getClientId(context)
+ + "', '" + forComponent.getClientId(context) + "');", null);
}
+
@Override
public void encodeEnd(FacesContext context) throws IOException
{
@@ -83,11 +120,12 @@
response.flush();
super.encodeEnd(context);
}
- public void writeScript(FacesContext context)
- throws IOException
+
+ public void writeScript(FacesContext context) throws IOException
{
Map request = context.getExternalContext().getRequestMap();
- if (request.get("SELECTDATE_SCRIPT") != null) {
+ if (request.get("SELECTDATE_SCRIPT") != null)
+ {
// already written out
return;
}
@@ -99,12 +137,12 @@
response.startElement("script", null);
response.writeAttribute("type", "text/javascript", null);
- response.writeAttribute("src", context.getExternalContext().getRequestContextPath() +
- WebResource.WEB_RESOURCE_PATH + "/date/calendar.js", null);
+ response.writeAttribute("src", context.getExternalContext().getRequestContextPath()
+ + WebResource.WEB_RESOURCE_PATH + "/date/calendar.js", null);
response.endElement("script");
}
- private void writeLocaleInformation(ResponseWriter response,
- Locale locale) throws IOException
+
+ private void writeLocaleInformation(ResponseWriter response, Locale locale) throws IOException
{
response.startElement("script", null);
response.writeAttribute("type", "text/javascript", null);
@@ -115,16 +153,28 @@
// Note: Calendar and DateFormatSymbols use 1 for the first day of the week, not 0.
response.write("\r");
- response.write("var CAL_DAYS_SHORT = '" + commaSeparate(symbols.getShortWeekdays(), 2) + "';\r");
- response.write("var CAL_DAYS_MEDIUM = '" + commaSeparate(symbols.getShortWeekdays()) + "';\r");
+ response.write("var CAL_DAYS_SHORT = '" + commaSeparate(symbols.getShortWeekdays(), 2)
+ + "';\r");
+ response
+ .write("var CAL_DAYS_MEDIUM = '" + commaSeparate(symbols.getShortWeekdays())
+ + "';\r");
response.write("var CAL_DAYS_LONG = '" + commaSeparate(symbols.getWeekdays()) + "';\r");
- response.write("var CAL_MONTHS_MEDIUM = '" + commaSeparate(symbols.getShortMonths()) + "';\r");
+ response
+ .write("var CAL_MONTHS_MEDIUM = '" + commaSeparate(symbols.getShortMonths())
+ + "';\r");
response.write("var CAL_MONTHS_LONG = '" + commaSeparate(symbols.getMonths()) + "';\r");
response.write("var CAL_FIRST_DAY_OF_WEEK = " + (cal.getFirstDayOfWeek() - 1) + ";\r");
response.write("var CAL_DATE_FORMAT = '" + getDateFormat() + "';\r");
+ if (startYear != -1 && endYear != -1)
+ {
+ response.write("var CAL_START_YEAR = " + startYear + ";\r");
+ response.write("var CAL_END_YEAR = " + endYear + ";\r");
+ }
+
response.endElement("script");
}
+
private String commaSeparate(String[] values)
{
return commaSeparate(values, -1);
@@ -138,17 +188,21 @@
if (!"".equals(val))
{
if (sb.length() > 0) sb.append(',');
- sb.append(limitLength(val,maxLength));
+ sb.append(limitLength(val, maxLength));
}
}
return sb.toString();
}
- private String limitLength(String source, int maxLength) {
- if (maxLength < 0 || maxLength > source.length()) {
+ private String limitLength(String source, int maxLength)
+ {
+ if (maxLength < 0 || maxLength > source.length())
+ {
return source;
- } else {
- return source.substring(0,maxLength);
+ }
+ else
+ {
+ return source.substring(0, maxLength);
}
}
}
More information about the jboss-cvs-commits
mailing list