@Pinyazhin
Hello Roman, I have spent some more time with your ftimefield example (thanks again for that) and with the TimeField API (TimeMode.H_12, TimeMode.H_24) and here is what I have found…
ftimefield Example - Problem: If the displayed “customTime” is “02:44 PM” and I remove the “editable=true” attribute in your order-browse.xml file, then the column display reverts back to a HH:mm format and displays “14:44”. I would expect a non-editable field displaying “02:44 PM”. There must be an internal side-effect preventing the correct display; this appears to be a bug. However, setting the customTimeField to editable=“false" in the order-edit.xml works as expected.
Furthermore, your CustomTimeDatatype.java file does not appear in my CUBA project view; it is only shown when I select the Packages view. Even after invalidating the cache and restarting, it does not appear in the CUBA entity tree structure. This may be a known bug in CUBA Studio or something in the studio settings that I am missing. Is CustomTimeDatatype.java displayed correctly in your project? DO you know how I can correct this?
Pet Clinic Example - Problem: I modified the “cuba-petclinic-i18n-messages-master” example to include the time with the following attribute…
@ Temporal(TemporalType. TIME )
@ NotNull
@ Column(name = “VISIT_TIME” , nullable = false )
private Date visitTime;
and here is what I have found….
If I want to display the local time in the browse column dependent upon the locale, then I need to set the Datatype format to e.g. “timeFormat=hh:mm a” in the “Main Message Pack”, but when I do this, this format is also used in the TimeField in the visit-edit.xml screen even when the TimeMode is explicitly set to H_12. So in my edit screen the TimeField display looks like this “02:44 P PM” and this causes an error when the input is validated.
If I remove the “timeFormat=hh:mm a” from the “Main Message Pack” and add the following formatter to the screen.xml file, then the display is static for only one selected locale.
< column id =“visitTime” >
< formatter class ="com.haulmont.cuba.gui.components.formatters.DateFormatter"
format ="hh:mm a"
useUserTimezone =“true” />
</ column >
Unfortunately, I have not found a description in the documentation or the forum how to programmatically alter/exchange this formatter at runtime.
I had the idea to use the (see above) for one column and then add a second column with a different formatter for format=“HH:mm” and programmatically set one of them to “visible=false” depending upon the locale, because I really only need two: “HH:mm” and “hh:mm a”. But since the column does not have a property field and uses its id to determine the attribute, it is no possible to add a second column. Doing this generates a runtime error.
I therefore decided to try a variant of this idea for testing purposes and added a second customer column for the format=“HH:mm” using the following code in the VisitBrowse screen controller:
@ Install(to = “visitsTable.visitTimeHHmm” , subject = “columnGenerator” )
private Component visitsTableVisitTimeHHmmColumnGenerator(Visit visit) {
Label label = uiComponents.create(Label. NAME );
String visitTimeStr = visit.getVisitTime().toString();
CharSequence charSequence = (CharSequence) visitTimeStr;
LocalDateTime localDateTime = LocalDateTime. parse (charSequence, DateTimeFormatter. ofPattern ( “HH:mm” ));
label.setValue(localDateTime.toString());
return label;
}
I think that this is probably the right idea but this method however generates a parsing error currently:
“DateTimeParseException: Text ‘Thu Jan 01 14:04:00 CET 1970’ could not be parsed at index 0”
and I have not yet been able to find a solution to this. This is my first experience with formatters in Java, so I am certainly doing something wrong. Please note, that I have tried several variations of this formatter, respectively, this method of formatting but I have yet to find the right combination.
Do you have any suggestions, how I can best solve this current problem?
Best regards
Chris