Access jcr:content propeties from page node - aem

I have dropdown where the values of options are like jcr:content/jcr:title, jcr:content/jcr:description, /jcr:content/par/entry/text etc. Here the last one is the property of parent, like jcr:title is the property of jcr:content node & text is the property of entry node, but entry has parent par and par has parent jcr:content. I am at the page node and using the below code to fetch such values which doesn't work :
Node n = (Node)nodeIter.next();
log.info(n.getProperty("/jcr:content/par/entry/text"));
Any Idea how to get values in such a way.
Thanks

Remove the starting slash from the property path. It makes the path absolute while you are interested in the relative one (as in other examples you've described):
n.getProperty("jcr:content/par/entry/text");

Related

Querybuilder | access property for which path is not fixed

Normally I would use filter for property like cq:tags as mentioned below. Here I know where cq:tags property exists in content structure:
group.5_group.fulltext.relPath=jcr:content/#cq:tags
group.5_group.fulltext=*location*
For any page where I can drop any number of component and property is inside component node, how will I add filter for such properties.
E.g. My component name is component and prop is property. Some exmaple path for porp can be jcr:content/mainParsys/component/#prop or jcr:content/mainParsys/componen_anyrandomValue/#prop
group.5_group.fulltext.relPath=what_should_be_the_path_or_filter
group.5_group.fulltext=*location*
Why are you trying to search through path if it's undefined?
You can go with the resourceType of the component as it will remain same and try your query in Query Debugger as:
type=nt:unstructured
1_property=sling:resourceType
1_property.value=my-project/components/content/component
2_property=myprop
2_property.operation=exists
It worked for me to search for a property inside a component.

AEM DefaultValue written to JCR

I noticed that when I set my defaultValue for a dropdown, altho it is correctly selected in the drop down when I first add my component to the page it does not write the defaultValue to the corresponding JCR until I edit the component and save it. Even if I just open the corresponding dialog and click OK now my component works as expected because the values have been added to the JCR.
I am sure there is an important piece that I am missing here, does anyone knows how defaultValues that are required in order for the component to render properly can be added to the JCR when they are first added to the page?
Like Shwan say's that's the way it works. The default values or empty texts are only for the dialog. They aren't persisted until the dialog is authored. The properties have to be set by a different method. CQ already ships with this feature and you can do it without any custom code.
Under your component , create a node called cq:template[nt:unstructured] . If all the data is stored on the component node itself , add the default values as properties to cq:template node with name same as the ones in your dialog. In case the data is stored in a child node add a similar node under cq:template node.
Source : http://blogs.adobe.com/experiencedelivers/experience-management/defaults-in-your-component/
I believe that is simply the way it works. The default value specified in a dialog does not get used until the dialog is loaded/saved, so until that happens the node on the JCR repository that is being authored won't have the default value.
We got around this on a project by adding back-end code that was tied to the component (a tag) so that when the component was loaded, if the property did not exist, it would be written with the default the first time. Ex:
if (wcmMode == WCMMode.EDIT )
{
if(!currentNode.hasProperty("SomePropertyThatWillAlwaysExistIfTheDialogHasBeenSaved")) {
currentNode.setProperty("PropertyThatShouldHaveDefault", GlobalConstants.TRUE);
currentNode.getSession().save();
}
}
Like Sharath Madappa say's that's the way it works fine if component name and jsp name same. If you dont have componentname.jsp under component or page, cq:template won't work.(Reference:http://labs.6dglobal.com/blog/2014-07-08/using-the-cq-template/)
If you hava componentname.html under your component, changed the node [cq:template] type to [cq:Template] instead of [nt:unstructured]. In this case, defaultValues can be added to the JCR when they are first added to the page.

Tridion 2009 - Retrieve Component's parent folder TCM

Quick question. I'm building a Template Building Block (TBB) that retrieves metadata schema values from the parent folder of components. For example, all of the components listed in this folder will share the same title, but have different content. So, I created a schema and attached it to the parent folder. This way, if I want to change the title of all my components, all I have to do is change the metadata value on the folder.
I have this working with the parent folder TCM hard-coded, but, I need to grab this dynamically. Does anyone know how to grab the parent folder's TCM?
Thank you for your assistance.
RepositoryLocalObjects all have a ".OrganizationalItem" property that will return the container for the object.
Something along these lines should get you started:
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
Folder parent = (Folder)component.OrganizationalItem;
ItemFields folderFields = new ItemFields(parent.Metadata, parent.MetadataSchema);

Get parent element name in XPath

I am trying to figure out how to get the name of the parent from a text node's scope.
//text()[name(parent)='p']
How can you get the name of the current node's parent?
If you're trying to test the name, you almost had it:
//text()[name(parent::*)='p']
If you're trying to return the name:
name(//text()/parent::*)
FYI, point of terminology: a text node is not an element.
Anyway, the most succinct way to select the parent of the current node is ..
So, the name of the parent element of the current node (which could be a text node) is name(..)
Substituting that into your XPath expression:
//text()[name(..)='p']
But a less roundabout way to write that would be
//p/text()
(assuming the p elements in the document have no namespace prefix). Either way, you're selecting all text nodes that are children of elements named p.
//text/..[#name='p']
This will get all parents of <text> nodes as long as the parent has a name attribute of p.

Accessing value attribute in Protovis lines

I'm using Protovis Arc layout and I'd like to color links between nodes accoriding to the 'value' property defined in dataset. How can I access it?
Dataset is defined like that:
Nodes:
...
{nodeName:"Books"}
...
Links:
...
{source:1, target:4, value:20}
...
arc.link.add(pv.Line).strokeStyle(function(d) d.value > 10 ? "#cc0000" : "#eeeeee"); - does not work
The d property refers to the node. There's no value attribute defined on the node in this case; the link weights are defined on the links, which is why the property function isn't doing what you expect.
You can rewrite your property function to access the link (rather than node) data. The link data is associated with the link's parent panel, and is available as the second argument:
.strokeStyle(function(d, p) p.value > 10 ? "#c00" : "#eee")
There's more of an explanation in the layout documentation. And see also the pv.Layout.Network API reference:
The link mark is added to a child
panel, whose data property is
defined as layout's links property.
The link's data property is then a
two-element array of the source node
and target node. Thus, poperties such
as strokeStyle and fillStyle can
be overridden to compute properties
from either the node data (the first
argument) or the link data (the second
argument; the parent panel data)
dynamically.