In earlier versions of JDev, skins have been created either by pure code or by using the free Skin Editor. However, since JDev 12.2.1.x the skin editor has been integrated into JDeveloper itself.
A couple of questions in the ODC JDeveloper space are about how to create a skin with JDev which can be deployed as a shared library to a WebLogic Server. I gave this a try and it turned out, that you can build an ADF library jar from a skin project but you can’t use images to this jar which you might want to use in the application.
In this blog, I’ll show how to create a skin with resources like images and how to build a jar file from the skin together with the images and deploy it aa s shared jar to a WeblogicServer.
Building a skin project
The first part is to build a small skin project. The project we use to create a minimal skin, just to show that the skin is changing something. Then we add some images to the skin which we want to use in the application which uses the skin. Such images can e.g. used on an af:button component.
We start by creating a new application as an ‘ADF Fusion Web Application’
As we don’t need the created model project we delete it completely
If you get another dialog, telling you that you can’t undo the action, answer ‘Yes’ to delete the project. Now you should see a workspace with just the one project:
Know that we have a project we add a skin and e.g. add some skin selectors to change to the color of the button text. For this, we right click the ‘Web Content’ folder in the project and select ‘New from Garaly’ and then select ‘ADF Skin’ from the ‘JSF/Facelets’ node and fill in the basic information:
This will create the needed css file and the descriptors which define our skin (trinidad-config.xml and trinidad-skins.xml).
We open the sharedskin.css file if it’s not open already and switch to source mode. Here we add two simple skin selectors
which are changing the color of the text of a button and a link. You can add more sophisticated selectors but for this blog, it’s enough to show the working skin. To make it more interesting, and because that’s the real reason for this blog, we add some images to the skin which we like to use in the application using the skin. We add the images into a new folder like shown below
The reason for this structure is, that to read the images from the jar in the consuming application, we need a special resource loader. In case of ADF it’s the resource servlet which listens to the URL pattern ‘/adf/’’. This servlet is installed automatically for ADF Web Applications and is configured in the web.xml file
The final task for the skin project is to create a jar file which we can use in other applications. The easiest way to get such a jar is to create an ADF Library deployment descriptor. Open the project properties of the skin project and select the ‘Deployment’ node
And click the ‘New Profile’ icon, select to create an ADF Library Jar
and click ‘OK’. The remaining dialogs you can just click ‘OK’ or ‘Finish’.
To create the library we have to execute the descriptor by right-clicking on the project and selecting ‘Deploy’ and choosing the ‘sharedskinadflib’
This will create the jar in the ‘deploy’ folder of the project.
Sharing the skin with other applications
To share the skin with other application we can
- Create an ADF Library
- Add this library to the other application
- Add this library as a shared library to a WebLogic Server
- Create a normal jar
- Add this library to the other application
- Add this library as a shared library to a WebLogic Server
For this blog, we want to use option 2b. This allows to create the skin once, deploy it to a server and use it in every other application. In the next paragraph, we try out option 1a to show the problems when reading resources from a jar file.
Using a shared skin
Option 1a
We start with option 1a, just to show the problem when we try to read a resource from a jar. We build another ADF Fusion Web application and add the skin as ADF library from a ‘File System Connection’ which we create and let it point to the ‘deploy’ folder
Right-click on the ‘sharedskinadflib’ and add it to the new sample project. This will make the skin available to the application. To use the skin we have to add a skin to the application like we did to create the skin project. The difference is that we now choose the shared skin as the base skin
Creating a new page and adding a button and/or a link to the page we see the new style introduced by the ‘sharedskin’
So, the shared skin is working. Well, yes, but what about the images we added to the ‘sharedskin’?
Let’s try to add one to the button. In the property editor, we select the icon property of the button and click ‘Edit’ to get
However, we don’t see any image in the whole project. As we know where we put the images (or we can look into the sharedskinadflib) we can just add the path to the image like ‘skins/sharedskin/adf/images/home.png’ and we see the image
Running the application we get the page with the button but don’t see the image
Using DeveloperTools we see that the resource couldn’t be found. Inspecting the button element we see
The path to the image is not found 😦
If we change the address of the image to ‘/adf/images/home.png’ to use the resource servlet we still get an error
The reason is that the resource servlet expects the resources in a different path inside the jar. Every resource which should be read from a jar should be in a folder named ‘META-INF’.
The ADF library did not put the images into the META-INF folder
The problem is that we can’t change the layout of the ADF Library. When you create an ADF Library there is no option to make any changes to the content of the jar.
The conclusion is that using a skin in an ADF Library is problematic if there are other resources which you need to share.
To be continued…
In the final part 2 of the series, we see how the skin can be shared with other applications.