primefaces: DatePicker: PartialResponseError submitting multiple values

Here is a test case:
pf-4470.zip

Run the sample and then select a few dates from the multiple Calendar and press the “All” button.

You will get this stack trace:

Jan 24, 2019 7:41:10 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/test.xhtml]
javax.faces.FacesException: Value could be either String or java.util.Date
        at org.primefaces.util.CalendarUtils.getValueAsString(CalendarUtils.java:136)
        at org.primefaces.util.CalendarUtils.getValueAsString(CalendarUtils.java:55)
        at org.primefaces.component.calendar.BaseCalendarRenderer.encodeEnd(BaseCalendarRenderer.java:58)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
        at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:583)
        at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
        at javax.faces.component.UIForm.visitTree(UIForm.java:381)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

@GedMarc I had to fix this in your code to be bean compliant like this…

	/**
	 * Setter for property 'multi'.
	 *
	 * @param multi Value to set for property 'multi'.
	 */
	public void setMulti(List<Date> multi)
	{
		this.multi = multi;
	}

You were returning testView instead of a void method.

Then for this bug, this is complete

Thanks guys! See you on the next issue thread!

Thanks a lot, @melloware 😉 Original issue is fixed now. Could @melloware and @GedMarc please test it?

@mertsincan I have confirmed the JS error is no longer displaying if immediate=“false” in this scenario.

On value setting also found encodeEnd() didn’t handle properly for no value selected with immediate=true, had to wrap.

@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
		UICalendar uicalendar = (UICalendar)component;
		String markupValue = "";
		Object submittedValue = uicalendar.getSubmittedValue();

		if(submittedValue == null)
			submittedValue = "";

		ValueExpression ve = uicalendar.getValueExpression("value");
		if (ve != null) {
			Class type = ve.getType(context.getELContext());
			if(type == ArrayList.class) {
				submittedValue = ve.getValue(context.getELContext()).toString();
				markupValue = submittedValue.toString().substring(1, submittedValue.toString().length() - 1);
			}
		}
		else
		{
			try {
				markupValue = CalendarUtils.getValueAsString(context, uicalendar);
			}catch(Exception e)
			{
				Logger.getLogger("DatePickerRenderer").warning("No value bound to this calendar");
			}
		}
		String widgetValue = uicalendar.isTimeOnly() ? CalendarUtils.getTimeOnlyValueAsString(context, uicalendar) : markupValue;

		this.encodeMarkup(context, uicalendar, markupValue);
		this.encodeScript(context, uicalendar, widgetValue);
	}