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

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();

Related

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.

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

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"/>

TYPO3: use fluid's date view helper inline as argument for translate view helper

I am currently developing some extensions to use within TYPO3 6.
In one view I have database records with date fields. I can output the date values with the following:
<f:format.date format="d.m.Y H:i:s">{record.validend}</f:format.date>
However, I need a translated message, so I would like to use the translate view helper and put the formatted date in the arguments attribute. Without succes so far.
I tried:
<f:translate key="{msg_id}" arguments="{0: code, 1: {f:format.date(date: record.validend, format: 'd.m.Y H:i:s')}}" htmlEscape="0" />
…and…
<f:translate key="{msg_id}" arguments="{0: code, 1: {record.validend -> f:format.date(format: 'd.m.Y H:i:s')}}" htmlEscape="0" />
…following this guide: http://forge.typo3.org/projects/typo3v4-mvc/wiki/Fluid_Inline_Notation
However, there seems to be some syntax error in my notation forcing fluid to interpret the whole thing as a string, resulting in an error, cause the arguments attribut is expected to be an array.
Could anyone tell me if what I want is possible, and what syntax I need?
best regards
Christian
You need to escape the quotes of format with backslashes.
The solution is:
<f:translate key="{msg_id}" arguments="{0: code, 1: '{f:format.date(date: record.validend, format: \'d.m.Y H:i:s\')}'}" htmlEscape="false" />
The right way to use format.date as variable is:
{f:format.date(format : 'd-m-Y H:i:s', date : '#1368093280')}
I tested your request and it seems that it isnt possible to call a ViewHelper inside the argument arguments of a ViewHelper.
So you should try something else like a custom ViewHelper or format your date in the controller so you have a variable that contains the formatted date:
{f:translate(key : msg.id, arguments : {0 : msg.date})}

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

Grails - how to hide a date inside a form

I have an 'edit' view for a model that has several fields (one of which is a date). I only want a few of the fields visible to allow edits, so I just hide the other fields using <g:hiddenField>
But one of the fields is of type TimeStamp and I can't seem to find a way to hide this in the form. I tried
<g:form method="post" >
<g:textField name="firstName" value="${applicationUserInstance?.firstName}" />
<g:textField name="lastName" value="${applicationUserInstance?.lastName}" />
<g:datePicker name="createDate" style="visibility:hidden;" precision="day" value="${applicationUserInstance.createDate}" />
The date picker is still visible. Any idea how to hide the date so that I can just pass this to the update method upon submit of the form. Many thanks.
Just re-iterating Rob's comment here. No need to put that on the form. The only data you need on the form is the data you are updating and the ID of what is being updated. Everything else will just stay the same...
def update = {
def applicationUserInstance = User.get(param.id)
// at this point applicationUserInstance.createDate is
// correct.
applicationUserInstance.properties = params
// since no createDate was in the params, it doesn't change.
// so you're good
applicationUserInstance.save(flush:true)
}
Actually my answer below might not be the right answer to your question. Otherwise if you really just have a createdDate-field, which should keep track, when the entry was created in the database, I suggest you do it the Grails-way and use the reserved keywords 'dateCreated' and 'lastUpdated'
Check http://grails.org/doc/1.3.7/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.5.1 Events and Auto Timestamping
on how to use these. If you use these then my answer below will be helpful to control the visibility of these fields 'dateCreated', 'lastUpdated'
Suggestions for 'dateCreated', 'lastUpdated'
Probably you want this timestamp to be created automatically as you found it in the Grails documentation but you do not want it to be visible in your view.
Now, to exclude this timestamp from being visible, first
grails install-templates
I assume you have grails-1.3.7
Go to src/templates/scaffolding and check your gsp-files, e.g. 'create' and 'edit'
Search for this line:
<% excludedProps = ["version", "id",
and edit for example 'dateCreated'
<% excludedProps = ["dateCreated", "version", "id",
There is also a tutorial on this topic http://www.ibm.com/developerworks/java/library/j-grails01209/index.html
Greetings,
Jan