OFBiz Tutorial – Using CMS for Front End Application Static Pages (Part-1‏)

In this post, I’ll demonstrate OFBiz CMS(Content Management System) uses for static pages on a website(front end application) through simple content data setup. CMS gives users the flexibility to change the content to be shown on static pages of your website.

Often website owners want to have static web page setup e.g. About Us, FAQ, Terms and Conditions, Privacy Policy etc.  An effective CMS empowers the website owner to update the page content herself, without asking for help from the development team. Let’s walk through a basic example setup of this capability in Apache OFBiz.

All the features mentioned here are supported by the out-of-the-box (OOTB) OFBiz CMS implementation.

In this exercise you will:

  • see the basic concept of DataResource and Content.
  • setup content data to embed FTL markup.
  • setup a content driven screen and use it to show the static content setup through data.

• Assumption: a component is already setup; here we are using the component name as “cmsdemo”.

DataResource and Content records

Let’s suppose that you want to define content (that will be included in a screen) for showing the text “This is the text that will appear on the screen.”.

Data Resource type- ELECTRONIC_TEXT

First of all, you have to define a DataResource representing this text. This gives you greater flexibility because you can store long texts in the textData field. If you want to embed FTL markup (directives etc…) that needs to be processed before rendering, you can achieve this using the dataTemplateTypeId attribute. This way all the Freemarker instructions in the text will be executed before rendering the screen. Following data needs to be setup in an XML data file:

<DataResource dataResourceId="DS-01" dataResourceTypeId="ELECTRONIC_TEXT"/>
<ElectronicText dataResourceId="DS-01">
    <textData><![CDATA[
        This is the text that will appear on the screen.
    ]]></textData>
</ElectronicText>

Content

Now you have to create a Content record that is associated to the DataResource. 
No matter what type of data resource you have chosen, the Content record is the same as:

<Content contentId="CN-01" contentTypeId="DOCUMENT" contentName="Content 01" dataResourceId="DS-01"/>

Note that the contentTypeId is “DOCUMENT”: all pages and sections of pages should be of this type.

Using the <content/> element in a screen definition

Now we can easily include the content directly inside the <widgets/> section of the screen definition with the following directive:

<screen name="main">
    <section>
        <widgets>
            <label style="h1">OFBiz CMS Demo</label>
            <content content-id="CN-01"/>
        </widgets>
    </section>
</screen>

In the given example screen name is “main”.

Running the content driven screen

Load the data that you have just created for static content for a screen.

Make sure to have an entry in ofbiz-component.xml file for the data file created as:

<entity-resource type="data" reader-name="demo" loader="main" location="data/DemoCMSData.xml"/>

or if OFBiz is already up on your machine then you can also load data through webtools –> XML Data Import.

Request and View Mapping in Controller.xml

Request:
<request-map uri="main">
    <security https="true" auth="false"/>
    <response name="success" type="view" value="main"/>
</request-map>

View Mapping:
<view-map name="main" type="screen" page="component://cmsdemo/widget/CmsDemoScreens.xml#main"/>

Now access the main page by using URL: [https://localhost:8443/cmsdemo/control/main] You will see the result in the browser as follows:

OFBiz CMS Demo

OFBiz CMS Demo

You are done with the basic setup of a static website using OFBiz CMS capabilities.

It was a very basic example.  We’ll expand on the details and demonstrate more OFBiz CMS capabilities in upcoming posts.  If you need help with OFBiz CMS in the mean time please feel free to contact HotWax Systems today!

 


DATE: Mar 17, 2010
AUTHOR: Pranay Pandey
OFBiz Tutorials, OFBiz Ecommerce, cms, OFBiz Development, OFBiz Tutorial, Content Management System (CMS), OFBiz, Pranay Pandey, ofbiz cms, ofbiz content management