Personal tools
You are here: Home Framework Def How to Create Business Entities

Business entities are the basic building block of Foundation applications. They encapsulate the business data as defined by the fields and present the data to the user in a panel.

Create a Foundation Project

Create a new Foundation Project called busentity1 using a plugin. For this how to we will be using Eclipse and SqlServer.

Select the SQLServer Database Type and modify the Database URL for your database. Leave the default FParent and FChild entities, we will be creating new ones for the project. Then create new Run profiles for define and clientserver and test that the default application can be defined and run.

For more information on how to do this see the Getting Started with Eclipse How To

Creating a new Business Entity

Create the Class

Select the common.classes package and then select File -> New -> Class. Name the new class FSample1. (The F is important since it tells Foundation that this is a Foundation business entity). Check Constructors from Superclass.

Press Finish.

This new class will become a table in the database (TSample1).

Inherit from FThing

Modify the class declaration to extend FThing:

package com.foundation.busentity1.common.classes;

import com.foundation.common.classes.FThing;

public final class FSample1 extends FThing<FSample1> {

    public FSample1() {
        super();
        // TODO Auto-generated constructor stub
    }

}

Have the Constructor Throw a RemoteException

This allows exceptions to propigate from the back to the client through RMI.

public FSample1() throws RemoteException {
    super();
    // TODO Auto-generated constructor stub
}

Create Data Fields

By inheriting from FThing a fCode and fDescription fields are already available.

Add a string field to the class:

public FString fName = new FString() {
    public String getLabel() { return "Name"; }
    public String getHint() { return "The name of the sample"; }
};

The getLabel() method will create the label beside the textbox for this string.

See section 3.1.4 Business Simple Type in the Developers Guide for a complete listing of all the avaliable fields.

Add a Form Panel

The form panel creates the main data entry and single record display screen, usually used for data entry.

//@see FObject#defineFFormPanel
    public void defineFFormPanel(FFormPanel<FSample1> fFormPanel) throws Exception {
    super.defineFFormPanel(fFormPanel);
    fFormPanel.addFControls(FSample1.class);
}

This will add all the fields defined in the FSample1 class to the formpanel.

Add a List Panel

The list panel creates a list of records below the Form Panel, usually used for search return and child records.

//@see FObject#defineFListPanel
public void defineFListPanel(FTablePanel<FSample1> fTablePanel) throws Exception {
    super.defineFListPanel(fTablePanel);
    fTablePanel.addFColumns(FSample1.class);
}

This will add all the fields defined in the FSample1 class to the list panel.

Add a Default Sort Order

When records are returned you can define a default sort order using the getFSorter() method:

public IFSorter getFSorter() throws RemoteException {
    return FSorter.construct(this, fCode, true);
}

This will return the data sorted by the primary key fCode. See Section 3.4.7 Defining the Default Sort Order in the Developers Guide.

Creating Data

A business entity can define it own data by suppling it in the getInitAry():

// @see FObject#getInitAry
protected Object[][] getInitAry() throws RemoteException {
    return new Object[][] {
        { fCode, fDescription, fName },
        { "record1", "record1", "one" },
        { "record2", "record2", "two" },
        { "record3", "record3", "three" },
    };
}

This will add three records to the busines entity.

Add the Class to the Menu

In order to access the new business entity from the GUI add the following to the MenuBar class:

FMenu fMenuTables = new FMenu("~Tables", "Tables within the system");
addFObjectMenuItems(fMenuTables, FParent.class);
addFObjectMenuItems(fMenuTables, FChild.class);
addFObjectMenuItems(fMenuTables, FSample1.class);
add(fMenuTables);

Define and Run

The application is now read to be defined in the database and run.

The Administrator username and password will be the same as you entered when you created the project. If you forget they are defined in data/FUser.txt

Source Code

This project can be downloaded here. Unzip it into a directory and Import it into Eclipse.

Help

For any additional support email support@foundationdms.com.