Before You Begin
This 10-minute tutorial shows you how to add a composite
component to the navdrawer starter template of your Oracle
JavaScript Extension Toolkit (Oracle JET) web application. You
learn how to use Oracle JET tooling to create a composite
component named demo-name-badge
that you add to
the Incidents tab of your web application.
Background
A composite component is a reusable piece of user interface that you can embed as a custom HTML element in your web application. Composite components can contain Oracle JET components, other composite components, HTML, JavaScript, or Cascading Style Sheets (CSS). Oracle JET tooling creates a folder in your web application where these elements of the composite component reside.
What Do You Need?
- A development environment set up to create Oracle JET applications, with JavaScript runtime, Node.js, and Oracle JET command-line interface installed
- Completion of the previous tutorials in this learning path
so that you have created the
JET_Web_Application
folder
Create
a Composite Component
- Open a Command Prompt window if it isn't already open.
Change to the /
JET_Web_Application
directory and create thedemo-name-badge
composite component.ojet create component demo-name-badge
- In your file system, navigate to the /
JET_Web_Application
/src
/js
/viewModels
directory and open theincidents.js
file in an editor. - In the
incidents.js
file, edit thedefine()
block to include the composite loader library.define(['ojs/ojcore', 'knockout', 'jquery', 'jet-composites/demo-name-badge/loader'],
- Save the
incidents.js
file. - In your file system, navigate to the /
JET_Web_Application
/src
/js
/views
directory and open theincidents.html
file in an editor. - Copy the following code block for the
demo-name-badge
custom HTML element.<demo-name-badge></demo-name-badge>
- In the
incidents.html
file, replace the content in the<div>
tag of theIncidents Content Area
with the copied code.<div class="oj-hybrid-padding"> <h1>Incidents Content Area</h1> <div> <demo-name-badge></demo-name-badge> </div> </div>
- Save the
incidents.html
file. - In the Command Prompt window, change to the /
JET_Web_Application
directory and run the application.ojet serve
- In the browser that displays your
JET_Web_Application,
click the Incidents tab. - Leave the Command Prompt window and the browser that displays your web application open.
Oracle JET tooling creates the demo-name-badge
composite component in the /JET_Web_Application
/src
/js
/jet-composites
directory. The composite component name contains a hyphen and
is lowercase, as required by the W3C naming conventions for
custom components.
The browser displays the navdrawer starter template with the components visible in the Dashboard tab of your web application.
The browser displays the navdrawer starter template with the default message visible in the Incidents tab of your web application.

The ojet serve
command lets you
make changes to your application code that are immediately
reflected in the browser.
Define
Custom Composite Metadata
- Navigate to the /
JET_Web_Application
/src
/js
/jet-composites
/demo-name-badge
directory and open thecomponent.json
file in an editor. - Copy the following code snippet and replace the contents of
the
component.json
file with the copied code.{ "name": "demo-name-badge", "displayName": "demo-name-badge", "description": "Component for displaying a badge with a name and an image", "version": "1.0.0", "jetVersion": "^5.0.0", "properties": { "badgeName" : { "type" : "string" }, "badgeImage" : { "type" : "string" } } }
- Save the file.
Define
the Component view
- Navigate to the /
JET_Web_Application
/src
/js
/jet-composites
/demo-name-badge
directory and open thedemo-name-badge-view.html
file in an editor. - Copy the following code snippet and replace the contents of
the
demo-name-badge-view.html
file with the copied code.<div class="badge-face"> <oj-avatar src="[[$properties.badgeImage]]" size="lg"></oj-avatar> <h3><oj-bind-text value="[[$properties.badgeName]]"></oj-bind-text></h3> </div>
- Save the file.
Define
the Component viewModel
- Navigate to the /
JET_Web_Application
/src
/js
/jet-composites
/demo-name-badge
directory and open thedemo-name-badge-viewModel.js
file in an editor. - In the
demo-name-badge-viewModel.js
file, edit thedefine()
block to include the'ojs/ojavatar'
library.define( ['ojs/ojcore', 'knockout', 'jquery', 'ojL10n!./resources/nls/demo-name-badge-strings', 'ojs/ojavatar'],
- Save the file.
Define
the Component CSS
- Navigate to the /
JET_Web_Application
/src
/js
/jet-composites
/demo-name-badge
directory and open thedemo-name-badge-styles.css
file in an editor. - Copy the following code snippet and replace the contents of
the
demo-name-badge-styles.css
file with the copied code.demo-name-badge:not(.oj-complete){ visibility: hidden; } demo-name-badge{ display : block; width : 200px; height: 200px; margin : 10px; } demo-name-badge .badge-face { height : 100%; width : 100%; background-color : #80C3C8; border-radius: 5px; text-align: center; padding-top: 30px; }
- Save the file.
Add
Your Composite Component
- Navigate to the /
JET_Web_Application
/src
/js
/views
directory and open theincidents.html
file in an editor. - In the
incidents.html
file, edit the<h1>
tag to displayTest Composite
as the title for yourdemo-name-badge
composite component.<h1>Test Composite</h1>
- In the
<div>
tag of theTest Composite
component, edit thedemo-name-badge
custom HTML element to include thebadge-name
andbadge-image
attributes.<div class="oj-hybrid-padding"> <h1>Test Composite</h1> <div> <demo-name-badge badge-name="Duke Mascot" badge-image="https://upload.wikimedia.org/wikipedia/commons/b/b1/ThumbsUp.svg"> </demo-name-badge> </div> </div>
- Save the
incidents.html
file. - Open the browser to view the dynamic changes in your web application.
- If you don't see the above format of the
demo-name-badge
composite component, in the Command Prompt window, press Ctrl+c, and then entery
to terminate the Oracle JET tooling batch job. Now, run the application again.ojet serve
The browser now displays the navdrawer starter template with the composite component visible in the Incidents tab of your web application.
