Grails: error executing tag <g:formatDate>: unknown class: java.lang.String with root cause - date

I have dates stored in my database in a format like this: 2017-04-12T00:00:00
I am displaying these on an index show page like so:
<td>${event.eventTime}</td>
I want to convert the date into a a regular format, I came across the grails formatDate tag.
I've tried variations of this but the error from the title still remains, where am I going wrong?
<td><g:formatDate date="${event.eventTime }" format="yyyy-MM-dd" /></td>

It appears that eventTime on your event object is a string rather than a date.
If you try the following as a test it should work:
<td><g:formatDate date="${new Date()}" format="yyyy-MM-dd" /></td>
Is eventTime stored as a date in the DB or maybe it's being converted en-route to the gsp?
To just strip off the time & keep the same format you could:
${event.eventTime?.substring(0, 10)}
Or you could convert to a date and back to another format:
<g:formatDate date="${Date.parse( "YYYY-MM-dd'T'hh:mm:ss", event.getTime )}" format="yyyy-MM-dd"/>

Related

SendGrid - formatDate with Insert tag definition - Error

I am trying to format the date using formatDate. None of the options is working in terms of formatting the date. Please suggest. We are using the insert tag to fetch values from the template.
{{insert notes_lead_creation_date}}
This date has to be formatted to DD/MM/YYYY. Currently the date has : notes_lead_creation_date:2058-07-25
Also, getting an error message.
This message has been dropped.
As per the documentation, you cannot format a date within an insert helper. If you are using insert to provide a fallback, you should use a conditional, like so:
{{#if notes_lead_creation_date}}
{{ formatDate notes_lead_creation_date "DD/MM/YYYY"}}
{{else}}
default content
{{/if}}
Note that the date must be provided in ISO8601 format too.

How to set two way binding for a date object?

I'm trying to implement DatePicker to return a Date Value similar to this example in Angular 6
https://stackblitz.com/angular/klxqgnondlx?file=app%2Fapp.component.html
It works great . . . . . . . but it returns a JSON date rather than Date object, so the two way binding with a corresponding date field doesn't work.
I need the date picker to return Date object not JSON
Here is what I tried
<input class="form-control" type="date" placeholder="yyyy-mm-dd"
id ="myDate" name="myDate" [(ngModel)]="model.myDate| date:'yyyy-mm-dd'" ngbDatepicker #d="ngbDatepicker" (ngModelChange)="myDate= $event" >
But it didn't work
What is returned is up to the library you are using. You could always use a different library. It might be easiest to just make your model a string (representation as JSON date), and convert it to a Date object when you actually need to use the Date representation.

How to convert a Date in a dynamically added input field (JSF)

In my application I want to enter a date in an <input> field which is programatically created for a JSF page.
The creation of the input field looks like this:
// Input
String jsfValue = String.format("#{%s.item.%s}", getELClassname(), property.getKey());
ValueExpression valueExpression = JSFUtils.createValueExpression(jsfValue, property.getValue());
HtmlInputText input = (HtmlInputText) app.createComponent(HtmlInputText.COMPONENT_TYPE);
input.setId(property.getKey());
input.setValueExpression("value", valueExpression);
The property is an instance of java.util.Date and the <input> field is just an HtmlInputText component without any converter assigned to it.
When the <input> tag is rendered, then the following value can be seen for a date:
Tue Mar 11 18:31:20 CET 2014
If I know want to save the form, then the JSF page complains about the format of the date because it is not able to convert the input value to a java.util.Date.
Can someone tell me how I can create a converter programatically for a HtmlInputText component?
When I was using MyFaces for my application then the conversion was done automatically because I never had this problem before.
DateTimeConverter converter = (DateTimeConverter) application.createConverter(Date.class);
converter.setPattern(somePattern);
input.setConverter(converter);
The trick is to apply a DateTimeConverter to the dynamically created input field so that JSF knows how to convert the given String into a proper java.util.Date.
Here is a code sample:
HtmlInputText input = (HtmlInputText) app.createComponent(HtmlInputText.COMPONENT_TYPE);
...
DateTimeConverter converter = (DateTimeConverter) app.createConverter(DateTimeConverter.CONVERTER_ID);
converter.setPattern("mm/dd/yyyy");
input.setConverter(converter);
If other date formats are needed, you can take a look at Wikipedia: Date format by country.

Set initial value of DateInputElement

I need to set intial value for DateInputElement. The .dart file has a variable dob with initial value:
String dob='01/01/2013'
and html has
<input id='mydob' type='date' name='dob' required='true' bind-value='dob'/>
dob is not shown when UI is displayed. The control shows mm/dd/yyyy.
If I select a date on UI, the date value is populated in dob variable.
Although bind-value sets two way binding, still tried setting the value to dob as follows without success:
<input id='mydob' type='date' name='dob' required='true' value={{dob}} bind- value='dob'/>
Also tried the following in life cycle events but did not work:
DateInputElement e = query('#mydob');
e.value=dob;
The format you are trying to put into the field is wrong. It's supposed to be 2013-01-01 (YYYY-MM-DD) according to the RFC. This is completely independent from dart or any other binding.
I would add that it is nessary to have the 0. So it is 2013-01-01 and not 2013-1-1

struts 2 s:date tag with value from variable in request with it's name in request

I have a problem in my web app with struts 2 and a date value. I've got a form and inside it an s:textfield that shows a date value. I read this value from request, and the problem is that the name of that value is in other variable.
The Action I'm calling does this:
...
public String execute(){ return SUCCESS;}
public MyObject getObject1(){
MyObject result = new MyObject();
result.setDate(new java.util.Date());
return result;
}
...
On SUCCESS it goes to my form.
The code in my form (what I was wondering to write) is:
<s:form action="save">
<s:set name="objName" value="object1"></s:set>
<jsp:include page="../includedform.jsp"></jsp:include>
</s:form>
And in the "includedform.jsp" there is:
<s:textfield name="%{objName}.date" label="Date" >
<s:param name="value">
<s:date name="%{%{objName}.date}" format="dd/MM/yyyy" />
</s:param>
</s:textfield>
The syntax:
%{%{objName}.anagrafica.dataNascita}
doesn't work (it shows nothing, obviously). So i'll need something like this but working :)
Other tags s:textfield inside "includedform.jsp" (ommited in the code bellow for simplicity) without date fields are working, because I am using only the name attribute and struts looks automatically for the value. This is the code I use for these textfields:
<s:textfield name="%{objName}.name" label="Name"/>
your question is very confusing and you need to rephrase to make it more clear and readable.
i am not sure why you are doing this
<s:textfield name="%{objName}.date" label="Date" >
while this can be done like
<s:textfield name="objName.date" label="Date" > OR
<s:textfield name="%{objName.date}" label="Date" >
when you write objName.date OGNL assume that you have a bean in your action class namely objName and this bean has property namely date, s ultimately this will get converted to
getObjName().getDate() by ONGL
On a similar fashion <s:date name="%{%{objName}.date}" format="dd/MM/yyyy" /> datee tag works
For more details please refer to the official doc
Struts2 Date tag
There is one solution which i tried and it worked :)
1)Keep the column in which you want to store date in database's table in "DATE" data type only.
2)Use only Textfield tag in JSP page.Dont use Date tag.
Note:Make sure that you make user input date in YYYY-MM-DD format only by placing a placeholder in textfield tag !
3)Keep the variable for accessing that field of string type only.Dont use DATE data type.
4)Now run Query: Select DATE_FORMAT(datecolumnname,'%d/%m%/Y') as date_two from tablename; and you will get date from that columnin dd/mm/yyyy format even if it is stored in YYYY-MM-DD format in table .
5)And you can also compare your datecolumn's data with curdate() and related functions as well and it works :) .
6)Like i used query: Select id,name,DATE_FORMAT(datecolumnname,'%d/%m/%Y') as datecolumn2 from tablename where datecolumnname >= curdate();