Using JavaScript variable in freemarker

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using JavaScript variable in freemarker

anjibman
Hi All.

I have Java Date type field return from back end using jQuery AJAX. It can be access as like
var accessDate = response.book.accessDate;
alert(accessDate);

Since its value is in millisecond i need to display in webpage as mm/dd/yyyy. I didn't find easy way to do through JavaScript so I am planning to use freemarker date function something like ${response.book.accessDate?date?string.short}

how can i copy JavaScript var to freemarker data-model to do date formatting?
Reply | Threaded
Open this post in threaded view
|

Re: Using JavaScript variable in freemarker

Denis Bredelet
Hi anjibman,

> Hi All.
>
> I have Java Date type field return from back end using jQuery AJAX. It can
> be access as like
> var accessDate = response.book.accessDate;
> alert(accessDate);
>
> Since its value is in millisecond i need to display in webpage as
> mm/dd/yyyy. I didn't find easy way to do through JavaScript so I am planning
> to use freemarker date function something like
> ${response.book.accessDate?date?string.short}

Can you have the AJAX query answered by a Freemarker engine?

Your idea cannot work because by the time the browser runs the JavaScript code, Freemarker is already out of the loop and cannot do anything.

> how can i copy JavaScript var to freemarker data-model to do date
> formatting?

The data-model is on the server and the JavaScript is running on the client, so that's not possible unless you use Freemarker with AJAX as I suggested above.

-- Denis.
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user