Donnerstag, 24. März 2011

Referencing images when creating reusable templates

If your going to create a template that's exported to a ADF Library JAR to be reusable, you'll get trouble to refer to images within the template.
We might want to add a background image to our beautiful template. So we set a inline style for the first Panel Stretch Layout in our application.

 
<af:panelstretchlayout id="pt_psl1" 
inlinestyle="padding:10px;background-image:url('/oracle/ui/pattern/dynamicShell/images/back.jpg');">
</af:panelstretchlayout>
 
In our design view everything looks nice but after using the template within our application the background image is missing. This is because it's not within our applications directory path at /oracle/ui/pattern/dynamicShell/images/back.img. If you create the structure and put the images there it would be working. But it's against all rules of reusability. So we keep the image within our templates JAR file and refer to it in a different way.
It's quiet simple. Just use
#{facesContext.externalContext.requestContextPath} 
to refer to your image and everything works fine.
 
<af:panelstretchlayout id="pt_psl1" 
inlinestyle="padding:10px;background-image:url('#{facesContext.externalContext.requestContextPath}/oracle/ui/pattern/dynamicShell/images/back.jpg');">
</af:panelstretchlayout>
 

1 Kommentar :

  1. Thanks a lot buddy, You saved a lot of time and effort, and probably i couldnt have figured out the issue if i wouldnt have read this.

    AntwortenLöschen