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)