Accessing Component inside a component - aem

I have created a page which is of type cq:page. I have a component under the jcr:content node of this page as nt:unstructured type and points to the component location in apps.
I have hardcoded a component inside this component. Now, I'm unable to access the nodes in the second component. I need to set properties of the nodes (in the second component) using the ResourceResolver — how do I access the nodes in the second component?

Because you're hard-coding component B inside of component A, you can also statically define its path relative to A.
Presumably, you're using <cq:include> to embed component B inside of component A.
Two of its possible attributes are the path and resourceType. Path in this case is the relative path that the included component will have when created.
So if the JSP for component A contains:
<!--Some component A content here -->
<cq:include path="inner" resourceType="myProject/components/content/componentB"/>
<!-- Some more component A content -->
Any time a node with a resource type of "componentA" is created, it will create a child node with a relative path to component A of "inner" (with a resource type of componentB).
I.e. if the outer component in your case is at /content/mysite/mypage/jcr:content/componentA, then the inner component will be at /content/mysite/mypage/jcr:content/componentA/inner, given the code above.

Related

E4 contribute with a shared element

My application is built from multiple plugins/model fragments. I am trying to contribute with a shared element (a part) in one of my fragments. I don't have access to the main e4xmi file (the one that contains the Trimmed Window) so it has to be done within my fragment. Any way I can do this ?
In your fragment.e4xmi just add a Model Fragment specifying the id of the parent Trimmed Window as the 'Extended Element ID' and 'sharedElements' as the 'Feature Name'. Add your part to the
Something like:

Bind form field to an object after ngInit has run angular 2 in reactive forms

We are using a component that contains a form. We don't want to bind the fields to any specific model at initiation because we want to be able to use it against multiple interfaces.
We are using it as a multiple instance component in a parent componen, like the following example:
<component>
<foo1></foo1>
<foo2></foot2>
<component>
Assuming that the foo subcomponents contain a form with the field Name
From the parent component, we would like to bind (for example) the Name field in foo1 to object.foo1.form.name and object.foo2.form.name
But this has to happen in the ngAfterViewInit event.
The API says that there is a model property on the formcontrol directive. But can you access that property after post ngInit? If so, how?

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.

Access jcr:content propeties from page node

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");

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.