Recently I did my R&D on how to change Skin of the ADF application at run time using ADF technology stack available in Oracle JDeveloper 11g Preview 4.
In this post I want to describe how I was able to achieve it, with a hope it may come in handy within our Oracle community(skin-adf-sample-application).
First make following changes to trinidad-config.xml
Before Change
After Chaging
Instead of hard coding, I made it dynamic using “sessionScope.skinFamily”.
(With this I came to conclusion that with every time trinidad-config.xml is read before page rendering)
After this I created three button for demo purpose to show how page skin can be changes at run time as follows:
After that I am setting the session variable “skinFamily” based on button press by the user.
Example if user click “blafplus-rich” button then I am doing following things in the button ( backing bean):
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elc = fc.getELContext();
ExpressionFactory ef = fc.getApplication().getExpressionFactory();
ValueExpression ve = ef.createValueExpression(elc, “#{sessionScope.skinFamily}”, Object.class);
ve.setValue(elc, ”blafplus-rich”);
This will set the skin to “blafplus-rich”.
There are some other predefined skin provided by the Oracle which we can set at runtime (or can be hardcoded in trinidad-config.xml)
All my button has same coding except last line which is changes base on the button click (Actually this can be put as a single procedure and can be called with the button, rather then writting whole code in each button).
Special Notes:
Use of “ValueBinding” before JDeveloper 11g for setting the value of session variable
“richDemo” Button Code for backing bean
// Add event code here…
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ValueBinding vbSessionScopeRowKey;
vbSessionScopeRowKey = app.createValueBinding(“#{sessionScope.skinFamily}”);
vbSessionScopeRowKey.setValue( fc, “richDemo”);
Use of “ValueExpression” since JDeveloper 11g for setting the value of session variable
Even though the above piece of code will work in Oracle JDeveloper 11g but will give warning that “ValueBinding” is deprecated.
So now New “richDemo” Button Code for backing bean I changed as follows:
// Add event code here…
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elc = fc.getELContext();
ExpressionFactory ef = fc.getApplication().getExpressionFactory();
ValueExpression ve = ef.createValueExpression(elc, “#{sessionScope.skinFamily}”, Object.class);
ve.setValue(elc, ”blafplus-rich”);
Few Look & Feel of Skins provided by Oracle:
Download Sample Code :: skin-adf-sample-application
6 responses so far ↓
1 viorel // Sep 15, 2008 at 12:39 am
This is a very good example.
How can I set (in a backing bean) the initial skin that will be used when the page load for the first time? I tried using the BeforePhase, but is not working.
Thanks,
Viorel
2 Rajender Singh // Sep 17, 2008 at 6:35 pm
Hi Viorel,
Trying with no success, it giving following error
WARNING: Header modification request was rejected. Because the setter method was called from included servlet. It is restricted by SRV.8.3 of Servlet Specification 2.4.
Let me do some more r&d on it.
If you get anything, please let me know.
Thanks & Regards
Raj
3 viorel // Sep 17, 2008 at 9:49 pm
I got it partial working using the hints from this post:
http://forums.oracle.com/forums/thread.jspa?threadID=706077&messageID=2759867#2759867
I still have some issues with re submit or partial trigger, but at least the initial page will have the required skin.
4 Rajender Singh // Sep 17, 2008 at 10:47 pm
Thanks !
oracle site seem to having some problem today.
Once online I will check it out and will try doing some r&d on it.
Regards
5 Luca // Oct 14, 2008 at 2:18 pm
This sample does not work on JDeveloper 10.1.3.4 ?
6 Rajender Singh // Oct 27, 2008 at 4:22 pm
Hi Luca,
Actually I created this sample in JDeveloper 11g Preview 4.
But didn’t try creating same in previous release.
Thanks & Regards,
Rajender
Leave a Comment