
Creating User Modules ProcessPageStateBase
Create complete registration screens (inclusion, alteration, and exclusion) in a few minutes.
Table of contents 1. Initial Considerations 2. XmlFormCollection and ContextValue 3. XmlEditList 4. ProcessPageStateBase
On this page The ProcessPageStateBase Class Defining the information dictionary Explaining the parameters of the ProcessPageField Using the ProcessPageStateAnydata Explaining the parameters of ProcessPageStateAnydata Using ProcessPageStateDB Explaining the parameters of ProcessPageStateDB
The ProcessPageStateBase Class
The ProcessPageStateBase is a class whose basic function is to be a small machine of states capable of managing when the component should be in visualization mode, editing, inclusion or exclusion, in addition to performing persistence operations in the data repository.
Although this mechanism is well known, it becomes viable for unrestricted use in XMLNuke, since the product of the ProcessPageState is an XML which can be listed in the form most convenient to the user, and thus adapts to any layout.
The ProcessPageState contains all the basic functionalities required for managing data flows. The definitions of information persistence, like database or XML, should be done through specializations of this class. XMLNuke currently implements two specialized classes for the ProcessPageState:
-
ProcessPageStateAnydataSet (If an AnyDataSet repository from XMLNuke is used);
-
ProcessPageStateDBDataSet (If a relational database is used, like: MySql, SQL, Oracle, PostGree, among others).
To use any of these classes, it is first necessary for the user to provide a small dictionary of information that specifies which type of field will be added to the page. The configuration of this dictionary should be done through an object of the ProcessPageFields class, which is a collection of objects of the ProcessPageField class. For each field you wish to add to the page, you must create an object of the corresponding ProcessPageField class. This will specify: the type of data that should be entered, if the field is visible for listing and for editing, if the field is required or not, along with other information that is relevant to the field. Once created, the object from the ProcessPageField class, which represents a specific field, should be added to the object of the ProcessPageFields class, which representes the set of fields of the page.
It's possible to specialize the ProcessPageStateAnyDataSet and ProcessPageStateDBDataSet classes to execute certain specific functions of their modules (this will be discussed in a later topic).
Defining the information dictionary
This is the most important phase in the process of using ProcessPageStateBase and is independent from the persistence mechanism which will be used. In other words, whether the ProcessPageStateAnydataSet or the ProcessPageStateDBDataSet is used, this phase should be completed in advance.
To define the dictionary of information, to represent each field to be displayed on the page, the objects of the ProcessPageField class should be instanced. These will later be added to the objects of the ProcessPageField class, as shown in the example below. It's important to note that the object of the ProcessPageFields should be added to an element on the screen in order to be displayed, as in XmlParagraphCollection, for example.
To define the dictionary of information, it's important to note that the first field should be the KEY field, and that there should be only one key field.
CSharp
ProcessPageField fieldPage;
ProcessPageFields pageFields = new ProcessPageFields();
fieldPage = new ProcessPageField(true);
fieldPage.fieldName = "code";
fieldPage.key = true;
fieldPage.dataType = INPUTTYPE.NUMBER;
fieldPage.fieldCaption = "Código";
fieldPage.fieldXmlInput = XmlInputObjectType.TEXTBOX;
fieldPage.visibleInList = true;
fieldPage.editable = true;
fieldPage.required = true;
fieldPage.rangeMin = "100";
fieldPage.rangeMax = "10000";
pageFields.addProcessPageField(fieldPage);
fieldPage = new ProcessPageField(true);
fieldPage.fieldName = "name";
fieldPage.key = false;
fieldPage.dataType = INPUTTYPE.TEXT;
fieldPage.fieldCaption = "Nome";
fieldPage.fieldXmlInput = XmlInputObjectType.TEXTBOX;
fieldPage.visibleInList = true;
fieldPage.editable = true;
fieldPage.required = true;
pageFields.addProcessPageField(fieldPage);
PHP
$pageField = new ProcessPageFields();
$fieldPage = new ProcessPageField();
$fieldPage->fieldName = "code";
$fieldPage->key = true;
$fieldPage->dataType = INPUTTYPE::NUMBER;
$fieldPage->fieldCaption = "Código";
$fieldPage->fieldXmlInput = XmlInputObjectType::TEXTBOX;
$fieldPage->visibleInList = true;
$fieldPage->editable = true;
$fieldPage->required = true;
$fieldPage->rangeMin = "100";
$fieldPage->rangeMax = "10000";
$pageField->addProcessPageField($fieldPage);
$fieldPage = new ProcessPageField();
$fieldPage->fieldName = "name";
$fieldPage->key = false;
$fieldPage->dataType = INPUTTYPE::TEXT;
$fieldPage->fieldCaption = "Nome";
$fieldPage->fieldXmlInput = XmlInputObjectType::TEXTBOX;
$fieldPage->visibleInList = true;
$fieldPage->editable = true;
$fieldPage->required = true;
$pageField->addProcessPageField($fieldPage);
Explaining the parameters of the ProcessPageField
fieldname
Idenfities the name of the field inside the data repository
key
Identifies that the field is key.
dataType
Attributes a value of the INPUTTYPE type to determine which type of data should be expected (number, text, data, e-mail)
fieldCaption
Determines the label which will be displayed when editing.
fieldXmlInput
Attributes a value of the XmlInputObjectType type to determine what type of object will be used for editing. It can be a TextBox, Memo, Password, Check, etc.
visibleInList
Determines if the field will be visible in the listing or not.
editable
Determines if the field will be editable or not
required
Determines if the field is required or not
rangeMin
Determines the minimum limit to be entered in the field
rangeMax
Determines the maximum limit to be entered in the field
size
Determines the text box size
newColumn
Determines if the field will generate a new column in the listing, or if it will be in the same column as the previous one. Default is to always generate a new column.
Using the ProcessPageStateAnydata
Once defined in the dictionary of information, the ProcessPageStateBase must be informed of this dictionary. When using an AnyDataset from XMLNuke, it should be used as an object of the ProcessPageStateAnydata class, as shown in the example below.
CSharp
AnydatasetFilenameProcessor anyData = new AnydatasetFilenameProcessor("arquivo", this._context);
ProcessPageStateAnydata processPage =
new ProcessPageStateAnydata(
this._context,
pageFields,
"Editing test using database",
"module:sample?op=4",
null,
anyData);
PHP
$processPage = new ProcessPageStateAnydata(
$this->_context,
$pageField,
"Editing test using database",
"module:sample?op=4",
null,
new AnydatasetFilenameProcessor("sample", $this->_context));
Explaining the parameters of ProcessPageStateAnydata
To instance an object of the ProcessPageStateAnydata class, the following parameters must be sent (context, fields, header, module, buttons, anydata):
context
Object of the XmlNuke Context type
fields
Object of the ProcessPageFields type, which contains the set of fields represented by the added ProcessPageField objects.
header
Defines the title of EditList where the entries will be listed
module
Determines the module that will be processed when submitting the page. Generally it is the same module that instanced the ProcessPageState
buttons
Defines a collection of customizable buttons of the CustomButtons type
anydata
Object of the AnyDataSetFilenameProcessor type that indicates the path of the AnyDataset repository that was used.
Using ProcessPageStateDB
If a relational database is being used, an instance should be created of the ProcessPageStateDB class, as shown in the example below.
The ProcessPageStateDB class provides all of the necessary functionalities for editing data in a single database table. To use more tables, this class must be specialized.
CSharp
ProcessPageStateDB processPage =
new ProcessPageStateDB(
this._context,
pageField,
"Title of work area",
"module:sample",
null,
"DATABASE_TABLE",
"XMLNUKE_CONNECTION");
processPage.setSort("campo");
PHP
$processPage = new ProcessPageStateDB(
$this->_context,
$pageField,
"Title of work area",
"module:sample?op=5",
null,
"DATABASE_TABLE",
"XMLNUKE_CONNECTION");
Explaining the parameters of ProcessPageStateDB
To instance an object of the ProcessPageStateDB class, the following parameters must be sent (context, fields, header, module, buttons, table, connection):
context
Object of the XmlNuke Context type
fields
Object of the ProcessPageFields type, which contains the set of fields represented by the added ProcessPageField objects.
header
Defines the title of EditList where the entries will be listed
module
Determines the module that will be processed when submitting the page. Generally it is the same module that instanced the ProcessPageState
buttons
Defines a collection of customizable buttons of the CustomButtons type
table
Determines the database table which will be used
connection
Determines the database connection which will be used to access the table. Generally this connection is configured in the file _db.anydat.xml which is located in the folder /data/sites/anydataset/.
|