I would like to speed up localDate input and allow the user the enter a date without separators.
The facelet is :
<p:datePicker id="startDate" value="#{ordreComptablesView.startDate}" />
and startDate is a LocalDate.
Currently the user enters a date like this : 31/12/2023
It would be nice to be able to enter the date also like this : 31122023
At the end the display value is still 31/12/2023
Is it "simple" to do ? Could you make it available in the future ?
I use PF 12
DatePicker (Java 8+) : entering localDate without separator
Did you try to create a converter?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House
PF 13.0.0--Jakarta. Jakarta Faces 4.0.1/Kotlin Multiplatform 1.9.10
Mojarra 4.0.2, OmniFaces 4.2
WildFly 29.0.1.Final 'preview' Jakarta EE 10.0.0
JDK 20.0.2, Kotlin 1.9.10, Gradle 8.3 Groovy DSL, MongoDB 7.0.0
IntelliJ IDEA 2023.2.1, macOS Ventura 13.5.1
Mojarra 4.0.2, OmniFaces 4.2
WildFly 29.0.1.Final 'preview' Jakarta EE 10.0.0
JDK 20.0.2, Kotlin 1.9.10, Gradle 8.3 Groovy DSL, MongoDB 7.0.0
IntelliJ IDEA 2023.2.1, macOS Ventura 13.5.1
I'm not sure if Omnifaces dates function can be useful.
A converter might be the solution. I tried to extend org.primefaces.convert.DateTimeConverter but for some reason it is not called.
As I have disabled the datePicker popup (showOnFocus = "false") I could use JSF "h:inputText" with "f:convertDateTime" but then the "look" of the component is not good.
A converter might be the solution. I tried to extend org.primefaces.convert.DateTimeConverter but for some reason it is not called.
As I have disabled the datePicker popup (showOnFocus = "false") I could use JSF "h:inputText" with "f:convertDateTime" but then the "look" of the component is not good.
Here is my solution with converter. It would be great if such a nice feature appears in PrimeFaces
The converter :
In faces-config.xml :
Code: Select all
<p:datePicker autocomplete="off" showOnFocus="false" id="dateGestion" value="#{cc.attrs.program.record.dateGestion}" >
<f:convertDateTime type="localDate" dateStyle="short" />
<f:ajax event="blur" render="@this" />
</p:datePicker>
Code: Select all
public class DateTimeConverter extends org.primefaces.convert.DateTimeConverter {
private static final Pattern PAT = Pattern.compile("[^a-zA-Z]");
private static final Pattern PATD = Pattern.compile("\\d+");
@Override
public Object getAsObject(FacesContext context, DatePicker datePicker, String value) {
try {
String pattern = datePicker.calculatePattern();
if(PATD.matcher(value).matches()) {
String apattern = PAT.matcher(pattern).replaceAll("");
var formatter = DateTimeFormatter.ofPattern(apattern);
LocalDate date = LocalDate.parse(value, formatter);
return date;
}
} catch(Exception e) {}
return super.getAsObject(context, datePicker, value);
}
}
Code: Select all
<converter>
<converter-id>javax.faces.DateTime</converter-id>
<converter-class>gbt.view.converter.DateTimeConverter</converter-class>
</converter>
I always create custom tags for each input (sub) type. That way it's easy to do stuff like that globally.
In your case global attributes might help. https://primefaces.github.io/primefaces ... attributes
In your case global attributes might help. https://primefaces.github.io/primefaces ... attributes
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House
That's right a custom tag might be interesting.
"Global Attributes" is a very interesting feature. Thanks for the tip.
@jepsar : you suggested somewhere else to use the mask in the datePicker. Thanks, it does what I want : fast input.
So I don't need my custom converter anymore.
"Global Attributes" is a very interesting feature. Thanks for the tip.
@jepsar : you suggested somewhere else to use the mask in the datePicker. Thanks, it does what I want : fast input.
So I don't need my custom converter anymore.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 7 guests