question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DatePicker: pattern messed with LocalDateTime and showTime="true"

See original GitHub issue

1) Environment

  • PrimeFaces version: trunk
  • Application server + version: jetty 9.20
  • Affected browsers: all

2) Expected behavior

The user-provided pattern is not modified.

3) Actual behavior

HH:mm is added to the pattern, causing conversion errors.

4) Steps to reproduce

5) Sample XHTML

<h:form>
	<div>
		<p:outputLabel for="date1" value="Date1" style="display: inline-block; width: 120px;"/>
		<p:datePicker id="date1" value="#{testViewCdi.date1}" showTime="true"/>
		<p:message for="date1"/>
	</div>
	<div>
		<p:outputLabel for="date2" value="Date2" style="display: inline-block; width: 120px;"/>
		<p:datePicker id="date2" value="#{testViewCdi.date2}" showTime="true" pattern="dd/MM/yy HH:mm"/>
		<p:message for="date2"/>
	</div>
	<div>
		<p:outputLabel for="date3" value="Date3" style="display: inline-block; width: 120px;"/>
		<p:datePicker id="date3" value="#{testViewCdi.date3}"/>
		<p:message for="date3"/>
	</div>
	<div>
		<p:outputLabel for="date4" value="Date4" style="display: inline-block; width: 120px;"/>
		<p:datePicker id="date4" value="#{testViewCdi.date4}" pattern="dd/MM/yy"/>
		<p:message for="date4"/>
	</div>
	<p:commandButton id="sub" value="submit" update="@form"/>
</h:form>

6) Sample bean

@Named
@ViewScoped
public class TestViewCdi implements java.io.Serializable {

	private java.time.LocalDateTime date1 = java.time.LocalDateTime.now();

	private java.time.LocalDateTime date2 = java.time.LocalDateTime.now();

	private java.time.LocalDateTime date3 = java.time.LocalDateTime.now();

	private java.time.LocalDateTime date4 = java.time.LocalDateTime.now();

	// getters and setters
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
NicolaIsottacommented, Sep 25, 2019

IMHO the easiest and best solution is the server-side only:

  1. If the user provides a pattern and if the pattern contains a time part, remove the part
  2. This “cleaned” pattern will be passed by the widget builder
  3. if showTime is true, generate a time pattern from the datepicker attributes (hourFormat and showSeconds)
  4. Combine the “clean” pattern and the generated time pattern to create a “full” pattern. This one will be used to convert the value
0reactions
NicolaIsottacommented, Nov 7, 2019

PR: #5313

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with passing LocalDateTime data using Kendo api ...
I'm using a kendo date picker in a jsp binded form (using spring + ... STRING) private Cause cause; @DateTimeFormat(pattern="MM.dd.yyyy ...
Read more >
Unable to input 12 hour format LocalDateTime in calendar o ...
I'm having some issues with calendar on capturing LocalDateTime in twelve hour format like this: <p:calendar id="popupCalendar" ...
Read more >
Datetime advance format in datepicker - OutSystems
Hi. I want to enable time in date picker control.but show time option is not available there.i saw the outsystems documentation.advanced format one...
Read more >
DatePicker (JavaFX 8) - Oracle Help Center
public class DatePicker extends ComboBoxBase<LocalDate> ... setConverter(new StringConverter<LocalDate>() { String pattern = "yyyy-MM-dd"; DateTimeFormatter ...
Read more >
<input type="datetime-local"> - HTML - MDN Web Docs
The format of the date and time value used by this input type is ... and dates outside June can't be scrolled to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found