Create parent container 1 and activity container components
Introduction
The Oracle JavaScript Extension Toolkit (Oracle JET) virtual DOM app that you will have developed at the end of this learning path series will be composed of the components shown in the following image. That is, the ParentContainer1 component contains an ActivityContainer component that displays a list of activities. Once an activity is selected, a second parent component (ParentContainer2) renders that includes a component (ActivityItemContainer) to display the list of items associated with the selected activity. Finally, on selection of an activity item, the app renders an ItemDetailContainer component that displays pricing and stock level information about the selected activity item.

Objectives
In this tutorial, you will compose some of the foundational components of your Oracle JET virtual DOM app. To aid in the visualization of the app layout, you will also add the Oracle JET oj-panel and oj-bg style classes to display borders and color around the containers. You can remove these style classes from the final app.
Prerequisites
- A development environment set up to create Oracle JET virtual DOM apps that includes an installation of Node.js
- Access to the Oracle JET Cookbook
- (Option 1) Completion of the final tutorial in the previous learning path in this series: Prepare to Deploy an Oracle JET Virtual DOM App
- (Option 2) If you haven’t completed the previous learning path in this series: The
jet_virtual_dom_app_temp.zipdownloaded
Task 1: Download the Starter Virtual DOM App
Skip this task if you’re continuing to work in an app that you created in the previous learning path.
-
Rename
jet_virtual_dom_app_temp.zipasJET-Virtual-DOM-app.zip. Extract the contents to theJET-Virtual-DOM-appdirectory. -
Navigate to the
JET-Virtual-DOM-appdirectory, and restore the Oracle JET virtual DOM app.npm installYour virtual DOM app is ready to use.
Task 2: Create the Item Detail Component
The Content component was created when you scaffolded the virtual DOM app in the last learning path. Rename and refactor this component as ItemDetailContainer, a child component that will be rendered by the ParentContainer2 component that you will create in the next tutorial.
-
In the
JET-Virtual-DOM-app/src/componentsdirectory, rename thecontentdirectory toItemDetail. Then rename theindex.tsxfile within it toItemDetailContainer.tsx.Note: If your editor brings up a prompt asking whether imports should be updated in the renamed file or directory, as in the message from Visual Studio Code below, click No and continue.
. -
In
ItemDetailContainer.tsx, change the lineexport function Content() {toconst ItemDetailContainer = () => {. Then add anexportstatement for theItemDetailContainercomponent to the end of the file.const ItemDetailContainer = () => { . . . }; export default ItemDetailContainer; -
Replace the beginning of the
returnstatement in theItemDetailContainercomponent with the following code, up to but not including theoj-labelelement. Thedivincludes an Oracle JEToj-bgstyle class to add a gray background color to the container.return ( <div id="itemDetailsContainer" class="oj-bg-neutral-30"> <h3>Item Details</h3> <oj-label for="basicSelect">Select Chart:</oj-label> . . . -
Delete the
renderListItemfunction and remove the last closing</div>tag from the end of thereturnstatement. -
Save and close the file.
Your code should look similar to
item-detail-container-tsx.txt
Task 3: Create the Content Component
Recreate the Content component, which renders a title for your app and a Preact element for the ParentContainer1 component that you will create in the following task.
-
In the
JET-Virtual-DOM-app/src/componentsdirectory, create aContentdirectory with an emptyContent.tsxfile inside it. -
Add the following import statements to the top of the file. You will create the
ParentContainer1component later in this tutorial.import { h } from "preact"; import ParentContainer1 from "../ParentContainer1"; -
Create the
Contentcomponent’s function definition.const Content = () => { return ( ); } -
In the function’s
returnstatement, add adivcontaining theh1header Product Information and aParentContainer1element to access the component you will create.const Content = () => { return ( <div class="oj-web-applayout-max-width oj-web-applayout-content"> <h1>Product Information</h1> <ParentContainer1 /> </div> ); }; -
At the end of the file, add an
exportstatement for theContentcomponent.export default Content; -
Save and close the file. Your code should look similar to content-tsx.txt.
-
In the
JET-Virtual-DOM-app/src/componentsdirectory, open theapp.tsxfile in your editor. At the top of the file, find the line of code whereimport { Content } from "./content/index";, then edit it to readimport Content from "./Content/Content";. -
Save and close the file.
Task 4: Create the Parent Container 1 Component
Create the ParentContainer1 component, which is the parent container component for the rest of the components you will create.
-
In the
JET-Virtual-DOM-app/src/componentsdirectory, create aParentContainer1.tsxfile. -
Add the following
importstatements to the top of the file. You will create theActivityContainercomponent later in this tutorial.import { h } from "preact"; import ActivityContainer from "./Activity/ActivityContainer"; -
Create the
ParentContainer1component’s function definition, which returns adivthat contains theActivityContainerelement. Thedivelement includes an Oracle JEToj-bgstyle class to add a yellow background color to the container and anoj-panelstyle class to create a border.const ParentContainer1 = () => { return ( <div id="parentContainer1" class="oj-panel oj-bg-warning-20"> <ActivityContainer /> </div> ); }; -
At the end of the file, add an
exportstatement for theParentContainer1component.export default ParentContainer1; -
Save and close the file.
Your code should look similar to parent-container1-tsx.txt.
Task 5: Create the Activity Container Component
Create the ActivityContainer component, a child component that is rendered by the ParentContainer1 component. The ActivityContainer component renders a header and a list of activities.
-
In the
JET-Virtual-DOM-app/src/componentsdirectory, create anActivitydirectory and anActivityContainer.tsxfile inside it. -
At the top of the file, add the following
importstatement.import { h, ComponentProps } from "preact"; -
Create the
ActivityContainercomponent’s function definition, which returns adivelement containing anh3HTML header Activities and a list of activities. Thedivincludes an Oracle JEToj-bgstyle class to add a blue background color to the container.const ActivityContainer = () => { return ( <div id="activitiesContainer" class="oj-bg-info-30"> <h3 id="activitiesHeader">Activities</h3> <div id="activitiesItems" class="item-display no-wrap"> <ul> <li class="li-item">Baseball</li> <li class="li-item">Bicycling</li> <li class="li-item">Skiing</li> <li class="li-item">Soccer</li> </ul> </div> </div> ); }; -
At the end of the file, add an
exportstatement for theActivityContainercomponent.export default ActivityContainer; -
Save and close the file.
Your code should look similar to
activity-container-tsx.txt. -
Navigate to the
JET-Virtual-DOM-app/src/stylesdirectory and open theapp.cssfile in an editor. Add theitem-display,no-wrap, andli-itemstyle classes to the end of the file..item-display { width: 100%; height: 100%; max-height: 500px; overflow-x: hidden; overflow-y: auto; } .no-wrap { flex-wrap: nowrap; } .li-item { list-style-type: none; font-size: 1rem; font-weight: 500; } -
Save and close the file.
Your code should look similar to
app-css.txt.
Task 6: Run the Virtual DOM App
-
In the terminal window, run the app from the
JET-Virtual-DOM-appdirectory.npx ojet serveThe Activity Container (blue) inside of Parent Container 1 (yellow) displays the list of activity names. Note that the Item Detail Container is not displayed because it has not yet been rendered inside another component (it will be added to the Parent Container 2 component, created in the next tutorial).

-
Close the browser window or tab that displays your running virtual DOM app.
-
In the terminal window, press Ctrl+C, and if prompted, enter
yto exit the Oracle JET tooling batch job.
Next Step
Proceed to the next tutorial in this module.
This tutorial is part of the module Compose Components.
- Create Parent Container 1 and Activity Container Components
- Create Parent Container 2 and Activity Item Container Components
You can return to the virtual DOM learning path’s main page to access all the modules on building virtual DOM apps.
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Create parent container 1 and activity container components
F72917-05