How do I use getStructuredDataNode() ?
I can't seem to access the first text field named "link" in the
attached data definition, using
$currentPage.getStructuredDataNode("newsandevent/item[1]/headline")
.
Originally, we had this code with a "current page XML" index block:
#set ($link = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/newsandevents/item[1]/link"))
<a href src="${link.value}">some text</a>
But when I try this code, Cascade returns link: ${link.value}:
#set ($link= $currentPage.getStructuredDataNode("newsandevent/item[1]/link") )
link: ${link.value}
Similarly, these tests return The object is null.
$_PropertyTool.outputProperties($currentPage.getStructuredDataNode("newsandevent/item[1]/headline") )
`$_PropertyTool.outputProperties($currentPage.getStructuredDataNode("newsandevent/item[1]/headline").textValue )
I'm currently on Cascade 7.12.4.
- data-definition.xml 2.58 KB
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 04 May, 2015 06:52 PM
Hi Erik,
Although the
getStructuredDataNodes
method will accept an XPath-like syntax, you won't be able to useitem[1]
to filter down to a specific position like you would with XPath.Instead, you would want to use something like the following to get the link field from the first
newsandevents/item
group:Note: The node path you used in your sample snippet was slightly off for the
newsandevents
group identifier and you need to usegetStructuredDataNodes
when obtaining nodes set to multiple.Alternatively, you can also use the bracket notation when accessing the array of
item
nodes:Please let me know if you have any questions.
Thanks!
2 Posted by espanae on 05 May, 2015 02:48 PM
Thanks Ryan. That did the trick.
I'd been following the example in Cascade Server Hidden Gems Series: The Velocity Tool Edition, where it states that the getStructuredDataNode methods expect an XPath expression for which Structured Data Node(s) you want to reference. Perhaps that should say path instead of XPath to avoid confusion.
Also, could you provide a brief example of how to use the class method or property returned by:
3 Posted by Ryan Griffith on 05 May, 2015 02:58 PM
Hi Erik,
Definitely a good point there on the wording. I'll see if we can make an adjustment to the blog post.
Regarding the property
Class
, I don't think there is anything truly useful there. Because the returned value ofgetStructuredDataNodes
is an array ofStructuredDataNode
objects, you would want to output the properties of one of the array's elements:Please let me know if you have any questions.
Thanks!
4 Posted by Wing Ming Chan on 05 May, 2015 03:05 PM
Hi Erik,
The Java
Class
class is related to Java reflection. In fact, this is the key to Java programming in Velocity. If you are interested in this topic, see Java Programming in Velocity.Wing
5 Posted by Wing Ming Chan on 05 May, 2015 03:29 PM
Erik,
I also want to bring your attention to the similarity between web services and Velocity in this area. I have been talking about fully qualified identifiers in a structured data object. When you access a node using web services, you plug in such an identifier. In Velocity, it is almost exactly the same. Every time when you see ";0" or ";1" in an identifier, you need to used get(0) or get(1) to get the node. I hope that you know what I am talking about.
Wing
6 Posted by espanae on 05 May, 2015 05:31 PM
Guys, thanks for clarifying about Class.
Wing, I do remember you talking about fully qualified identifiers but ";0" or ";1" doesn't ring a bell. Are those web services references?
7 Posted by Wing Ming Chan on 05 May, 2015 05:43 PM
Erik,
The notion of fully qualified identifier is one of my inventions in my web service library used to deal with data definition and structured data. Such an identifier can be used to uniquely identify a field in a data definition or a node in a structured data. The digital part of such an identifier signifies the absolute position of a node in a set of nodes in a structured data, instantiating the same field in the corresponding data definition. For detailed discussion, see DataDefinition, and Working With Fully Qualified Identifiers.
Wing
8 Posted by espanae on 05 May, 2015 07:32 PM
Thanks for the links, Wing. I'll check them out.
espanae closed this discussion on 05 May, 2015 07:32 PM.
Wing Ming Chan re-opened this discussion on 06 May, 2015 03:09 PM
9 Posted by Wing Ming Chan on 06 May, 2015 03:09 PM
Here are two pages documenting structured data and metadata with respect to Velocity, with class API and example code:
Structured Data
Metadata
Wing
espanae closed this discussion on 11 May, 2015 03:32 PM.
espanae re-opened this discussion on 12 May, 2015 01:59 PM
Ryan Griffith closed this discussion on 12 May, 2015 02:11 PM.
espanae re-opened this discussion on 12 May, 2015 04:15 PM
10 Posted by espanae on 12 May, 2015 04:15 PM
I can't figure out the syntax to read the value of a checkbox-item (same data definition). I got as far as the parent node but don't know what to append to that?
I also tried:
#if ( $announcement.getChild("active").value == 'Yes' )
and that doesn't recognize when the box is checked either.Here's the page XML:
Any help would be much appreciated!
11 Posted by Wing Ming Chan on 12 May, 2015 05:30 PM
Hi Erik,
Since you are working with a checkbox,
textValue
won't work andvalue
is not even an identifier. You have to usetextValues
, which is a String array. You need to check if the array contains elements, and if it does, whether it contains "Yes". Of course you can also check the size of the returned array. If the size is larger than 0, then it must contain "Yes" (because this is the only option). Note that when "Yes" is checked, the size is actually 2, not 1. (textValues[0]
stores an empty String).So you want something like this:
To actually get at the value, you need something like
$announcement.getChild("active").textValues[1]
, assuming the array is not empty.Wing
12 Posted by Wing Ming Chan on 12 May, 2015 08:01 PM
Erik,
I have been reading the posts in Velocity and it suddenly dawns on me that you are mixing two things:
Velocity can be used to transform block data (page data is from the calling-page index block). This assumes that we are dealing with block XML directly (through the
JDOM
object$contentRoot
) and not using locator tool or$currentPage
. Here you will see elements like <value> (as shown in you page XML). Thisvalue
element has nothing to do with$currentPage
. Here we are dealing with raw XML. The methods you can use are those provided in org.jdom.Element. For example,Element.getValue()
.Velocity can be used alone without any block data. In this case, we can use the
$_
(theLocatorTool
object) to look for a page or a block, or use$currentPage
to access the page. When$currentPage
is used, you are dealing with a Java object, specifically, aPageAPIAdapter
object. When you deal with Java objects and callgetStructuredDataNode
, you need to stick with the API.I assume that you are not working with a block. But when you post the page XML, you are still mixing the two, because the page XML does not help at all when dealing with
getStructuredDataNode
. The raw XML is not available to the Java object. And if you check the API documentation, there is nogetValue()
method orvalue
property inStructuredDataNode
.Your data definition does help though. I looked at the definition and figured out the structure of the structured data object.
Wing
Ryan Griffith closed this discussion on 03 Jun, 2015 05:53 PM.