Re: Javascript + jquery + php page
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Sunday, August 28, 2011, 11:05:09 AM, Håvard Wahl Kongsgård wrote:
> Thanks, but is it possible to integrate SQL with FreeMarker?
Well, if you put a JDBC Connection or DataSource into the data-model,
I'm certain FreeMarker's reflection support's enough for issuing
queries... But I would not recommend that, as it's awkward and all.
The FreeMarker-ish way is writing a (few) TemplateDirectiveModel
implementations instead, something that you could use like this for
example:
<@sqlExec "INSERT INTO foo(X, Y) VALUES(?, ?)" x y />
<@sqlSelect "SELECT id name FROM foo"; row>
... ${row.id} ... ${row.name} ...
</@sqlSelect>
For that you write a TemplateDirectiveModel and put that into the
data-model with name "sql", or pull it into an #imported/#included
file with <#assign sqlExec = "com.example.SqlExecDirective"?new()>.
Still, data-base modifications should clearly be done outside the
template according the MVC principles, in the Controller.
> I use geoserver(FreeMarker is the template engine). I only need to
> do some simple inserts from a form to a postgresql database.
>
> -Håvard
>
> 2011/8/27 Daniel Dekany <[email protected]>:
>> FreeMarker just generates text (like HTML, JavaScript, whatever) on
>> the *server* side. So of course you can have AJAX, jQuery etc. on your
>> FreeMarker-generated web pages. But mind you, JavaScript runs on the
>> *client*, and hence after FreeMarker was generated the page.
>>
>> You can't (or shouldn't) use FreeMarker on the same way as you use
>> PHP. With PHP you do all the program logic including the presentation,
>> while with FreeMarker you do the presentation only. FreeMarker is for
>> MVC frameworks, where it's used for the MVC View. Do the non-View
>> programming in Java, Groovy, Scala, or whatever you prefer, but not in
>> FreeMarker. (Or if you don't need MVC, you don't want to use
>> FreeMarker.)
>>
>> Saturday, August 27, 2011, 8:57:10 PM, Håvard Wahl Kongsgård wrote:
>>
>>> Hi, without success, I experimented with including simple Javascript
>>> Ajax code interacting with a PHP site in freemaker templates.
>>>
>>> example
>>> http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/
>>>
>>> With the current version of freemaker is it possible to include this
>>> type of code in freemarker templates?
>>>
>>
>> --
>> Best regards,
>> Daniel Dekany
>>
>>
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev