This tutorial shows you how to create a custom skin (.css file) to change the look and feel of an application.
show more or lessRead more...

We assume, for this tutorial, that JDeveloper 11g (11.1.2.) is installed and that you have access to an Oracle database with the hr schema created.

Your final application should look like the following:

The final Application running in your browser

Purpose Duration Application
In this lab, you learn how to create a custom skin (css file) for an application and see how the changes you make to the skin affect the look and feel of the application. 45 minutes Download the solution Application
Step 1: Getting Started
  1. Download the ADFSkin zip file. Right click this icon alt text and choose Save Target As... from context to download the adfskin.zip file to a local directory of your choice.

  2. Unzip the adfskin.zip file to a local directory of your choice (i.e. labs)

  3. Start JDeveloper by selecting Start > All Programs > Oracle Fusion Middleware 11.1.2 > JDeveloper Studio 11.1.2

  4. If prompted for a Role, choose Studio Developer (All Features) and click OK.

    Select Role startup dialog
  5. Close the Tip of the Day window.

  6. Once loaded, the JDeveloper IDE appears. Show more or lessRead more...
    The very first time you open JDeveloper, the Start Page displays. You can re-invoke the Start Page later by choosing Help | Start Page.

    JDeveloper default startup IDE

    Notice the various options available to help you learn about JDeveloper. After exploring these options, click the X on the Start Page tab to close it. (the X appears when you mouse over the tab).
  7. Click the Open Application link in the Application Navigator.

    From the predefined application you downloaded, you create a new ADF Skin file (.css) to modify the look and feel of the sample application.

  8. In the Open Application dialog, select the file C:\labs\ADFSkin\ADFSkinSample\ADFSkinSample.jws and click Open.

    The Open Application(s) dialog

    If you are prompted to migrate the project, click Yes to confirm.

  9. Once the application is loaded in JDeveloper, check the database connection. Right-click the Model node and select Project Properties from context.

    The Open Application(s) dialog
  10. In the Project Properties dialog, select the Business Components and if required click Load Extension to load the appropriated library files.

    Project Properties option
  11. Next to the Connection field, click the Edit icon The Edit icon to review the connection parameters.

    Project Properties option
  12. In the Edit Database Connection dialog, type the following values. Note that the values provided here as example may need to be modified to work with your environment.

    Property Value
    Connection Name hrconn
    Username/Password hr / <your hr password>
    Save Password Checkbox checked
    Driver Thin
    Host Name The machine where the schema is installed (e.g. localhost)
    SID The database where the HR schema is installed (XE, orcl...)
    The Open Application(s) dialog
  13. Your application needs to be able to communicate with the database. Show more or lessRead more...A database connection has been created in the startup application, but you need to check that the values are appropriate for your environment.
  14. Click Test Connection to confirm that you can connect.

    The Edit Database Connection dialog C
  15. Click OK if the connection was successful. Show more or lessRead more...
    If the connection fails, check that the parameters entered are correct and that the Oracle database and listener services are running.
    The connection should also appear in the Initialize Business Components Project page.
  16. Expand the Model project node to review the Business Components created for this application. The Application Navigator should look like the following:

    The Model hierarchy in the Application Navigator
  17. The Model project node contains all the data model Business Components needed for your application. Show more or lessRead more...

    Entity objects, view objects, foreign key links, foreign key associations and application module. The application module serves as the Data Control provider, allowing data bindings between your pages and the database. An application module is an ADF Business Components component that encapsulates the business service methods and UI-aware data model for a logical unit of work related to an end-user task.
    Collapse the Model node.
  18. Now expand the ViewController node and feel free to navigate through the nodes to review the existing components.
    The Application Navigator should look like the following:

    The ViewController hierarchy in the Application Navigator

Step 2: Creating a New ADF Skin and Reviewing Skin Configuration

An ADF skin is a type of CSS file where you define CSS style properties based on the Cascading Style Sheet (CSS) specification for the component for which you want to customize the appearance.
  1. In the Application Navigator, Right-click the ViewController project and select New from the context menu.

    The New option on the ViewController project
  2. In the New Gallery, expand the Web Tier node, select JSF/Facelets and in the right hand pane, select ADF Skin as the item.

    The New Gallery dialog with JSK/Facelets | ADF Skin selected.

    Click OK.

  3. In the Create ADF Skin File dialog, change the file name to MyNewSkin.css. Append \MyNewSkin to the existing skins directory path. Check the Use as the default skin family for this project checkbox and in the Extends field choose to extend the fusionFx-simple-v2.desktop skin from the list of values.

    Click OK.

  4. Oracle ADF provides a set of ADF skins that you can extend... Show more or lessRead more...
    The new skin file appears in the Application Navigator under the Web Content | skins | MyNewSkin nodes.

    The skin.css file in the Application Navigator
  5. MyNewSkin.css opens by default in the design editor with a selector tree of components that you can navigate to. When you navigate into the component, the preview will be updated with a view of that component.

    The Skin Navigator in the design pane.
  6. If you click the Source editor tab, you will see that you have a new empty skin file. Show more or lessRead more...


  7. Scroll down in the Navigator to locate the Home.jspx entry. Right-click and select Run from context to launch the page in the Firefox browser. This verifies that your application is running and has the look and feel of the skin you have extended, which is fusionFx-simple-v2.desktop. This is because you have not yet made any changes to your skin file to override the fusionFx-simple-v2 look and feel.

    Shows the Run option from context.
    Note that after a fresh install of JDeveloper, the first time you deploy your application, you need to create a default domain for WebLogic server. Show more or lessRead more...

    In the Create Default Domain dialog, type an 8 digits password of your choice and confirm it.

    alt text

    Click OK.
  8. While your page is being loaded, expand the WEB-INF node and double-click trinidad-skins.xml to open it in the editor.

    Shows the trinidad-skins.xml file in the Application Navigator nodes
  9. The trinidad-skins.xml file is a registry file of all custom skins available to an application. Show more or lessRead more...
    The file doesn't exist by default as it is not needed when using the Oracle look and feel.
  10. The source shows that your skin file, MyNewSkin has been added to other existing skins. These skins are registered skins and available for use by your project.

    The xml code for MyNewSkin.
  11. Click the cross on the right hand corner of the current tab to close the editor. Show more or lessRead more...
    Shows closing a tab
  12. Double-click the trinidad-config.xml file. It shows that the current skin for your application is MyNewSkin, the skin you just created.

    The xml code for trinidad-config file

    Click the cross on the right hand corner of the current tab to close the editor.

  13. The family name is used to configure the custom skin that is applied to the running application. Show more or lessRead more...
    This can be done as a static configuration or dynamically using Expression Language. To conditionally set the value, enter an EL expression that can be evaluated to determine the skin to display. For example, if you want to use the German skin when the user's browser is set to the German locale, and to use the English skin otherwise, you would have the following entry in the trinidad-config.xml file:
    <skin-family>#{facesContext.viewRoot.locale.language=='de' ? 'german' : 'english'}</skin-family>
  14. Switch to the Firefox window, now the Home page should be loaded in the browser.

    The page running in your browser.
  15. From the main menu toolbar, select View > Firebug.

    The Firebug option in Firefox.
  16. An easy way to find the CSS class is by using a free add-on for Mozilla Firefox called Firebug. Show more or lessRead more...
    Firebug is a convenient tool for web development allowing debugging, editing, and monitoring CSS, HTML, JavaScript and Net requests in any web page.

    To install Firebug, in Firefox, select Tools | Add-ons from the Firefox menu and type firebug in the search field. (Download, install and reload firefox).

  17. Move the Debug pane at the bottom of your page to make it visible. It should display the HTML tab by default.

    The debug tool for html source code.
  18. In the right hand pane, the Style tab shows that you're using MyNewSkin . Hover over the MyNewSkin link, it displays the location of the skin file used. Confirm that it is the one you've added to your application.

    Link pointing to the source file.
  19. Notice that for now, the look and feel of the page is still using the default fusion style. Show more or lessRead more...
    It uses the default fusion style since you haven't yet made any changes to MyNewSkin to extend it with new properties.
  20. From the main menu toolbar, re-select View > Firebug to hide the Debug pane.

    Turning off the Firebug option.
  21. Return to JDeveloper without closing the browser window.

Step 3: Changing the UI - Page Background and Font Family
The ADF skin defines rules that determine how to apply CSS style properties to specific components or groups of components.
  1. In the Design editor of MyNewSkin, select the Faces Component Selectors > Document > af|document entry.

    Calling the Edit dialog for the Background field.
  2. In the Property Inspector (use View | Property Inspector from the main menu if the pane is not visible), change the background color for a yellowish one. Click the down arrow at the right of the Background Color field and select Edit.

    Calling the Edit dialog for the Background field.
  3. In the Background Color dialog, type #fcfacb in the RGB Hex filed.

    Background colot property dialog.

    Click OK.

  4. Using the drop down list, set the Background Image property to none.

    Changing the Backgroung image to none.
  5. Click the Save All button alt text in the toolbar to save your work.

    Changing the Backgroung image to none.
  6. Switch to the Firefox window and reload the page.

    Reloading the page in the Firefox browser
  7. Notice the change of the background now reflected in your browser.

    The new UI for the application.
  8. You are now going to change the font of the application text.
    Without closing the browser window, switch back to JDeveloper and in the Skin editor, expand the Global Selector Aliases | Font nodes, and select the .AFDefaultFontFamily entry.

    The Skin editor.
  9. Each category may include one or more of these types of ADF Faces skin selectors. Show more or less Read more...
    Standard selectors are those that directly represent an element that can have styles applied to it. For example, af|body represents the af:body component. You can set CSS styles, properties, and icons for this type of element.
  10. In the Property Inspector in the Font/Text section, from the drop down list on the Font Family attribute, select Times New Roman.

    Changing the Font Family.
  11. In the Navigator, select the .AFDefaultFont:alias.

    The Skin Navigator.
  12. The :alias pseudo-class is a special type of class that serves as a syntax aid to organize code in your skin file. new app Show more or lessRead more...
    You can, for example, use it to set styles for more than one component or more than one portion of a component. You can also create your own alias classes that you can then include on other selectors. For example, you can define an alias pseudo-class (.AFLabel:alias) where you define label colors for a number of form components. Subsequent changes to the alias pseudo-class impact all components referenced by the alias pseudo-class.
  13. In the Font/Text section, set the Font Size to 12 px.

    The Font Size property.
  14. In the Line Box section, set the Line Height to 18 px.

    The Line Height property .
  15. Click the Save All button The Save All icon. in the toolbar to save your work.

  16. Switch to the browser window and reload the page.

    The UI of the application before reloading the page.
  17. Notice the font changes in the page.

    The new UI in the browser.

    Don't close the browser window. You are now going to make changes to the look and feel of the Panel Header.

  18. Switching back to JDeveloper, collapse the Global Selector Aliases node and in the Faces Component Selectors, expand the Panel Header | Pseudo-Elements nodes and update three of the components. Select the title0 node.

    The Skin Navigator.
  19. Pseudo-elements are used to denote a specific area of a component that can have styles applied. Show more or lessRead more...
    Pseudo-elements are denoted by a double colon followed by the portion of the component the selector represents. For example, af|chooseDate::days-row provides the styles and properties for the appearance of the dates within the calendar grid.
  20. In the Property Inspector, for the title0 component set the Background Color to #fff27e. (Enter the value and press Return)

    The Background Color property.
  21. Set the title-text0 > Font/Text > Color component to Red.

    The Color field.
  22. Set the content0 component to the following properties:

    Section Property Value
    Common Background Color White (from LOV)
    Common Border 1px solid
    Common Border Color #fff27e
    The new propertie values.
  23. The new rendering in the design editor should display like this:

    The Skin rendering
  24. Click the Save All button in the toolbar to save your work.

  25. Reload the page in Firefox.

  26. Notice the changes in the UI. Also observe that only the Home tab is selectable at the moment. You need to login to make other tabs accessible.

    The page after reload.
Step 4: Updating the Look & Feel for Table Headers and Links
  1. To see the current look and feel of the table headers, you need to login to the application. Click the Login link.

    The Login link
  2. In the Login dialog, enter sking/Welcome1234. and click OK.

    the Authentication dialog.
  3. The tabs are now selectable. Click the Employees Overview tab.

    The page in the browser.

    Notice the rendering of the Employees table headers.

    The Employees Overview tab.
  4. In the next few steps, you are going to change the headers of the table to yellow with red font.
    Switch back to JDeveloper. In the Faces Component Selectors, collapse the PanelHeader node and expand the Column | Pseudo-Elements node and select the column-header-table entry.

    The Skin Navigator in JDeveloper.
  5. In the Property Inspector, in the Common section set the following properties:

    Property Value
    Background Color #fff27e
    Background Image none

    Changed properties.
  6. In the Font/Text section set the Color attribute to Red from the drop down list.

    hanged property.

    The rendering pane should look like the following:

    Skin rendering.
  7. Click the Save All button Save All icon. in the toolbar to save your work.

  8. Reload the page in Firefox.

    Reload menu option in Firefox. 
  9. Click the Employees Overview tab and notice the changes in the table headers.

    The Employees Overview tab.
  10. You are now going to change the look and feel of the links in the panel list. Observe the panel list under the Welcome to Our Site message. Hover your mouse over the hyperlink text, and note that then the text becomes underligned.

    The Home hyperlink.
  11. Switch back to JDeveloper, collapse the Column node and expand the Panel List > Pseudo-Elements one. Select the link entry.

    The link component in the Skin navigator.
  12. Notice the two sections in the rendering pane, the top one for link properties and the bottom one for the link hover properties.

    The rendering for the link component.
  13. For the link properties, in the Property Inspector, in the Font/Text section, set the following properties:

    Property Value
    Color Red (from LOV)
    Font Weight bold (from LOV)
    Text Decoration underline (from LOV)

    Font/Text properties for links.

    Font/Text properties for links.
  14. Click the link:hover section in the rendering pane and in the Property Inspector, in the Font/Text section, set the following properties:

    Property Value
    Font Weight bold (from LOV)
    Text Decoration none (from LOV)

    New Propeties for the links.
  15. Click the Save All button Save All icon. in the toolbar to save your work.

  16. Reload the page in Firefox.

    Reload button in Firefox.
  17. Observe the UI changes in the panel list. The links are now red and the underline state works the other way around when hovering over.

    The new UI of the page for links.

 

Step 5: Updating the Pane Body and the Shape of the Tabs

You are now going to change the look and feel of the tabs, using different images for the tab shape, and defining different fonts and colors. For this, you use image files provided with the application.

  1. Don't close the browser window. Switch back to JDeveloper and collapse the Panel List node.

    The PanelList component.
  2. Navigate to the Global Selector Aliases Folder and expand the node Component Group Tabs. (NEW SCREEN)

    The Skin navigator
  3. Notice that there are a lot of existing components to define tabs. Show more or lessRead more...
    Some are for tabs located at the top (Above tabs) and others are for the tabs located at the footer (Below tabs). Each tab has a start, middle and end part. You just want to change header tabs in the application.
  4. Select the AFTabAboveEndSelectedBackground:alias:ltr entry.

    The Skin navigator and the rendering editor.
  5. In the Property Inspector in the Common section, click the right-most down arrow next to the Background Image property and select Edit from context.

    The Background Image field.
  6. In the Edit Property dialog, navigate to skins | NewImages | af_panelTabbed where existing images are already provided and select the t3_above_end_a.png.

    Backgroung Image dialog.

    Click OK. The value should now be:

    Alias component Background Image
    .AFTabAboveEndSelectedBackground:alias t3_above_end_a.png
  7. Repeat the above step for the following End tab parameters:

    Alias component Background Image
    .AFTabAboveEndUnselectedBackground:alias:ltr t3_above_end_n.png
    .AFTabAboveEndUnselectedDisabledBackground:alias:ltr t3_above_end_d.png

  8. You could repeat the operation for the Middle and the Start components. Show more or lessRead more...
    In the next action you will use a prepared file to set the Middle and the Start component values. If you don't use the file, you need to populate the following values:
    Alias component Background Image
    .AFTabAboveMiddleSelectedBackground:alias t3_above_mid_a.png
    .AFTabAboveMiddleUnselectedBackground:alias t3_above_mid_n.png
    .AFTabAboveMiddleUnselectedDisabledBackground:alias t3_above_mid_d.png
    .AFTabAboveStartSelectedBackground:alias:ltr t3_above_start_a.png
    .AFTabAboveStartUnselectedBackground:alias:ltr t3_above_start_n.png
    .AFTabAboveStartUnselectedDisabledBackground:alias:ltr t3_above_start_d.png
  9. To populate the Middle and Start values from a prepared file, in the Application Navigator, locate the readme.txt file and double-click to open it in the source editor.

    The Application Navigator.
  10. Select and copy all the text with the exception of the first 2 lines.

    Selected text in the readme.txt file.

    Close the readme.txt.

  11.  With the MyNewSkin.css file displayed, click the Source tab at the bottom of the editor pane. Scroll down at the bottom of the file to find the first image uses defined, then select all of these related component definitions. Right-click and Paste from context.

    Selected text in the Skin source.
  12. The clipboard text in the file to replace the selected statements.

    The new source content once statements have been copied.
  13. Click the Design tab at the bottom of the editor and select the Panel Tabbed | af|panelTabbed to see the rendering for the new tab definitions.

    The Design of the Skin file.
  14. Click the Save All button Save All icon. in the toolbar to save your work.

  15. Switch to Firefox browser window.

    The page running in your browser.
  16. To be able to see the new look and feel defined for the tabs, you need to press the Ctrl key and click the reload button at the same time (In case the [Ctrl] + [Reload] action does not refresh the page, re-run the home page from JDeveloper). Observe the new rendering of your page. Click the Employees Overview tab to see the look and feel of active versus unselected tabs.

    The Employees Overview info.
  17. Switch back to JDeveloper. Now you need to update the text color of the link in the tabs to better match our styling. Navigate to the af|panelTabbed node and click the Source tab.

    The rendering of the Panel Tabbed
  18. Enter the following statements at the bottom of the code to define the new tab aspect.



    The Skin navigator and rendering.
  19. Click the Save All button alt text in the toolbar to save your work.

  20. Switch back to Firefox.

    The Employees Overview info.

    and reload the page.

    Reload icon in Firefox
  21. Observe the new rendering of your page. Click the Employees Overview tab to see the look and feel of active versus unselected tabs.

    The page in the browser window
Step 6: Implementing Dynamic Skin Change

To be able to implement a Dynamic Skin UI change, perform the following steps:

  1. For this new section, you need to re-deploy the application, so close the browser window this time and switch back to JDeveloper.

  2. In the Log window, click the arrow within the Stop red icon and select ADFSkinSample to stop the running application. Notice that you don't need to stop WebLogicServer.

  3. Now enable the skin drop down list so you can switch the skin dynamically. Do this by updating the trinidad-config file with the reference to the dynamic code. Select the trinidad-config file editor.

    The Application Navigator

    The Source looks like the following:

    The trinidad-config content.
  4. Copy the comment line of code with the skin-family tag, and paste it in place of the active skin-family MyNewSkin tag.


    The trinidad-config content.
  5. In the Application Navigator, double-click the Home.jspx entry to open the page in the Design editor.

    Selecting the Home.jspx node in the Application Navigator.
  6. In the Design editor, click within the panel group layout component underneath myCompanyLogo. This selection highlights the corresponding component in the Structure pane.

    The Home page
  7. Click the Source tab at the bottom of the editor pane. The panelGroupLayout should be highlighted.

    The panelGroupLayout component in the Source of the page.
  8. Notice the commented section.

    The source code.
  9. Cut the end of comment tag (-->) and paste it at the end of the start comment tag line:


    The source code.
  10. Click the Save All button alt text in the toolbar to save your work.

  11. Right click the Home.jspx page and select Run to restart the page.

    The context menu.
  12. The page loads up in the browser window.

    The context menu.
  13. Use the Choose a Skin field and select MyNewSkin from the list of values.

    The page running in the browser.
  14. The new UI is dynamically changed. Use the Choose Skin field and select another Skin flavor from the list (i.e. princess-skin).

    The Skin drop-down list.
  15. The UI is dynamically changed.

    The new rendering in the browser.
  16. Experiment with other look and feel choices from the list.

    Another rendering in the browser.
  17. You've now completed the skin tutorial.

Summary
In this tutorial you saw how to change the look and feel of components such as panels, panel tabs, fonts, table headers and links by creating your own skin (.css file) in JDeveloper. Finally, you updated your application so that the UI can be dynamically changed at run time. You learned how to: To learn more about ADF skins, refer to:

Bookmark Print Expand all | Hide all
Back to top

Did you find this page helpful?



Copyright © 2011, Oracle and/or its affiliates. All rights reserved.