What to do when Cannot format given Object as a Date in convertDateTime of JSF

--Environment --Windows10 64bit version 1909 - penjdk 11 2018-09-25 - Eclipse IDE for Enterprise Java Developers Version: 2020-03 (4.15.0) - JSF 2.3.9

2020-07-20 09:49:54:387 X-TrackingId:6079d04e-6554-492e-b2be-e01eed06        ERROR   MyExceptionHandler.handle:63 Cannot format given Object as a Date
java.lang.IllegalArgumentException: Cannot format given Object as a Date
        at java.base/java.text.DateFormat.format(DateFormat.java:338)
        at java.base/java.text.Format.format(Format.java:158)
        at javax.faces.convert.DateTimeConverter$FormatWrapper.format(DateTimeConverter.java:495)
        at javax.faces.convert.DateTimeConverter$FormatWrapper.access$300(DateTimeConverter.java:470)
        at javax.faces.convert.DateTimeConverter.getAsString(DateTimeConverter.java:544)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:491)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:509)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:330)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:143)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:595)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1654)
        at com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:64)
        at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:559)
        at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:1068)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:278)
        at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:90)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:566)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1647)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:152)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:566)
  <h:outputText value="#{bean.myTimestamp}" >
     <f:convertDateTime pattern="yyyy/MM/dd HH:mm" timeZone="Japan" />
  </h:outputText>

Cause: Because the date to be converted is LocalDateTime

    bean.setMyTimestamp(LocalDateTime.now());

Correspondence: Specify "localDateTime" for type

Specifies what contents the string value will be formatted to include, or parsed expecting. Valid values are "date", "time", "both", "localDate", "localDateTime", "localTime", "offsetTime", "offsetDateTime", and "zonedDateTime". convertDateTime (JSF 2.3 View Declaration Language: Facelets Variant, generated with VDLDoc.)

This will work


  <h:outputText value="#{bean.myTimestamp}" >
     <f:convertDateTime pattern="yyyy/MM/dd HH:mm" timeZone="Japan" type="localDateTime" />
  </h:outputText>

I'm worried about something ... image.png

Other correspondence

I haven't done it but for someday

--Create your own Converter - java - f:convertDateTime support for Java8 LocalDate / LocalDateTime? - Stack Overflow --Convert LocalDateTime to Date and use -Mutual conversion between Java8 Local Date Time and old Date --Easy and fun to play with the program --Stop using LocalDateTime (close up in the old world)

Recommended Posts

What to do when Cannot format given Object as a Date in convertDateTime of JSF
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
How to output a list of strings in JSF as comma-separated strings
What to do when a javax.el.PropertyNotWritableException occurs
How to get the current date as a string in yyyyMMdd format
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do when IllegalStateException occurs in PlayFramework
What to do when the value becomes null in the second getSubmittedValue () in JSF Validator
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
What to do when JSF tags do not become HTML
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
ParseException: What to do when Unparseable date is reached
[React.useRef] What to do when the latest state cannot be referenced in the event listener
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get a java.io.IOException in GlassFish
What to do when Method not found in f: ajax
What to do when Git Repository cannot be displayed in Team Explorer for Eclipse in Azure
[Ruby / Rails] What to do when NoMethodError appears when using a destructive method such as filter!
What to do when a could not find driver appears when connecting to a DB in a Docker environment
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do when Cannot apply expression operators to method binding
What to do when "relation" hibernate_sequence "does not exist" in the ID column of PostgreSQL + JPA
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do when javax.batch.operations.JobStartException occurs
What to do if Operation not permitted is displayed when you execute a command in the terminal
I tried to make a parent class of a value object in Ruby
What to do if you get a groovy warning in Thymeleaf Layout
What to do when CentOS cannot be started with VirtualBox on Catalina
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
What to do if Command line is too long appears when building a gradle project in Intellij IDEA
What to do when undefined method ʻuser_signed_in?'
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What I tried when I wanted to get all the fields of a bean
Androd: What to do about "The Realm is already in a write transaction in"
What to do when is invalid because it does not start with a'-'
What to do if ffi installation fails when launching an application in Rails
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
What a beginner did to understand Object Orientation
What to do when debugging "Source not found"
What do you use when converting to String?
What to do if you can't get the text of an element in Selenium
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
What to do when Address already in use is displayed after executing rails s
What to do if you get a port error when docker-compose up on Mac
What Android, Kotlin beginners did in a month and what they were able to do
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
I tried to explain what you can do in a popular language for web development from a beginner's point of view.