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.

Documentation: how to set a default parameter for all components of same type

See original GitHub issue

1) Environment

  • PrimeFaces version: 8.0
  • Application server + version: jetty (primefaces-test project)

2) Expected behavior

If I select 23/04/2020, that should be the date submitted.

3) Actual behavior

However, the value submitted is 23/04/0020.

4) Steps to reproduce

Set locale to pt_BR, create a LocalDate variable and use it in a Calendar or DatePicker component.

5) Patch to reproduce the error with https://github.com/primefaces/primefaces-test:

Index: src/main/java/org/primefaces/test/TestView.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/org/primefaces/test/TestView.java	(revision 0fca0e2a9c3a808e29f69aa5bb8071b189eb004c)
+++ src/main/java/org/primefaces/test/TestView.java	(date 1587677612246)
@@ -1,26 +1,40 @@
 package org.primefaces.test;
 
-import java.io.Serializable;
 import javax.annotation.PostConstruct;
 import javax.faces.view.ViewScoped;
 import javax.inject.Named;
+import java.io.Serializable;
+import java.time.LocalDate;
 
 @Named
 @ViewScoped
 public class TestView implements Serializable {
     
     private String testString;
+    private LocalDate datInicio;
     
     @PostConstruct  
     public void init() {
         testString = "Welcome to PrimeFaces!!!";
     }
 
+    public void salvar(){
+        System.out.println(datInicio);
+    }
+
     public String getTestString() {
         return testString;
     }
 
     public void setTestString(String testString) {
         this.testString = testString;
-    }    
+    }
+
+    public LocalDate getDatInicio() {
+        return datInicio;
+    }
+
+    public void setDatInicio(LocalDate datInicio) {
+        this.datInicio = datInicio;
+    }
 }
Index: src/main/webapp/WEB-INF/faces-config.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/webapp/WEB-INF/faces-config.xml	(revision 0fca0e2a9c3a808e29f69aa5bb8071b189eb004c)
+++ src/main/webapp/WEB-INF/faces-config.xml	(date 1587676972305)
@@ -4,6 +4,10 @@
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
     <application>
+        <locale-config>
+            <default-locale>pt_BR</default-locale>
+            <supported-locale>pt_BR</supported-locale>
+        </locale-config>
         <action-listener>org.primefaces.application.DialogActionListener</action-listener>
         <navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
         <view-handler>org.primefaces.application.DialogViewHandler</view-handler>
Index: src/main/webapp/test.xhtml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/webapp/test.xhtml	(revision 0fca0e2a9c3a808e29f69aa5bb8071b189eb004c)
+++ src/main/webapp/test.xhtml	(date 1587677860655)
@@ -5,12 +5,14 @@
       xmlns:p="http://primefaces.org/ui"
       xmlns:h="http://java.sun.com/jsf/html">
 
-    <h:head>
-        <title>PrimeFaces Test</title>
-    </h:head>
-    <h:body>
-
+<h:head>
+    <title>PrimeFaces Test</title>
+</h:head>
+<h:body>
+    <h:form prependId="false">
         <h1>#{testView.testString}</h1>
-
-    </h:body>
+        <p:calendar value="#{testView.datInicio}" pattern="dd/MM/yy"/>
+        <p:commandButton value="Salvar" action="#{testView.salvar}"/>
+    </h:form>
+</h:body>
 </html>
\ No newline at end of file

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
tandraschkocommented, Apr 27, 2020

we had a issue for creating a mechanism to allow default values, configured globbaly in the application for each attribute for each component thats a better way to go

2reactions
mellowarecommented, Apr 24, 2020

@hfluz that is not a bad idea. Somthing like…

	<context-param>  
		<param-name>primefaces.DEFAULT_DATE_PATTERN</param-name>  
		<param-value>dd/MM/yy</param-value>  
	</context-param>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
Understanding Default Parameters in JavaScript - DigitalOcean
Default Parameter Data Types ... Any primitive value or object can be used as a default parameter value. In this section, you will...
Read more >
Describing Parameters - Swagger
Default Parameter Values. Use the default keyword in the parameter schema to specify the default value for an optional parameter. The default value...
Read more >
Set a default parameter value for a JavaScript function
Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed. In ES6, you can...
Read more >
Creating parameter defaults in Amazon QuickSight
The simplest default is a static (unchanging) default, which shows the same value to everyone. As the designer of the dashboard, you choose...
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