Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONPublished

MVC architecture in AdvPL

ModelDef() · ViewDef() · MenuDef()

Organize business rules, presentation and operations in a Protheus routine with MVC.

MVCFrameworkModelDefViewDefMenuDefProtheus
01 · OVERVIEW

Overview

In AdvPL Framework MVC, ModelDef defines the model and business rules, ViewDef builds the interface connected to that model, and MenuDef declares available operations. The framework supplies the controller behavior. This separation allows the model to be reused by interfaces, automated routines and integrations.

02 · SYNTAX

Syntax

ModelDef() · ViewDef() · MenuDef()

Parameters

ModelDef
Função estáticaRequired

Creates and returns the data model, entities, relationships, validations and persistence.

ViewDef
Função estáticaRequired

Creates and returns the interface, links the model and arranges forms, grids and containers.

MenuDef
Função estáticaRequired

Returns routine operations; FWMVCMenu() may generate the standard set.

03 · PRACTICAL EXAMPLE

Minimal MVC routine structure

#Include "TOTVS.ch"
#Include "FWMVCDef.ch"

// Same structure as the Portuguese example;
// user-facing texts can be localized.
Expected result

ModelDef owns the model, ViewDef connects the interface, and MenuDef supplies operations.

BEST PRACTICES
  • Keep business rules in the Model; the View should handle presentation and interaction.
  • Use unique, stable identifiers for every component.
  • FWFormStruct(1, cAlias) is for the Model and FWFormStruct(2, cAlias) is for the View.
  • Use Help() for Model validation messages.
  • Check the current documentation before using historical signatures or XML integrations.
COMMON PITFALLS
  • Do not use visual messages such as MsgAlert() inside the Model.
  • Each MVC source should have only one ModelDef, ViewDef and MenuDef.
  • Do not persist business rules directly in the View.
  • The supplied PDF contains historical APIs whose support depends on the current release.

Related content

REFERENCES
  1. TOTVS. AdvPL using MVC. Supplied 134-page PDF, generated June 1, 2018; sections and page ranges listed in the Portuguese edition.
  2. TOTVS. AdvPL using MVC manual, version 4.0. TDN.
  3. TOTVS. FWFormModel. TDN.
  4. TOTVS. FWFormView. TDN.
  5. TOTVS. MVC examples. TDN.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR