[
http://issues.apache.org/jira/browse/MYFACES-167?page=comments#action_62361 ]
David R. Heffelfinger commented on MYFACES-167:
-----------------------------------------------
I was able to reproduce this problem using the simple calendar
example distributed with MyFaces. Here is a patch for HtmlCalendarRenderer
that should take care of the problem. Basically what it does is it catches the
IllegalArgumentException thrown by RendererUtils and sets the value of
InputText to whatever value the user entered. A conversion error message is
still displayed when the conversion fails.
David
Index: HtmlCalendarRenderer.java
===================================================================
RCS file:
/home/cvspublic/incubator-myfaces/src/components/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java,v
retrieving revision 1.20
diff -u -r1.20 HtmlCalendarRenderer.java
--- HtmlCalendarRenderer.java 11 Feb 2005 14:11:04 -0000 1.20
+++ HtmlCalendarRenderer.java 7 Apr 2005 13:52:08 -0000
@@ -128,7 +128,18 @@
Locale currentLocale = facesContext.getViewRoot().getLocale();
- Date value = RendererUtils.getDateValue(inputCalendar);
+
+ Date value;
+
+ try
+ {
+ value = RendererUtils.getDateValue(inputCalendar);
+ }
+ catch (IllegalArgumentException illegalArgumentException)
+ {
+ value = null;
+ }
+
Calendar timeKeeper = Calendar.getInstance(currentLocale);
timeKeeper.setTime(value!=null?value:new Date());
@@ -171,8 +182,16 @@
RendererUtils.copyHtmlInputTextAttributes(inputCalendar,
inputText);
inputText.setTransient(true);
- inputText.setValue(getConverter(inputCalendar).getAsString(
- facesContext,inputCalendar,value));
+
+ if (value == null && inputCalendar.getSubmittedValue() != null)
+ {
+ inputText.setValue(inputCalendar.getSubmittedValue());
+ }
+ else
+ {
+ inputText.setValue(getConverter(inputCalendar).getAsString(
+ facesContext,inputCalendar,value));
+ }
inputText.setEnabledOnUserRole(inputCalendar.getEnabledOnUserRole());
inputText.setVisibleOnUserRole(inputCalendar.getVisibleOnUserRole());
> x:inputCalendar and conversion/validation errors
> ------------------------------------------------
>
> Key: MYFACES-167
> URL: http://issues.apache.org/jira/browse/MYFACES-167
> Project: MyFaces
> Type: Bug
> Environment: Any
> Reporter: Enrique Medina Montenegro
>
> I'm using the MyFaces tag named x:inputCalendar in order to let the
> user select a date from a popup calendar or enter it directly. If the
> user enters a valid date, everything goes perfect.
> The problem comes when the user enters something wrong, for example
> letters. The component tries to convert this value to a valid date
> (following the pattern, if there is one), and then throws a
> ConvertException exception, so the Apply Request Values phase returns
> false, and LifeCycle jumps to the render phase.
> When rendering, the component is asked to encode itself, so the
> following code is executed:
> public void encodeEnd(FacesContext facesContext, UIComponent
> component) throws IOException
> {
> RendererUtils.checkParamValidity(facesContext, component,
> HtmlInputCalendar.class);
> HtmlInputCalendar inputCalendar = (HtmlInputCalendar) component;
> Locale currentLocale = facesContext.getViewRoot().getLocale();
> Date value = RendererUtils.getDateValue(inputCalendar);
> ....
> }
> As you can see, the last visible line of this code is:
> Date value = RendererUtils.getDateValue(inputCalendar);
> so it forces the actual value of the inputCalendar to be a date. And
> as obviously we come from a conversion error and that means the value
> is not a valid date, the RendererUtils.getDateValue(inputCalendar)
> throws:
> throw new IllegalArgumentException(
> "Expected submitted value of type Date for
> component : "+
> getPathToComponent(component));
> so this exception results in a ServletException that brings up the
> undesirable "full of Java trace annoying text" page to the user.
> I was wondering why the encondeEnd of this component forces the value
> to be obtained to be a date, when anything can be entered in a input
> text box.
> I've been looking at the common h:inputText tag and its component
> always uses the RenderUtils.getStringValue method from its encodeEnd
> method, so if a conversion/validation error has been detected, it is
> presented to the user using the friendly mechanism of a FacesMessage
> and the well-known messages tags.
> So I think this could be a bug as no validation can be done at all!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira