3.9. Edit Views, Layout and Components
In this section, we will override the default detail view that is generated by Skyve.
Resident Edit View
Skyve provides us with a very useful function that creates a default edit view
based on our document attributes and attribute types. The default widget will be applied for each attribute type.
To create our Resident edit view
, we will progress through the following steps.
Create the Edit View
-
Click on
Generate edit view
on the right side of the Eclipse window and type the module and document name in the Console window. -
Open the Resident module by going to the agedCare module on the left side of the Eclipse window. You can see a view module, and in this view module, there is a document called
generatededit.xml
. Rename the document toedit.xml
Enhance the Edit View
In the previous step, we generated an edit view by using the Generate Edit View function. Now, we will enhance our edit view to make it more visually appealing.
Currently, the Resident attributes are shown one by one, from top to bottom.
We will enhance the view by showing all personal information on the left-hand side of the screen and the photo and BIO on the right-hand side.
To do that, we need to understand Skyve View Containers. There is an explanation on working with view containers in the views chapter of the developer guide.
After reading through the chapter on Skyve containers, you may have already guessed how to split the view into 2 parts.
The hbox
container lays out items horizontally.
Open the resident edit.xml
file and add the code given below.
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit"
title="Resident"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<tabPane>
<tab title="General">
<hbox border="true">
<!-- left side -->
<vbox responsiveWidth="8" percentageWidth="60">
<form>
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="residentID" />
</item>
</row>
<row>
<item>
<default binding="residentName" />
</item>
</row>
<row>
<item>
<default binding="DOB" />
</item>
</row>
<row>
<item>
<default binding="roomNo" />
</item>
</row>
<row>
<item>
<default binding="admissionDate" />
</item>
</row>
<row>
<item>
<default binding="facility" />
</item>
</row>
</form>
</vbox>
<!-- right side -->
<vbox responsiveWidth="4" percentageWidth="40">
<form>
<column percentageWidth="20" responsiveWidth="1" />
<column />
<row>
<item showLabel="false">
<contentImage binding="photo" />
</item>
</row>
<row>
<item>
<default binding="BIO" />
</item>
</row>
</form>
</vbox>
</hbox>
</tab>
<tab title="Assessments">
<dataGrid binding="assessments">
<boundColumn binding="hygieneAssessment" />
<boundColumn binding="painAssessment" />
<boundColumn binding="continenceAssessment" />
<boundColumn binding="sleepAssessment" />
<boundColumn binding="behaviourAssessment" />
<boundColumn binding="assessmentCreatedBy" />
<boundColumn binding="assessmentReviewTime" />
<onAddedHandlers />
<onEditedHandlers />
<onRemovedHandlers />
<onSelectedHandlers />
</dataGrid>
</tab>
</tabPane>
<actions>
<defaults />
</actions>
<newParameters />
</view>
To see the changes, generate domain and re-deploy the application as you did before (stop the WildFly server, run Generate Domain, then restart WildFly).
Next, we will group related information together to make it easier to manage.
The easiest way is to use the border
and borderTitle
attributes of the Form container.
So, in this case, we will have 2 forms, one for Resident information and another for Facility information.
Add border
and borderTitle
in the <form>
tag.
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit"
title="Resident"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<tabPane>
<tab title="General">
<hbox border="true">
<!-- left side -->
<vbox responsiveWidth="8" percentageWidth="60">
<form border="true" borderTitle="Resident Info">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="residentID" />
</item>
</row>
<row>
<item>
<default binding="residentName" />
</item>
</row>
<row>
<item>
<default binding="DOB" />
</item>
</row>
</form>
<form border="true" borderTitle="Facility Info">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="roomNo" />
</item>
</row>
<row>
<item>
<default binding="admissionDate" />
</item>
</row>
<row>
<item>
<default binding="facility" />
</item>
</row>
</form>
</vbox>
<!-- right side -->
<vbox responsiveWidth="4" percentageWidth="40">
<form>
<column percentageWidth="20" responsiveWidth="1" />
<column />
<row>
<item showLabel="false">
<contentImage binding="photo" />
</item>
</row>
<row>
<item>
<default binding="BIO" />
</item>
</row>
</form>
</vbox>
</hbox>
</tab>
<tab title="Assessments">
<dataGrid binding="assessments">
<boundColumn binding="hygieneAssessment" />
<boundColumn binding="painAssessment" />
<boundColumn binding="continenceAssessment" />
<boundColumn binding="sleepAssessment" />
<boundColumn binding="behaviourAssessment" />
<boundColumn binding="assessmentCreatedBy" />
<boundColumn binding="assessmentReviewTime" />
<onAddedHandlers />
<onEditedHandlers />
<onRemovedHandlers />
<onSelectedHandlers />
</dataGrid>
</tab>
</tabPane>
<actions>
<defaults />
</actions>
<newParameters />
</view>
Now that we have created a view for Resident records, it’s time to learn about View Components.
So, what are View Components?
Let’s imagine that our view is very complex with many sections and these sections can be reused in different views. Skyve allows for reuse of view sections via the component widget.
To demonstrate how to re-use components, we will split our view into three components:
- Resident Info
- Facility Info
- Photo and Bio
The view component must be declared according to convention - the file name must match the declared name.
Resident Info Component
In the Resident -> views package, create a new file called _residentInfo.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_residentInfo" title="Resident Info"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Resident Info">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="residentID" />
</item>
</row>
<row>
<item>
<default binding="residentName" />
</item>
</row>
<row>
<item>
<default binding="DOB" />
</item>
</row>
</form>
</view>
Facility Info Component
In the Resident -> views package, create a new file called _facilityInfo.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_facilityInfo" title="Facility Info"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Facility Info">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="roomNo" />
</item>
</row>
<row>
<item>
<default binding="admissionDate" />
</item>
</row>
<row>
<item>
<default binding="facility" />
</item>
</row>
</form>
</view>
Photo and Bio Component
In the Resident -> views package, create a new file called _photoBio.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="_photoBio"
title="Resident Photo and Bio"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form>
<column percentageWidth="20" responsiveWidth="1" />
<column />
<row>
<item showLabel="false">
<contentImage binding="photo" />
</item>
</row>
</form>
<form border="true" borderTitle="BIO">
<column />
<row>
<item showLabel="false">
<textArea binding="BIO" />
</item>
</row>
</form>
</view>
Combine Together
Now that we have created the components, we will use them in our edit view
.
Change edit.xml
view to as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit"
title="Resident"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<tabPane>
<tab title="General">
<hbox border="true">
<!-- left side -->
<vbox responsiveWidth="6" percentageWidth="50">
<component name="_residentInfo" />
<component name="_facilityInfo" />
</vbox>
<!-- right side -->
<vbox responsiveWidth="6" percentageWidth="50">
<component name="_photoBio" />
</vbox>
</hbox>
</tab>
<tab title="Assessments">
<dataGrid binding="assessments">
<boundColumn binding="hygieneAssessment" />
<boundColumn binding="painAssessment" />
<boundColumn binding="continenceAssessment" />
<boundColumn binding="sleepAssessment" />
<boundColumn binding="behaviourAssessment" />
<boundColumn binding="assessmentCreatedBy" />
<boundColumn binding="assessmentReviewTime" />
<onAddedHandlers />
<onEditedHandlers />
<onRemovedHandlers />
<onSelectedHandlers />
</dataGrid>
</tab>
</tabPane>
<actions>
<defaults />
</actions>
<newParameters />
</view>
Now, re-deploy the application to check that the view appears as it did before.
Facility Edit View
In the previous section, we explored and practiced creatig an edit view and customizing it to meet our requirements. It’s now easy for us to create an edit view for the Facility document.
The Facility edit view will contain three components:
- Facility Info
- Facility Address
- Facility Location
Let’s start with the Facility Info component.
-
Generate the edit view for the Facility document
-
Add the facility component in the same way we did for the Resident component by renaming it from
generatededit.xml
toedit.xml
.
Facility Info Component
In the Facility -> views package, create a new file called _facilityInfo.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_facilityInfo" title="Facility Info"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Facility Info">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="facilityName" />
</item>
</row>
<row>
<item>
<default binding="facilityManager" />
</item>
</row>
</form>
</view>
Facility Address Component
In the Facility -> views package, create a new file called _facilityAddress.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_facilityAddress" title="Facility Address"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form borderTitle="Facility Address" border="true">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="buildingNumber" />
</item>
</row>
<row>
<item>
<default binding="streetName" />
</item>
</row>
<row>
<item>
<default binding="suburb" />
</item>
</row>
<row>
<item>
<default binding="state" />
</item>
</row>
</form>
</view>
Facility Location Component
In the Facility -> views package, create a new file called _facilityLocation.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_facilityLocation" title="Facility Location"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Facility Location">
<column />
<row>
<item showLabel="false">
<geometryMap binding="location">
<onChangedHandlers />
</geometryMap>
</item>
</row>
</form>
</view>
Combine Together
After creating the components, add them to the edit.xml
view as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit"
title="Facility"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<hbox border="true">
<!-- left side -->
<vbox responsiveWidth="6" percentageWidth="50">
<component name="_facilityInfo" />
<component name="_facilityAddress" />
</vbox>
<!-- right side -->
<vbox responsiveWidth="6" percentageWidth="50">
<component name="_facilityLocation" />
</vbox>
</hbox>
<actions>
<defaults />
</actions>
<newParameters />
</view>
Again, re-deploy the application to see the changes in the Facility document.
Assessment Edit View
This completes the edit views for the Resident and Facility documents. Next, we will create an edit view for the Assessment document. The Assessment document will show the following sections:
- Resident Info
- Assessment Detail
- Review Detail
Let’s start with Resident Info
Generate an edit view for the Assessment document first.
Resident Info Component
In the Assessment -> views package, create a new file called _residentInfo.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_residentInfo" title="Resident Info"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Resident Info">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="parent.residentName" />
</item>
</row>
</form>
<form border="true" borderTitle="Resident Photo">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item showLabel="false">
<contentImage binding="parent.photo" />
</item>
</row>
</form>
</view>
Assessment Detail Component
In the Assessment -> views package, create a new file called _assessmentDetail.xml
with ots content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_assessmentDetail" title="Assessment Detail"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Assessment Detail">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="hygieneAssessment" />
</item>
</row>
<row>
<item>
<default binding="painAssessment" />
</item>
</row>
<row>
<item>
<default binding="continenceAssessment" />
</item>
</row>
<row>
<item>
<default binding="sleepAssessment" />
</item>
</row>
<row>
<item>
<default binding="behaviourAssessment" />
</item>
</row>
</form>
</view>
Review Detail Component
In the Assessment -> views package, create a new file called_reviewDetail.xml
with its content as below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="_reviewDetail" title="Review Detail"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<form border="true" borderTitle="Review Detail">
<column percentageWidth="30" responsiveWidth="4" />
<column />
<row>
<item>
<default binding="assessmentCreatedBy" />
</item>
</row>
<row>
<item>
<default binding="assessmentReviewTime" />
</item>
</row>
</form>
</view>
Combine Together
After the components have been created, add them to the edit.xml
view as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<view xmlns="http://www.skyve.org/xml/view"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit"
title="Assessment"
xsi:schemaLocation="http://www.skyve.org/xml/view ../../../../schemas/view.xsd">
<hbox border="true">
<!-- left side -->
<vbox responsiveWidth="5" percentageWidth="40">
<component name="_residentInfo" />
<component name="_reviewDetail" />
</vbox>
<!-- right side -->
<vbox responsiveWidth="7" percentageWidth="60">
<component name="_assessmentDetail" />
</vbox>
</hbox>
<actions>
<defaults />
</actions>
<newParameters />
</view>
Re-deploy the application to see the changes we have made in this step.
Continue to 3.10 Roles