the Easy framework for Agile development with Oracle WebCenter Sites
In this section we will see how to create links and how to use them to build naviations.
The general rule to create a link is using the method Asset.getUrl
. However you generally need to load the asset to do this.
Since you generally generate links for assets pointed by attributes, this is the typical code you write:
a.getAsset("Related", "Page").getUrl()
Another option is to use the Env.getUrl(id)
. To use this method, you need an id. You use this method when you navigate the siteplan.
NOTE Be aware of dependencies when you retrieve assets by id. The pagelet you generate will depend on them, and if you change the linked asset then the pagelet must be invalidated.
Once you got the url, you can use it to set the href attribute.
The SitePlan
class helps you to navigate in the siteplan.
You get a siteplan instance with e.getSitePlan()
. The SitePlan has a concept of current node in the siteplan, and by default it is the current site. You can then do the following:
sp.children()
returns the children of the current nodem as an array of Idssp.goTo(id)
lets you to change the current idsp.getPath()
return the path (as an array of id) from the current asset up to the root. Note that in the path the current node is excluded so when you are at the root, the path is an array of zero elements.
Using the SitePlan this is the code to create the top level menu, that create a StringBuilder with to Pages located to the top level of the site plan:
StringBuilder sb = new StringBuilder();
SitePlan sp = e.getSitePlan();
for (Id id : sp.children()) {
String name = e.getAsset(id).getName();
sb.append(
format("<a href='%s'>%s</a> |",
e.getUrl(id), name));
}
AgileSites - Written by Michele Sciabarrà - © 2013 Sciabarra srl
Open Source Software releases under the Apache License 2.0
Credits: Hosted on GitHub Pages using the Dinky theme for Jekyll Bootstrap