Primefaces calendar : Not able to format the date - primefaces

Updated : I have used primefaces calendar to show dates. It's default format is mm/dd/yy but for other locale like german it is dd.mm.yy. If I specify the format for english for example dd/MM/yyyy then it shows correct format for english but then on changing language to german it shows again dd/MM/yyyy instead of dd.MM.yyyy
I have tried this :
<p:calendar id="createdDateToDK"
value="#{messagesDefaultKeys.createdDateTo}" showOn="button"
mode="popup" navigator="true" pattern="dd/MM/yyyy>
<f:converter converterId="messages.convertors.DateConvertor" />
</p:calendar>
I have tried below also:
<p:calendar id="createdDateToDK"
value="#{messagesDefaultKeys.createdDateTo}" showOn="button"
mode="popup" navigator="true">
<f:convertDateTime for="createdDateToDK" pattern="dd/MM/yyyy"></f:convertDateTime>
</p:calendar>
I am using primefaces3.5 jar and JSF2.0 .
I do not want to add another calendar component just for another language . Please note that this happens only when I specify the format for calendar else while it works well with different locales.

No need to use a converter for dates, calendar comes with an attribute called pattern, you can use it to change the pattern of dates, for exemple <p:calendar pattern="dd.MM.yyyy HH:mm" /> this will show 21.02.2017 15:42, you can change the pattern to separate the date however you like using dots, slach or any character

Related

Why WPF ignores my CultureInfo.CurrentCulture

I started messing up with MySQL.Data.EntityFramework (8.0.15) and I'm getting wrong date format.
In my culture ('pl-PL') date format is "YYYY-MM-DD", but DataGrid shows dates in "MM/DD/YYYY" format by default. My Windows regional settings are correct.
Console.WriteLine(CultureInfo.CurrentCulture); // shows pl-PL
My binding initially was like this:
<!-- wrong date format -->
Binding="{Binding date}"
Setting ConverterCulture in Binding worked:
<!-- correct date format -->
{Binding date, ConverterCulture='pl-PL', StringFormat=d}
but I don't want to set ConverterCulture everywhere.
My question is:
How can I fix this?
Try setting
Thread.CurrentThread.CurrentUICulture
And maybe, you need to take a look to
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

Primefaces dataTable populate (search) doesn't work well after filtering

I have a Primefaces dataTable like this in a <h:form> block:
<p:dataTable id="basicDT" var="partyDB" value="#{mbRechercheAbonne.listPartyDB}"
paginator="true"
emptyMessage="Aucun abonné ne correspond aux critères"
paginatorPosition="bottom"
paginatorAlwaysVisible="false"
rows="25"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100"
currentPageReportTemplate="{startRecord} - {endRecord} sur {totalRecords} résultats"
filteredValue="#{mbRechercheAbonne.filteredListPartyDB}">
and a search button that populates the dataTable using a #ViewScoped bean that updates the value of listPartyDB when rechercheAbonne() is called:
<p:commandButton value="Rechercher" update="display :consultform:basicDT" icon="ui-icon-check"
actionListener="#{mbRechercheAbonne.rechercheAbonne()}" onstart="startRecherche()" oncomplete="stopRecherche()"/>
Searching multiple times works, the dataTable's content changes like expected.
However, when using filtering and then removing the filter (i.e. adding a letter in a filter field above a column and then removing that letter), the search no longer works. I found that the search does actually work, but I need to apply a filter again (and remove it to have the unfiltered list) to see the result of the new search.
Explaining with pictures :
Searching for "test":
Searching for "abc" right after, works as intended:
Searching for test again, filtering one column, works as intended:
Removing the filter (going back to pic 1), and then searching for "abc". Does not work:
Applying a filter again does it on the "abc" search that wasn't showing originally - removing the filter shows what the last search should have shown.
Thanks for your help.

primefaces:datatable: custom filter: "contains" instead of "beginning"

By default, primeface filter dataTable's rows, by finding rows that columns begins with the string entered in the search area.
How do I filter the DataTable rows that the column contains (not begins with) the string entered in the search area?
You can do this using filterMatchMode attribute on p:column of the dataTable. A very good example can be found on PrimeFaces showcase.
So if we take the above mentioned example, you could have roughly something like this:
<p:dataTable var="car" value="#{dtFilterView.cars}" widgetVar="carsTable"
filteredValue="#{dtFilterView.filteredCars}">
<p:column filterBy="#{car.id}" headerText="Id" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
The attribute filterMatchMode accepts values such as contains, endsWith, startsWith, exact...

Flex 4 - How to format and validate DateField TextInput?

I have a DateField with editable = true. Now i want to validate the DateField TextInput. If the user enter the value like this "200001/12/12", it has to be display the error message.
How can i do it?
If you are using your own date format, you need to make the validation by your own (custom function). Otherwise, you can use a DateValidator and call validate on DateField change:
<mx:DateValidator id="dateValidator" source="{myDate}" property="text" requiredFieldError="You must choose a date" />
<mx:DateField id="myDate" focusOut="dateValidator.validate()" />
This is a basic example, maybe you will need to tweak it a little. You can also use the reference (it has a working example at the bottom):
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/validators/DateValidator.html

primefaces dataexport from table with column content in ui:repeat

I have a master detail resultset that I present on a datatable.
The detail is fetched and rendered within to be combined into a single output string that remains in one column.
<p:column>
<f:facet name="header">BF Order Contents</f:facet>
<ui:repeat value="#{order.listOfOrderDetails}" var="orderitem" varStatus="orderitemstatus" >
<h:outputText value="#{orderitem.product.brand.name}-#{orderitem.product.name}#{orderitemstatus.last ? '':', '}" />
</ui:repeat>
</p:column>
On the datatable, that column displays as "Some Brand-Some Product, Other Brand-Other Product"
But when I export to EXCEL, I see:
com.sun.faces.facelets.component.UIRepeat#783622ba
in that column.
Does anyone have any idea about how I can overcome this (within xhtml only). I don't want to alter the backing bean to produce the detail string.
BTW: I'm on PF3.2, Mojarra 2.1.8, EL 2.2.1-b04, JDK1.7, Tomcat7
Thanks
It can be solved in the below manner.
Column having ui:repeat should not be made exportable i.e set exportable="false" attribute for p:column.
Add one more column to display the string property (write bussiness logic to convert list of string to a comma seperated string and set it the string property)
set the style as display:none; for the new column.
so during ui display, the previous column will display and during export the new column will be displayed showing comma seperated list.
I really don't think its possible , even with overriding the exporter class in the primefaces sources it will be way to complicated...
You probably better alter the backing bean
Also, you can add a star on a bit related an issue opened by me Feature request: Datatables custom filter function - filterFunction (like sortFunction for sort)
You can write a facelet function that does the iteration in Java and returns a string.. this will work just put it to outputText, or do 2 columns one put exportable false and the other make CSS display:none