jquery - Spring fmt tags + handlebars.js template + ajax -
i using springs fmt tags display date comment have being posted. this:
<fmt:formatdate type="both" value="${comment.date}" />
this works great comments have been posted. (written on page load)
the problem when dynamically adding new comment ajax.
then i'm using handlebars template follows.
<script id="new-comment-template" type="text/x-handlebars-template"> <div class="discussion-comment" id="{{id}}"> <h4 class="inline"> <small> <a href="/users/{{userid}}" class="text-primary inline">{{name}}</a> @ {{university}} {{date}} </small> </h4> <form id="command" class="pull-right inline" action="/courses/${course.id}/${course.name}/comment/{{id}}" method="post"><input type="hidden" name="_method" value="delete"> <button type="submit" class="btn btn-danger btn-sm"> <i class="fa fa-trash-o fa-lg"></i> </button> </form> <p>{{{message}}}</p> </div> </script>
but {{date}}
variable comes server on wrong form , if i'm trying
<fmt:formatdate type="both" value="{{date}}" />
im getting error since value not exist when template being parsed (i guess).
i use springs fmt:formatdate
tag since handles internationalisation.
is possible somehow?
if not i'm thinking of alternatives:
- keep track of time on client. updating constantly, writing "5min ago", "10min ago" , on. until page refreshed.
- try send time in right format server directly. possible run fmt:formatdate on server side?
thank you suggestions.
you might find moment.js solution this.
Comments
Post a Comment