Include HTML page with own Javascript in ADF application (loading Javascript programmatically)

Include HTML page with own Javascript in ADF application (loading Javascript programmatically)

November 20, 2014

I had to include a HTML page in my ADF application. The HTML page contains carousel and has references to javascript files which control it. I’ve found different ways to do this.

Here are some of them:

  –  using jsp:include

– using af:declarativeComponent

– using ui:include

I’ve decided to use the af:declarativeComponent which is placed inside an af:showDetailItem of an af:panelTabbed. So I have added the HTML page. Everything was perfect when I opened it, but after I opened a new tab and returned to the first one – the slider disappeared. After a short research I found that there are two javascript files and the second one is used by the first one, so the first javascript file cannot find a method which is declared in the second one.

I’ve changed the order and the slider started to work in this case but when I pressed over opened tab and returned to the first one with included slider, it didn’t work. Finally, I found that the javascript didn’t load in this case so, I had to load it every time when I open this tab. I made it programmatically. I created a text filed in this page and I used its get method to load the javascript.

Every time I`ve opened the page, the get method is called and executes the code to load the javascript files. Here is the code:

public String getSliderJavascript(){
FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = null;
erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, carouselJS);
erks.addScript(fctx, mainJS);
return null;

public void setSliderJavascript(String s){

private static String getSliderJavascript(String name) {
String path 
= FacesContext.getCurrentInstance().getExternalContext().getRealPath(name).toString().trim();
String script 
return script;

Finally everything works perfectly.

Thank you for reading the blog!
Please leave a comment and if you have a better solution – share it!

Boris Velichkov

Java EE and Oracle Developer

More Posts - Website

Follow Me:

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!