Forum OpenACS Q&A: pros and cons of .adp pages...

Collapse
Posted by David Kuczek on
Can anybody describe the pros and cons of .adp pages?

How can I transform a regular openacs .tcl page into a .adp page?

Is there a tutorial, documentation or "how to" somewhere?

Collapse
Posted by Roberto Mello on
AOLserver/OpenNSD caches the .adp's to avoid too much recompilation. This is a big pro IMHO. I don't know about any cons. To me it's more about the way you like to program.

In .adp's the "default" is HTML. You have to 'escape' into Tcl to be able to use it. It's something like: <h2>Some subsection</h2>

<%
  set db [ns_db gethandle]
  set name [database_to_tcl_string $db "select name from users where user_id=3"]
  ns_db releasehandle $db
%>

<b>your name</b> is <%= $name %>

Everything between <% %> is Tcl. You need to use ns_puts to output to the browser. Or <%= %>, which treats whatever is inside the brackets as arguments to an ns_puts. (I hope the < and > show up on the e-mail output).

AOLserver has good documentation on ADPs. Read the Tcl Development Guide at http://www.aolserver.com/docs

Collapse
Posted by Bob Fuller on
Roberto's reply provides me with verification that the problem I've been experiencing with some of my Portal Tables (which are ADP scripts) is somehow directly linked to the fact that AOLserver caches the ADP scripts in memory. Yes, there is a potential problem, unless of course I'm missing something.

The following script, which is the code for a portal called "Region",

<%
set user_id [ad_verify_and_get_user_id]
set selection [ns_db select $db "
  select group_name, short_name
  from user_groups ug, user_group_map map
  where ug.group_type = 'Region'
  and ug.group_id = map.group_id
  and map.user_id = $user_id"]
ns_db getrow $db $selection
set_variables_after_query
ns_puts "<B>$group_name</B><BR>"
ns_puts "<a href='/groups/$short_name/calendar/monthly.tcl'>$group_name Calendar</a><BR>"
ns_puts "<a href='/groups/$short_name/address-book/'>$group_name Contact List</a><BR>"
ns_puts "<a href='/groups/$short_name/news/'>$group_name News</a>"
%>
is fine when you access it under /portals/admin/edit-table; there are no error messages relating to problems with ADP parsing, and the table looks like it should. However, if you access it from an actual portal a little while later, the $group_name and $short_name variables disappear! (They're replaced with null values, or something of the sort, so the table still gets parsed, but all references to Regions -- the group names that are supposed to be there -- disappear. BTW, there is a group_type called 'Region' in my installation, in case anyone wonders.)

Anyone have ideas about what I might be missing in this example, and/or possible workarounds? (The example is missing the usual calls to ns_db gethandle and releasehandle because, to the best of my understanding, those are covered with the Portals code itself.)

Collapse
Posted by Grzegorz Mucha on
One more thing for ADP's. When switching to nsd8x, I had to solve
the ISO8859-2 vs Unicode encoding problem. I couldn't make AOLServer
output the correct charset when processing adp requests and it is
not only my problem.

I circumnavigated it by using the [ad_parse_template] function -
though as I had had to use the ns_startcontent command, I changed
the -file to -string switch in ns_adp_parse and immediately got
rewarded with 'fancy' adp-parser not working.

The ADP's are a fine thing, though they pose some problems when
using different encodings.