Re: Using JavaScript variable in freemarker

Denis Bredelet <[email protected]> Tue, 03 Sep 2013 08:24:51 +0100
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
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