Trouble extending an AEM component - components

I'm trying to extend a component, but my new marquee.html updates aren't rendering on the page. The dialog updates are okay. Here's what I have:
Parent component
marquee
> _cq_dialog
> clientlibs
_cq_editConfig.xml
.content.xml
marquee.html
Child component
marquee2
> _cq_dialog (All these updates are working.)
.content.xml
marquee.html (None of these updates are rendering.)
Shouldn't any changes in the child component's marquee.html file override the parent file? I've been researching to see if I missed a step and everything seems to be in order, but apparently I'm missing something.

In the child component, the "marquee.html" file should be renamed to "marquee2.html" since the component node is named "marquee2".

Related

JSF custom component

I have a legacy code that I am about to rewrite. It contains a lot of custom JSF components. Most of them simply builds a subtree of other components (either from JSF core or other customs) in place when they are in the tree. So for example in xhtml I have:
<custom-component atributes...>
<child-component/>
<child-component/>
</custom-component>
And then in PostAddToViewEvent implementation of this component does for example something like:
UIComponent rootChildElement = JSFUtil.findAncesstorOfType(this, HtmlForm.class);
List<UIComponent> guiListChildren = this.getChildren();
if (rootChildElement == null) {
rootChildElement = new HtmlForm();
} else {
rootChildElement = new UINamingContainer();
}
rootChildElement.getChildren().addAll(this.getChildren());
But during debugging I have noticed that when JSF processed an AJAX request for such custom component, that even though children are added to the created form, they are built again from XHTML page and added again. This results in those children being actually in two places in the tree when AJAX is performed.
Funny thing that this works in JSF 2.0.3, but when we wanted to upgrade to JSF 2.1.something it stopped working, because command link in the children which was AJAX source could not be found in the tree when it is expected to be.
I think it should be possible to do the same thing in PreRenderView phase, but then actions won't work, because command components will be created too late.
How such components should be implemented:
composite component
facelet tag
tag decorator?
something else?
Is it safe to modify component tree here? If I have a component, that do not reassign children, but adds some new items to itself like command buttons or other components?

Angular 2 - transclude in child component

I've a tree-view component (which uses a tree-view-item component) and I want to let the user to define the template of the items.
something like this (which would display "Item:" followed by the name in bold) :
<tree-view
[children]="folders"
childrenProperty="children">
<template>Item:<b>{{item.name}}</b></template>
</tree-view>
I can retrieve the TemplateRef using #ContentChild in the TreeView component class and access it from the TreeViewItem component but I've not found how to inject it into the dom of the item.
You can fin a Plunker on my tree-view component here : http://plnkr.co/edit/IMqKV4TrwHoiWfJKHHQn?p=preview
Is there a way to achieve this using Angular 2 ?
After lot of digging, I've found no way to achieve exactly what I wanted.
A workaround is to load (using DynamicComponentLoader) a given component (in input) for each item of the tree.
<tree-view
[children]="folders"
childrenProperty="children"
[itemComponentClass]="itemComponent">
</tree-view>
Where itemComponent is a reference to the class of the component (which have a template).
Not the better way but it's working : http://plnkr.co/edit/96IWGkw3owtUWfuG299V?p=preview

SSJS onClick action will not fire on XPage

I found this question, but it does not appear to be resolved, and I also have more to add.
First off, the linked question defines pretty much the same issue that I am having.
1. I am using the application layout control from the ExtLib
2. It does not matter if the button is in that control or not.
3. CSJS actions will fire from the button, SSJS actions will not fire.
4. No errors are present
5. Browser / cache is irrelevant as the server side action just will not fire.
After seeing the linked question, I looked in the Local file in the package view and found an anomaly that makes me wonder if it could be the cause. I have never seen such a file before and even looked in my other xpage projects just to be sure.
This file cannot be deleted, and when clicked upon, the display window says that the element does not exist.
Does anyone know what this file is, how I can remove it, or could it be that my application is corrupted?
**More Info **
The following snippet is copied from the java file for the XPage located in the Local directory. Everything looks fine to me.
private UIComponent createEventHandler(FacesContext context,
UIComponent parent, PageExpressionEvaluator evaluator) {
XspEventHandler result = new XspEventHandler();
String sourceId = "button2/xp:eventHandler[1]/xp:this.action[1]/text()";
MethodBinding action = evaluator.createMethodBinding(result,
"#{javascript:view.postScript(\"alert(\'server script fired!\')\");}",
null,null, sourceId);
result.setAction(action);
result.setSubmit(true);
result.setEvent("onclick");
result.setRefreshMode("complete");
return result;
}
EDIT
Moving all of the design elements into a new .nsf so that file is no longer present does not change the problem of the SSJS onclick action not firing. That strange file is however not present.
Is it failing on a converter / validator? That can cause it to skip out of the lifecycle before Invoke Application phase. To test whether a button is actually working, you can also use "Do not validate or update data". Then the SSJS runs in Apply Request Values phase. If the SSJS is triggered (you won't have the latest data from the browser in the data model or components though), then it's another good bet for converter or validator failure.

A few questions reagarding UI components state and phases

Having gone through these excellent posts:
Why JSF saves the state of UI components on server?
Why does JSF save component tree state?
and midway the JavaEE6 tutorial I still have the following questions:
When I am developing a custom UI component whose values (styleClass, value, etc) are either defined statically(in the xhtml) or set via a bean, do I need to explicitly save/restore state in the extended component as well?
Is it correct to say that the scope of the UI components is view scoped?
How is the view identified behaviour? (If I navigate away from a view, the view gets rebuild the next time around. But if I open another tab, it is restored - at least the bean!)
When I am executing an Ajax call, I would expect that 'execute' part of the UI component would be restored&processed and the 'rendered' part would be restored&updated. After running into some problems with UI:repeat, it is not clear to which extend the component tree is to be restored and if is possible to partially edit.
As an example (I am not sure that it works like this): I define a UI:repeat that iterates over some values and creates some Ajax commandlinks. Whenever I call the command, it will restore the whole ui:repeat regardless of the Ajax scope (execute/render) that I have defined. So it will re-render the whole ui:repeat. Furthermore, I don't understand how it could ever -not- restore the ui:repeat as due to being a namingcontainer it will edit the id of my newly added component.
How can I define a build-time component (vs render-time) and why would I want to do this? (It seems that build time components are troublesome when mixed with rendertime, so why have both)
Thanks
When I am developing a custom UI component whose values (styleClass, value, etc) are either defined statically(in the xhtml) or set via a bean, do I need to explicitly save/restore state in the extended component as well?
Yes. You normally use StateHelper for this.
See also:
How to save state when extending UIComponentBase
JSF custom component: support for arguments of custom types, the attribute setter is never invoked
Adding Custom Attributes to Primefaces Autocomplete Component in JSF
Is it correct to say that the scope of the UI components is view scoped?
Absolutely not. UI component instances are request scoped. Only anything which is stored via StateHelper is in essence view scoped (and restored into newly created component instances during "restore view" phase).
See also:
JSF composite component - weird behavior when trying to save state
Backing bean in composite component is recreated on every request
How is the view identified behaviour? (If I navigate away from a view, the view gets rebuild the next time around. But if I open another tab, it is restored - at least the bean!)
It's likely requested from browser cache. Try submitting a form therein. The chance is big that you get a ViewExpiredException. You need to tell the browser to not cache dynamic pages. Putting a breakpoint on bean's constructor would also confirm that it's never been invoked.
See also:
Avoid back button on JSF web application
Is JSF 2.0 View Scope back-button safe?
javax.faces.application.ViewExpiredException: View could not be restored
When I am executing an Ajax call, I would expect that 'execute' part of the UI component would be restored&processed and the 'rendered' part would be restored&updated.
This is not true as to restore part. The "whole" view state is restored. Note that the view state does since JSF 2.0 not necessarily represent the entire component tree. You've found the explanation/answer to that already in the two links mentioned in your question.
How can I define a build-time component (vs render-time) and why would I want to do this? (It seems that build time components are troublesome when mixed with rendertime, so why have both)
This is called a "tag handler". I.e. just extend from TagHandler instead of UIComponent and implement according its contract. Tag handlers are useful if the sole goal is to build the view (the JSF component tree). They do not appear in the JSF component tree. As to when to create a custom component or a custom tag handler, check the "components" and "taghandlers" sections of OmniFaces showcase, it may give some new insights as to real world use cases of those things.
See also:
Custom Facelet component in JSF
JSTL in JSF2 Facelets... makes sense?

How to programmatically generate JSF components at run time?

I've got to create screens to display a lot of JPA entities in the View. It would be great to create one facelet and pass to it a collection of fields e.g. List<Object>.
The facelet/custom component would need to convert each element of the list into the appropriate tag for display e.g. an enum field to h:selectOneMenu, String field to h:inputText, etc. This would need to be done at run time.
What's the easiest way to do this?
Worked on a project previously that created entire pages dynamically from stored configuration. There are two basic things you need
A BackingBean. You'll used this to get access to the UIComponent on the facelet which will act as the parent to the generated UIComponents. Something like a panelGroup. But, you'll need to bind the UIComponent to the backing bean, in order to have a parent against which you'll add the dynamically-created UIComponents
Access to the Application component. Typically FacesContext.getApplication() (I worked on this in JavaEE 5, so it might look a little different with injection). Once you have the Application component, you call the createComponent method, passing in the type of component you want to create.
It then becomes an activity of creating components dynamically, configuring them in code and adding them to the parent UIComponent defined via a binding bean. It can be tricky, but it can be done.

Resources