jsf 2 glassfish 4 primefaces 5.1
i am using the f:convertDateTime to convert the way date is shown but its showing the wrong date.
when i normally show the date it shows
Sat Jan 01 00:00:00 AST 2011
which is correct but its not what i want to show
so i am using <f:convertDateTime dateStyle="short"></f:convertDateTime> but instead of showing
01/01/11
its giving me
31/12/10
i tried using <f:convertDateTime pattern="MM/dd/yyyy"></f:convertDateTime> but that also gives me
12/31/2010
instead of
01/01/2011
<p:column headerText="Installation Date"
filterBy="#{w.installationDate}"
filterMatchMode="contains"
sortBy="#{w.installationDate}">
<h:outputText value="#{w.installationDate}" >
<f:convertDateTime pattern="MM/dd/yyyy"></f:convertDateTime>
</h:outputText>
</p:column>
Try adding this to your web.xml
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
Related
Good day
I need to display the delta time as the difference between two java.date.Util instances in the format 'HH:mm:ss'
The Omnifaces library seems very handy in calculating the amount of seconds difference between these two java.date.Util instances that will always be on the same day.
The one value is set using a Primefaces calendar component at the top of the .xhtml file like this:
<p:outputLabel for="datetime" value="Marathon Race Start: "/>
<p:calendar id="datetime" value="#{resultsView.marathonStart}" pattern="yyyy/MM/dd HH:mm:ss">
<p:ajax event="change" immediate="true" update="marathon_results_form:results_all_datatable"/>
</p:calendar>
And then the results are displayed in a Primefaces dataTable like below (only the time column shown as all other columns works correct):
<p:column headerText="Time - Completed" style="text-align: center; align-content: left">
<c:set var="raceTime" value="#{of:secondsBetween(resultsView.marathonStart,allResults.dateTimeStamp)}"/>
#{of:formatDate(raceTime, 'HH:mm:ss')}
</p:column>
The above snippet throws a runtime error stating:
cannot convert of type class java.lang.Long to class java.util.Date
If I remove the Omnifaces:
#{of:formatDate(raceTime, 'HH:mm:ss')}
And replace with only:
#{raceTime}
Converting the whole column then to:
<p:column headerText="Time - Completed" style="text-align: center; align-content: left">
<c:set var="raceTime" value="#{of:secondsBetween(resultsView.marathonStart,allResults.dateTimeStamp)}"/>
#{raceTime}
</p:column>
It indeed works correctly by showing the amount of seconds as a long in the table column; and as soon as the start time is updated via the Primefaces calendar, the amount of seconds as a long updates in real time in the table; exactly as it should.
So then, how can I in the EL (using JSF 2.3.5.SP1 on WildFly 15) convert those longs to the 'HH:mm:ss' format?
EDIT:
I know this can be easily done by passing the long raceTime to a managed bean's method and get a string back from the bean; however, if this can be done more concisely via EL or Omnifaces I would rather follow that approach.
According to the of:formatDate it expects a java.util.Date and not a java.lang.Long, so the classcast is to be expected since the return value of of:secondsBetween is not a java.util.Date.
So what you experience is totally as expected. See the 'See also' for a possible fix, but doing it in a backing bean is not wrong either (not not less consice imo). In addition you can also write your own EL function, not too difficul
See also
Explanation of "ClassCastException" in Java
How to format date in JSTL
How to create a custom EL function to invoke a static method?
This question already has answers here:
Format Date output in JSF
(3 answers)
Closed 5 years ago.
I have a form and when inserting the data the date is inserted in the database in this format :
2017-04-01 00:00:00.0
Here is the component for inserting date into database
<p:outputLabel for="dateFin" value="Date fin"/>
<p:calendar id="dateFin" value="#{etpBean.dateFin}" required="true">
</p:calendar>
here is my component
<p:outputLabel for="dateDebut" value="Date Debut"/>
<p:calendar id="dateDebut" value="#{etpBean.dateDebut}" required="true">
<p:ajax event="dateSelect" listener="#{etpBean.onDateDebutChange}"/>
</p:calendar>
And in this form for search by date and is the same component, then When i chose the date to do the search by date and i display it in my bean it is in this format
Sun Apr 30 00:00:00 GMT 2017
So the list that I recover from the database and always empty since it is not the same format
You are a little bit confused. The date does not change just its appearance. The <p:calendar> has its (maybe local dependent) format and it should differ from the one applied when you visualize it in another view. The visual format of the TTimeStemp values may be set by <f:convertDateTime> subtags:
<h:inputText value="#{bean.date}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:inputText>
<p:calendar value="#{bean.date}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</p:calendar>
I'm trying to fix my cfchart in CF11 to look some similar like in previous CF9. I converted my .xml files and instead I use JSON to style my elements. Problem that I can not fix is cfchartseries. My data that i'm passing in my chartseries looks good, I tried to output everything on the screen before I tested my chart. In CF9 my Time records were displayed on the screen from the first value all the way up to the last value. Here is my screen shot of my chart in CF9:
As you can see on the picture above all my time slots are displayed on the screen in order from the lowest to the highest. Also my record for 2015 is displayed with the bar in blue color, 2016 in pink color. Now I will show you my chart with the exact same code in CF11:
You can see thatmy chart in CF11 starts with the blue bar that present year 2015 and time slot that should not be on the first spot 1415. Also my other time slots are not displayed on the screen. I have tried so hard to get this done but still did not find any solutions. I'm wondering if anyone can help with this problem. Below is my code and I will show you both codes for CF9 and CF11.
Code for chart in CF9:
<cfchart format="#ffPrint#" xaxistitle="#desc#" yaxistitle="#yTitle#" style="ChartStyle.xml"
chartheight="700" chartwidth="#graphWidth#" title="#title#" showlegend="#theLegend#" >
<cfchartseries type="bar" itemcolumn="Spacer" valuecolumn="" seriescolor="white" >
<cfoutput>
<cfloop list="#dataList#" index="i">
<cfchartdata item="#i#" value="0">
</cfloop>
</cfoutput>
</cfchartseries>
<cfoutput query="getRecords" group="theYear">
<cfchartseries type="bar" itemcolumn="#theYear#" valuecolumn="theCount" seriescolor="#listGetAt(theColors,colorIndex)#" >
<cfset colorIndex++>
<cfoutput>
<cfchartdata item="#Description#" value="#theCount#">
</cfoutput>
</cfchartseries>
</cfoutput>
</cfchart>
Code for my chart in CF11:
<cfchart format="html" xaxistitle="#desc#" yaxistitle="#yTitle#" style="#cStyle#"
chartheight="700" chartwidth="#graphWidth#" title="#newTitle2#" showlegend="#theLegend#">
<cfoutput query="getRecords" group="theYear">
<cfchartseries type="bar" itemcolumn="#theYear#" valuecolumn="theCount" seriescolor="#listGetAt(theColors,colorIndex)#" serieslabel="#theYear#">
<cfset colorIndex++>
<cfoutput>
<cfchartdata item="#Description#" value="#theCount#">
</cfoutput>
</cfchartseries>
</cfoutput>
</cfchart>
In order to get any records in CF11 I had to remove my first CFCHARTSERIES, still if I have combination of 2015 and 2016 years records my chart does not display values on the screen. I think that problem is in CFCHARTSERIES but I do not what should be changed to fix this issue. If anyone can help please let me know.
Thanks in advance!
Somehow 437432903.96807599067687988281 translates to November 11, 2014, 4:08pm, but I'm not sure how.
Edit: The context is I'm trying to export data from Thyme, a menubar timer for Mac. It's recorded in an XML file called storedata. For example:
<object type="SESSION" id="z102">
<attribute name="seconds" type="int32">43</attribute>
<attribute name="minutes" type="int32">10</attribute>
<attribute name="hours" type="int32">4</attribute>
<attribute name="date" type="date">437432903.96807599067687988281</attribute>
</object>
Apple's OS X Objective C application framework Cocoa has a date/time class NSDate which uses an epoch date of January 1st 2001. So a timestamp of 437432903.96807599067687988281 seconds, when added to January 1st 2001, gives you the correct date and time: 9:08:23 pm GMT | Tuesday, November 11, 2014
I'm using RaptureXML to parse an rss feed from USGS. I am able to parse it just fine except the three tags of the same name. So, how do I get the 51.50 km from tag in this xml.
<item>
<pubDate>Thu, 12 Jan 2012 01:40:05 GMT</pubDate>
<title>M 4.7, near the east coast of Honshu, Japan</title>
<description>January 12, 2012 01:40:05 GMT</description>
<link>
http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc0007jgs.php
</link>
<geo:lat>36.3774</geo:lat>
<geo:long>141.2328</geo:long>
<dc:subject>4</dc:subject>
<dc:subject>pasthour</dc:subject>
<dc:subject>51.50 km</dc:subject>
<guid isPermaLink="false">usc0007jgs</guid>
</item>