Calendar IllegalArgumentException

UI Components for JSF
Post Reply
3man
Posts: 99
Joined: 16 Jun 2011, 16:13

20 May 2012, 13:49

Bug in CalendarUtils.java(line 41. function getValueAsString)

I added one more function isValueParsableAsDate

Code: Select all

    public static boolean isValueParsableAsDate(FacesContext context, Calendar calendar, Object value) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(calendar.calculatePattern(), calendar.calculateLocale(context));
        try {
            dateFormat.format(value);
        } catch (IllegalArgumentException ex) {
            return false;
        }

        return true;
    }
and change function getValueAsString from :

Code: Select all

public static String getValueAsString(FacesContext context, Calendar calendar) {
		Object submittedValue = calendar.getSubmittedValue();
		if(submittedValue != null) {
			return submittedValue.toString();
		}
		
		Object value = calendar.getValue();
		if(value == null) {
			return null;
		} else {
			//first ask the converter
			if(calendar.getConverter() != null) {
				return calendar.getConverter().getAsString(context, calendar, value);
			}
			//Use built-in converter
			else {
				SimpleDateFormat dateFormat = new SimpleDateFormat(calendar.calculatePattern(), calendar.calculateLocale(context));
				dateFormat.setTimeZone(calendar.calculateTimeZone());
				
				return dateFormat.format(value);
			}
		}
	}
to

Code: Select all

    public static String getValueAsString(FacesContext context, Calendar calendar) {
        Object submittedValue = calendar.getSubmittedValue();
        if (submittedValue != null) {
            return submittedValue.toString();
        }

        Object value = calendar.getValue();
        if (value == null) {
            return null;
        } else {
            //first ask the converter
            if (calendar.getConverter() != null) {
                return calendar.getConverter().getAsString(context, calendar, value);
            } //Use built-in converter
            else {
                SimpleDateFormat dateFormat = new SimpleDateFormat(calendar.calculatePattern(), calendar.calculateLocale(context));
                dateFormat.setTimeZone(calendar.calculateTimeZone());

                if (!isValueParsableAsDate(context, calendar, value)) {
                    return null;
                }

                return dateFormat.format(value);
            }
        }
    }
@PF admins, if U find this code usefull, u can implemented in pf jar.
-----------
primefaces-3.3-SNAPSHOT
tomcat 7.0.22
Mojarra 2.1.1 (FCS 20110408)
NetBeans 7.1

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

21 May 2012, 18:07

Create a new issue in issue tracker, refer to this forum topic URL in the new issue, and provide simple test case (xhtml, bean, test environment details, browser version/details etc, steps necessary to duplicate issue/defect) that allows Cagatay and PrimeFaces team to duplicate the issue, and your recommended solution in the new issue (unless you want to refer to this forum topic for the code/fix you provided here), and reply here with the new issue # and URL.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

3man
Posts: 99
Joined: 16 Jun 2011, 16:13

21 May 2012, 19:10

-----------
primefaces-3.3-SNAPSHOT
tomcat 7.0.22
Mojarra 2.1.1 (FCS 20110408)
NetBeans 7.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests