New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker: PartialResponseError submitting multiple values #4471

Closed
melloware opened this Issue Jan 24, 2019 · 19 comments

Comments

Projects
None yet
3 participants
@melloware
Copy link
Contributor

melloware commented Jan 24, 2019

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)
@mertsincan

This comment has been minimized.

Copy link
Member

mertsincan commented Jan 24, 2019

Does it work without immediate attribute on datepicker?

@mertsincan mertsincan self-assigned this Jan 24, 2019

@melloware

This comment has been minimized.

Copy link
Contributor Author

melloware commented Jan 24, 2019

So with immediate=false the error goes away but the values are not accepted and and the multi-calendar dissapears and I get this in the JavaScript Console:

Uncaught TypeError: this.viewDate.getMonth is not a function
    at $.(anonymous function).(anonymous function).renderDateView (http://localhost:8080/primefaces-test/javax.faces.resource/datepicker/datepicker.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:980:67)
    at $.(anonymous function).(anonymous function).renderDateView (http://localhost:8080/primefaces-test/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:144:25)
    at $.(anonymous function).(anonymous function).renderPanelElements (http://localhost:8080/primefaces-test/javax.faces.resource/datepicker/datepicker.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:961:42)
    at $.(anonymous function).(anonymous function).renderPanelElements (http://localhost:8080/primefaces-test/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:144:25)
    at $.(anonymous function).(anonymous function).renderDatePickerPanel (http://localhost:8080/primefaces-test/javax.faces.resource/datepicker/datepicker.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:953:48)
    at $.(anonymous function).(anonymous function).renderDatePickerPanel (http://localhost:8080/primefaces-test/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:144:25)
    at $.(anonymous function).(anonymous function)._render (http://localhost:8080/primefaces-test/javax.faces.resource/datepicker/datepicker.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:893:18)
    at $.(anonymous function).(anonymous function)._render (http://localhost:8080/primefaces-test/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:144:25)
    at $.(anonymous function).(anonymous function)._create (http://localhost:8080/primefaces-test/javax.faces.resource/datepicker/datepicker.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:113:18)
    at $.(anonymous function).(anonymous function)._create (http://localhost:8080/primefaces-test/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=7.0-SNAPSHOT:144:25)

image

The other poster said he had to use this crazy hack to make it work:

image

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 24, 2019

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);
	}
@mertsincan

This comment has been minimized.

Copy link
Member

mertsincan commented Jan 25, 2019

@melloware, the second issue(JS error) is fixed. Could you please test it?

@melloware

This comment has been minimized.

Copy link
Contributor Author

melloware commented Jan 25, 2019

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

@mertsincan

This comment has been minimized.

Copy link
Member

mertsincan commented Jan 25, 2019

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

@mertsincan mertsincan added the 6.2.16 label Jan 25, 2019

@mertsincan mertsincan added this to the 7.0 milestone Jan 25, 2019

@melloware

This comment has been minimized.

Copy link
Contributor Author

melloware commented Jan 25, 2019

@mertsincan So far the fixes look good. But @GedMarc has been heavily using this component so I will wait until he confirms as well.

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

Perhaps my repo is out of date?
Can you confirm the dependency for me please?

  <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

      <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>7.0.RC1</version>
        </dependency>

We have this widget in production ;) We were forced by business to push it in on the day of 6.2.14 release ;)

@melloware

This comment has been minimized.

Copy link
Contributor Author

melloware commented Jan 25, 2019

@GedMarc I think you can do this...

<dependency>
     <groupId>com.github.primefaces</groupId>
     <artifactId>primefaces</artifactId>
     <version>master-SNAPSHOT</version>
 </dependency>

I am not quite sure how jitpack works. If not if you git clone PF here you can do "mvn clean install" to build 7.0-SNAPSHOT locally.

It looks like JitPack will then force a build of the latest code if you use the above! So cool.

mertsincan added a commit that referenced this issue Jan 25, 2019

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

Getting much closer!

Caused by: javax.el.PropertyNotWritableException: /test.xhtml @43,141 value="#{testView.multidate}": Property [multidate] not writable on type [org.primefaces.test.TestView]
        at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
        at javax.faces.component.UIInput.updateModel(UIInput.java:834)
        ... 44 more

I double checked the getters/setters, looks ok to me, maybe just a sanity check on my stuff? I haven't done the best this week

pfdatepicker.zip

@melloware

This comment has been minimized.

Copy link
Contributor Author

melloware commented Jan 25, 2019

@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.

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

Ah yes I do the CRP builders, not the best week xD

@mertsincan

This comment has been minimized.

Copy link
Member

mertsincan commented Jan 25, 2019

@melloware, you are so fast 😄

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

Standard Inline & Normal & Immediate- Pass
Immediate Inline & Normal & Immediate - Pass
Locale Inline & Normal & Immediate - Pass

Restricted Dates inline & Normal & Immediate - Fail
Time Zoned Dates Inline & Normal & Immediate - Fail


Outside @Form Not Updated - Pass
Inside @Form Updated - Pass

I see you guys don't do "broken components", but "bug in components" logging - Should this get logged as new for minDate not taking effect (popup doesn't work, calendar doesn't display)

In the test, all inputs after the millenium calendar pre populate don't function

pfdatepicker.zip

image

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

Also looks like immediate=false without multiple doesn't function (date4 and after)
But this is really getting much better

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

crap wrong issue

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

no right issue xD

@melloware

This comment has been minimized.

Copy link
Contributor Author

melloware commented Jan 25, 2019

@GedMarc I would open a new issue one for each issue you have. That way they get tracked as individual issues and not in one big bucket. As small a reproducible test case for each just showing the issue.

@GedMarc

This comment has been minimized.

Copy link

GedMarc commented Jan 25, 2019

Then for this bug, this is complete

Thanks guys! See you on the next issue thread!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment