- Developing Oracle JET Apps Using MVVM Architecture
- Working with Oracle JET Web Components
- Add Web Components to Your Page
Add Web Components to Your Page
To use an Oracle JET Web Component, you must register the Web Component’s loader file in your application and you must also include the Web Component element in the application’s HTML. You can add any supporting CSS or files as needed.
- In the Web Components’s root folder, open
component.json
and verify that your version of Oracle JET is compatible with the version specified injetVersion
.For example, the demo-card example specifies the following
jetVersion
:"jetVersion": ">=3.0.0 <12.1.0"
This indicates that the component is compatible with JET versions greater than or equal to 3.0.0 and less than 12.1.0.
If your version of Oracle JET is lower than the
jetVersion
, you must update your version of Oracle JET before using the component. If your version of Oracle JET is greater than thejetVersion
, contact the developer to get an updated version of the component. - In your application’s
index.html
or main application HTML, add the component and any associated property declarations.For example, to use the
demo-card
standalone Web Component, add it to yourindex.html
file and add declarations forname
,avatar
,work-title
,work-number
,email
, andbackground-image
.<div id="composite-container" class="oj-flex oj-sm-flex-items-initial"> <oj-bind-for-each data="[[employees]]"> <template> <demo-card class="oj-flex-item" name="[[$current.data.name]]" avatar="[[$current.data.avatar]]" work-title="[[$current.data.title]]" work-number="[[$current.data.work]]" email="[[$current.data.email]]"> </demo-card> </template> </oj-bind-for-each> </div>
In the case of components within a JET Pack, the HTML tag name is the component full name. The full name of a pack's member component is always a concatenation of the pack name and the component name, as specified by the dependencies attribute of the pack-level
component.json
file (located in the pack root folder underjet-composites
). For example, a componentwidget-1
that is a member of the JET Packmy-pack
, has the following full name that you can reference as the HTML tag name.my-pack-widget-1
Note that the framework maps the attribute names in the markup to the component’s properties.
-
Attribute names are converted to lowercase. For example, a
workTitle
attribute will map to aworktitle
property. -
Attribute names with dashes are converted to camelCase by capitalizing the first character after a dash and then removing the dashes. For example, the
work-title
attribute will map to aworkTitle
property.
You can access the mapped properties programmatically as shown in the following markup:
<h5><oj-bind-text value="[[properties.workTitle]]"></oj-bind-text></h5>
-
- In your application’s ViewModel, set values for the properties you declared in the previous step and add the component’s loader file to the list of application dependencies.
For example, the following code adds the ViewModel to the application’s RequireJS bootstrap file. The code also defines the
jet-composites/demo-card/loader
dependency.require(['ojs/ojbootstrap', 'knockout', 'ojs/ojknockout', 'demo-card/loader'], function(Bootstrap, ko) { function model() { var self = this; self.employees = [ { name: 'Deb Raphaely', avatar: 'images/composites/debraphaely.png', title: 'Purchasing Director', work: 5171278899, email: 'deb.raphaely@oracle.com' }, { name: 'Adam Fripp', avatar: null, title: 'IT Manager', work: 6501232234, email: 'adam.fripp@oracle.com' } ]; } Bootstrap.whenDocumentReady().then(function() { ko.applyBindings(new model(), document.getElementById('composite-container')); } ); });
In the case of a JET Pack, you add the loader file for the JET Pack by specifying the path based on the pack root and folder name of the component contained within the pack.
'my-pack/widget-1/loader'
- Add any supporting CSS, folders, and files as needed.
For example, the demo card example defines a background image for the contact card in the application’s
demo.css
:#composite-container demo-card .demo-card-front-side { background-image: url('images/composites/card-background_1.png'); }