I am exploring a new interface for our JSF portal and am considering Angular2. I want to gradually migrate certain components in a page from JSF to Angular2 / REST. I don't want to use Angular2 for routing, at least not yet, and I don't want Angular to completely capture the page: some components should still be JSF for the foreseeable future.
Ideally, I would wrap the contents of the body of my JSF template with my Angular root component and project the HTML processed by JSF into the root component, so that JSF still works and any Angular components inside the template are matched and everyone can communicate. For instance:.
<h:body> <my-app> <h:panelGroup styleClass="languageSwitcher"> <h:form> <h:selectOneMenu value="#{languageHandler.language}" onchange="submit()"> <f:selectItem itemValue="en" itemLabel="English" /> <f:selectItem itemValue="nl" itemLabel="Dutch" /> </h:selectOneMenu> </h:form> </h:panelGroup> <my-angular-component data-source="/rest/mydata"></my-angular-component> </my-app> <h:body>
With Angular 1, I would use a transition to make this work. However, as I understand it, Angular 2 content projection does not work on the root component , since the rendered HTML is not considered an Angular-compiled view.
I also considered using the root component of templateURL to dynamically display a page processed by JSF, but this is difficult to implement and does not work very well with the many POSTs that JSF does.
The only way I can do this work is to make the root component of each Angular component that replaces the JSF bit, and on each page load all the components that I use. The disadvantage here is that I need a lot of template code to load every Angular component that I create, and they don't have a common root component, so the connection between them is limited. In addition, I need to configure each Angular component through attributes, but since these are not automatically selected either , I will need to add custom code for each component to pick them up:
class MyAngularComponent { constructor(public elementRef: ElementRef) { this.dataSourceUrl = this.elementRef.nativeElement.getAttribute("data-source"); } }
Then, when I finally replaced the entire interface with Angular, I had to reorganize each component again to use @Input instead of manually extracting information from the attributes.
Does anyone know a better way to do this? Or are JSF and Angular2 just not mixing well?