Object | +--HopObject
Defined in HopObject.js
See:
| SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods |
| Constructor Summary | |
HopObject()
Constructor for HopObject objects, providing the building blocks of the Helma framework. |
|
| Properties Summary | |
Number |
_id
The unique id of the HopObject. |
HopObject |
_parent
The parent collection containing this HopObject. |
| Methods Summary | |
Boolean
|
add(<HopObject> subnode)
Attaches a HopObject as an additional subnode. |
Boolean
|
addAt(<Number> position,<HopObject> subnode)
Attaches an additional subnode at the given index. |
Object
|
cache()
Cache object providing space for arbitrary run-time data. |
void
|
clearCache()
Clears this HopObject's cache property. |
Number
|
contains(<HopObject> obj)
Determines if a HopObject contains a certain subnode. |
Number
|
count()
Get the number of subnodes attached to this HopObject. |
HopObject
|
get(<String> id)
Retrieves a property or a subnode of a HopObject. |
HopObject
|
getById(<Number> id,<String> proto)
Retrieves the specified HopObject. |
HopObject
|
getChildElement(<String> name)
Optional handler to override the default URL path resolution. |
Array
|
getOrderedView(<String> name)
Returns a collection including all subnodes of a HopObject ordered according to the properties listed in the string passed as argument. |
helma.framework.repository.Resource
|
getResource(<String> resourceName)
Returns a helma.framework.repository.Resource object defined for the prototype. |
Array
|
getResources(<String> resourceName)
Returns an Array of helma.framework.repository.Resource objects defined for the prototype. |
String
|
href(<String> action)
Returns the absoulte URL path of a HopObject relative to the application's root. |
void
|
href_macro(param)
macro returns the url for any hopobject |
void
|
id_macro(param)
macro returns the id of a HopObject |
void
|
invalidate(childId)
Marks a HopObject as invalid so that it is fetched again from the database. |
Array
|
list()
Returns an array including all subnodes of a HopObject. |
void
|
loop_macro(param)
generic macro that loops over the childobjects and renders a specified skin for each of them |
void
|
onInit()
If a HopObject prototype defines a function named onInit(), it will be called on each HopObject that is fetched from embedded or relational database. |
void
|
onPersist()
If a HopObject prototype defines a function named onPersist(), it will be called on each HopObject immediately before it is stored to embedded or relational database. |
void
|
onRequest()
If defined, the onRequest() function is called on the object specified by the request path just before the action is invoked. |
void
|
onUnhandledMacro()
If a HopObject prototype defines a function named onUnhandledMacro(), it will be called when a macro is rendered on the HopObject that can't be mapped to a macro function or property of the HopObject. |
void
|
persist()
Stores a transient HopObject and all HopObjects reachable from it to database. |
void
|
prefetchChildren(<Number> startIndex, <Number> length)
Manually retrieving a particular set of subnodes. |
void
|
remove()
Deletes a HopObject from the database. |
void
|
removeChild(<HopObject> child)
Notifies a parent object that a child object has been removed. |
void
|
renderSkin(<String> skin, <Object> params)
Renders a skin of a HopObject and writes the result to the output buffer. |
String
|
renderSkinAsString(<String> skin, <Object> params)
Renders a skin of a HopObject and returns the result as string. |
void
|
setParent(<HopObject> subnode)
Assigns a HopObject as parent to a subnode. |
Number
|
size()
Get the number of subnodes attached to this HopObject. |
void
|
skin_macro(param)
macro rendering a skin or displaying its source (param.as == "source") |
void
|
switch_macro(param)
this macro renders a text depending on the value of a given property |
void
|
update()
Refetches updateable Subnode-Collections from the database. |
| Constructor Detail |
HopObject()
| Properties Detail |
Number _id
HopObject _parent
| Method Detail |
Boolean add(<HopObject> subnode)
subnode - as HopObject to add to this node.
Boolean addAt(<Number> position,<HopObject> subnode)
position - as Number, the index position where the subnode is to be inserted.
subnode - as HopObject to add to this node.
Object cache()
var obj = root.get(0); obj.cache.message = "This is a temporary message."
void clearCache()
Number contains(<HopObject> obj)
var obj = root.get("myObject");
res.write(root.contains(obj));
23
obj = root.get("blobject");
res.write(root.contains(obj));
-1
obj - as HopObject, the node to look for
Number count()
res.write(root.count()); 5
HopObject get(<String> id)
root.get(0);
HopObject author
root.get(1);
HopObject story
root.get("date");
Wed Oct 18 02:01:41 GMT+01:00 1971
root.get("title");
The Nudist On The Late Shift
root.get("1");
HopObject author
id - as String or Number
HopObject getById(<Number> id,<String> proto)
//get the child with id 17
var child = root.getById(17);
writeln(child._id);
17
//get the child at index 17 of the HopObject's children-collection
child = root.get(17);
writeln(child._id);
42
//get the child with the name "17" (_children.accessname = name) of the HopObject
child = root.get("17");
writeln(child._id);
69
writeln(child.name);
17
//get the persistent HopObject with prototype "Page" and id 127
var page = HopObject.getById(127, "Page");
writeln(page._id);
127
//get the persistent HopObject with prototype "Page" and id 127
var page = Page.getById(127);
writeln(page._id);
127
id - as Number
proto - as String, the name of the prototype
HopObject getChildElement(<String> name)
function getChildElement(name) {
if (name == 'transient') {
return new HopObject();
}
else {
return this.get(name);
}
}
name - as String, the name of the child element in the requested URL path
Array getOrderedView(<String> name)
var orderedByDate = hobj.getOrderedView("createtime desc, name");
for (var i in orderedByDate) {
doSomething();
}
// other syntax examples:
var orderedByName = hobj.getOrderedView("name");
var collectionByName = hobj.collection.getOrderedView("name");
name - as String, the property names to sort by
helma.framework.repository.Resource getResource(<String> resourceName)
root.getResource("main.skin");
/usr/local/helma-apps/myApp/repository1/HopObject/main.skin
root.getResource("type.properties");
/usr/local/helma-apps/myApp/repository3/Root/type.properties
root.getResource("Functions.js");
/usr/local/helma-apps/myApp/repository17/Root/Functions.js
resourceName - as String, the name of the requested resource
Array getResources(<String> resourceName)
resourceName - as String, the name of the requested resource
String href(<String> action)
var obj = root.get(0);
res.write('<a href="' + obj.href() + '">');
<a href="/main/">
res.write('<a href="' + obj.href('edit') + '">');
<a href="/main/edit">
action - as String, optional part to be attached to the URL of this HopObject
void href_macro(param)
void id_macro(param)
void invalidate(childId)
var obj = this.get(0); obj.invalidate();
Array list()
var objectList = root.list();
for (var i=0; i < objectList.length; i++){
var myObject = objectList[i];
res.writeln(myObject.created);
}
Wed Oct 18 02:01:41 GMT+01:00 1971
Fri Nov 03 13:25:15 GMT+01:00 2000
Mon May 29 07:43:09 GMT+01:00 1999
var amount = root.size();
for (var i=0; i < amount; i++){
var myObject = root.get(i);
res.writeln(myObject.created);
}
Wed Oct 18 02:01:41 GMT+01:00 1971
Fri Nov 03 13:25:15 GMT+01:00 2000
Mon May 29 07:43:09 GMT+01:00 1999
void loop_macro(param)
Object - providing the following properties: skin: the skin to render for each item (required) collection: the collection containing the items limit: max. number of items per page (req.data.page determines the page number) sort: property name to use for sorting order: sort order (either "asc" or "desc")
void onInit()
void onPersist()
void onRequest()
void onUnhandledMacro()
void persist()
var hobj = new HopObject(); hobj.foo = new HopObject(); res.debug(hobj.persist()); 2 res.debug(hobj.foo._id) 3
void prefetchChildren(<Number> startIndex, <Number> length)
res.writeln(root.length); 53874 root.prefetchChildren(0, 3); for (var i=0; i<3; i++) res.writeln(i + ": " + root.get(i)); HopObject 1 HopObject 5 HopObject 4
startIndex - as Number
length - as Number
void remove()
res.write(parent.size()); 24 var child = parent.get(5); child.remove(); parent.removeChild(child); res.write(parent.size()); 23
void removeChild(<HopObject> child)
res.write(parent.size()); 24 var child = parent.get(5); child.remove(); parent.removeChild(child); res.write(parent.size()); 23
child - as HopObject
void renderSkin(<String> skin, <Object> params)
Contents of the file root/example.skin: <html> <head> <title>Hello, <% param.title %>!</title> </head> <body bgcolor="<% param.bgcolor %>"> I greet you <% param.amount %> times. </body> </html>Rendering the skin:
var param = new Object();
param.bgcolor = "#ffcc00";
param.title = "World";
param.amount = "12345";
root.renderSkin("example", param);
<html>
<head>
<title>Hello, World!</title>
</head>
<body bgcolor="#ffcc00">
I greet you 12345 times.
</body>
skin - as String, the name of the skin to be rendered
params - as Object, optional properties to be passed to the skin
String renderSkinAsString(<String> skin, <Object> params)
var str = root.renderSkinAsString("example", param);
res.write(str);
which is equivalent to
root.renderSkin("example", param);
skin - as String, the name of the skin to be rendered
params - as Object, optional properties to be passed to the skin
void setParent(<HopObject> subnode)
var trash = user.stories.get(23); trash.setParent(root); root.remove(trash);
subnode - as HopObject
Number size()
res.write(root.size()); 5
void skin_macro(param)
void switch_macro(param)
void update()
| SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods |