DEV Community

Peter + AI
Peter + AI

Posted on

πŸ“š Understanding Component Entities and Fields in Uniface 10.4

πŸ’‘ Note: This blog post was created with AI assistance to help explain Uniface concepts in simple terms.

🎯 What Are Component Entities?

In Uniface 10.4, a component entity is a data structure that defines what information your component works with. Think of it as a container that holds the data your application needs. Each component can have multiple entities, and how you organize them determines how Uniface processes your data at runtime.

When your application runs, each component entity becomes an occurrence - which is basically a living instance of your data structure that can be manipulated and used.

πŸ”§ Two Types of Component Entities

1. Template-Based Entities 🎨

These are unique to your component and don't store data in a database. They're perfect for creating user interface controls or temporary data that doesn't need to be shared.

Example: Imagine you need a temporary calculation field that shows the sum of two other fields. You'd create a template-based entity for this because the result doesn't need to be saved to the database.

2. Derived Entities πŸ”—

These are created from modeled entities and inherit their definitions, properties, and scripts. This ensures consistency across your application when multiple components access the same data.

Example: If you have a "Customer" entity defined in your data model, any component using customer data would create a derived entity from this model. All components will handle customer data the same way automatically.

🎭 Inheritance and Overriding

Here's the cool part: while derived entities inherit everything from their parent model, you can still override specific properties or scripts locally in your component. When you do this, Uniface uses your local definition instead of the inherited one. This gives you flexibility when you need special behavior in specific components.

πŸ“ What Are Component Fields?

A component field represents a single piece of data within a component entity. Just like entities, fields can be:

  • Derived fields: Inherited from a modeled field πŸ“₯
  • Local fields: Defined directly in your component 🏠

Example: In a Customer entity, you might have fields like:

  • CustomerName (derived from the model)
  • CustomerEmail (derived from the model)
  • DisplayLabel (local field just for this component's UI)

🎨 Widgets: Making Data Visual

The Widget property of a component field is what makes your data visible and interactive for users. It determines:

  • How the field appears on screen πŸ‘€
  • How users can interact with it πŸ–±οΈ

Different Interfaces, Different Widgets

Uniface supports various user interface types, each with its own widget set:

  • Dynamic Server Pages: JavaScript-based widgets 🌐
  • Static Server Pages: HTML controls πŸ“„
  • Forms: Windows controls or Unifields (for character-based platforms) πŸ’»

Example: A "CustomerEmail" field could be displayed as:

  • A text input box on a web page πŸ“§
  • An editable field in a desktop form πŸ“
  • A read-only label in a report πŸ“Š

βš™οΈ Configuring Widget Properties

Widget properties can be set in three places:

  1. Assignment File: Sets default values for all instances πŸ“‹
  2. Properties Inspector: Defines initial values when designing ✏️
  3. Script: Changes values dynamically while your app runs πŸ”„

Example: You might set a text field's maximum length to 50 characters in the Properties Inspector, but your script could disable the field based on user permissions at runtime.

🎯 Why This Matters

Understanding component entities and fields is fundamental to building Uniface applications because:

  • Consistency: Derived entities ensure data is handled the same way across your entire application πŸ”’
  • Flexibility: You can override inherited behavior when needed for specific use cases πŸ”“
  • Reusability: Template-based entities let you create reusable UI patterns πŸ”„
  • Maintainability: Changes to modeled entities automatically propagate to all components using them πŸ“ˆ

πŸš€ Getting Started

When building your next Uniface component:

  1. Identify what data you need πŸ“Š
  2. Decide if you need derived entities (for database data) or template-based entities (for UI controls) πŸ€”
  3. Choose appropriate widgets for your fields based on your user interface type 🎨
  4. Set initial properties in the Properties Inspector βš™οΈ
  5. Add dynamic behavior through ProcScript when needed πŸ’»

By following these principles, you'll create well-structured, maintainable Uniface applications that are easier to develop and extend over time! πŸŽ‰


Keywords: uniface, component, entities, widgets

Top comments (0)