Forum OpenACS Q&A: XoTCL Newbie

Collapse
Posted by Nima Mazloumi on
I have several question regarding XoTCL and OpenACS. Please regard these questions more like a first step for the documentation to get new developers started.

  1. Why should I use it? My guesses are:
    • object orientation (encapsulation, inheritance) [1]
    • cleaner and less code
    • better performance
    • what else?
  2. Where can I see examples?
      Check out the packages
    • myfirstpackage
    • xotcl-core
    • xotcl-request-monitor
    under [2] as well as the documentation under [3].
  3. Does XoTCL provide an Object-Relational-Mapping?
    • If I am not mistake there is an abstraction layer for cr items: There is the meta class CrClass, the classes CrItem and Attribute. So it seems there is no OR-Mapping in general right?
    • Taking a look at the myfirstpackage package I see that the developer has to provide the typical life cycle procs containing the sql statements. Is a meta class the answer to this problem?
    • I remember Dave mentioning that the is a tcl abstraction layer to acs objects (if I am not mistaken) that abstracts also from PostgreSQL and Oracle. Could this be used as a starting point?
  4. What templating, data facilities does XoTcl provide?
    • I found the following classes Form, List, different fields like AnchorField, ImageField (edit, add, view, delete). You can define your own custom field providing little classes that implement the render-data class method. There are further the classes Table, Table2, TableWidget, ListWidget.
    • There is the HTML namespace which you can use to create an HTML dom
  5. Where is the difference between ad_instproc and instproc and ad_proc and proc within the context of XoTcl?

[1] http://media.wu-wien.ac.at/doc/features.gif

[2] http://media.wu-wien.ac.at/download/

[3] http://media.wu-wien.ac.at/doc/tutorial.html
Collapse
2: Re: XoTCL Newbie (response to 1)
Posted by Nima Mazloumi on
  • When do I use Class and when Object coming from the Java background?
Collapse
3: Re: XoTCL Newbie (response to 1)
Posted by Nima Mazloumi on
  • Do we have default serializers for classes: to string, to xml, ...?
Collapse
4: Re: XoTCL Newbie (response to 1)
Posted by Nima Mazloumi on
Here a little sample as I start learning XoTcl. You can run this in the developer shell:

# we define a class group with several parameters
Class Group -parameter {{name ""} size type start_date end_date {admin_id ""}}

#We define the default constructor
Group instproc init {} {

if {[empty_string_p [my admin_id]]} {
my set admin_id [ad_conn user_id]
}

my set size 0
my set type open
my set start_date [clock format [clock seconds] -format {%D %X}]
my set end_date [clock format [expr [clock seconds] + 3600] -format {%D %X}]
}

#we create class method toXML
Group instproc toXML {} {

acs_user::get -user_id [my admin_id] -array admin

set result ""
append result "?xml version=\"1.0\" encoding=\"[encoding system]\"?\n"
append result "<group name=\"[my name]\" start_date=\"[my start_date]\" end_date=\"[my end_date]\" admin=\"$admin(first_names) $admin(last_name)\" />\n"
return $result
}

#we create class method toString
Group instproc toString {} {
set result ""
append result "Group: [my name]\n"
append result "Size: [my size]\n"
append result "Starting: [my start_date]\n"
append result "Ending: [my end_date]\n"
return $result
}

#We test our code with two new groups
set result ""

append result "Group 1:\n"
Group group -name "default"
append result "String: [group toString]"
append result "\nGroup 2:\n"
Group group -name "Nimas first group" -size 30 -type closed
append result "XML: [group toXML]"

Now wouldn't it be great if that would be directly stored to the database. Without us using sql?

Collapse
5: Re: XoTCL Newbie (response to 1)
Posted by Nima Mazloumi on
Alright - now that we have two groups lets use the table widget to render so html table:


TableWidget groupsTable -volatile -columns {
Field name -label "Name" -orderby name
Field start_date -label "Starting"
Field end_date -label "Ending"
}

foreach g [Group info instances] {
groupsTable add -name [$g name] -start_date [$g start_date] -end_date [$g end_date]
}

set groupsTable [groupsTable asHTML]


In the adp we simply place:

@groupsTable;noquote@
Collapse
6: Re: XoTCL Newbie (response to 1)
Posted by Nima Mazloumi on
A bit of the track but I found two interesting projects:Maybe they can be somehow combined with OpenACS providing OpenACS with a platform independent IDE.