This post is based on Uniface Documentation 10.4 and was created with AI assistance.
Hey developer community! π
Today we're diving into the fascinating world of Uniface trigger activation. If you've ever worked with event-driven applications, you know how complex the behind-the-scenes processes can be. Uniface is no exception β but fortunately, there's a clear logic behind it! π§
π― What Are Triggers in Uniface?
Uniface applications are event-driven. This means that certain events activate corresponding triggers. These triggers can be activated by various sources:
- π€ User actions (clicks, inputs, etc.)
- π ProcScript statements
- π External events (asynchronous interrupts)
When an event occurs, the corresponding trigger is activated, and the script contained within determines what happens next. Pretty straightforward, right? π€
π Implicit Trigger Activation
Here's where it gets interesting! Some events happen implicitly β meaning they're automatically triggered without you having to explicitly program them.
A typical example in Form components:
π loseFocus - Field-level trigger
π leaveModifiedKey - Occurrence-level trigger
βοΈ leaveModified - Occurrence-level trigger
Imagine this: A user modifies a key field and attempts to store the data without actually leaving the field. What happens behind the scenes? π
π Cascading Processing
This is the exciting part! A single user click can trigger a chain reaction. Let's look at what happens when storing (^STORE
) in a Form component:
The Domino Effect π
π±οΈ User clicks a button β
^STORE
function is activated-
β Uniface automatically activates the required validation triggers:
-
validate
andvalidateKey
(data validation) -
loseFocus
,leaveModifiedKey
,leaveModified
(event completion)
-
πΎ Store trigger of the component is activated
βοΈ Write trigger is activated for every modified entity occurrence
π formatToDbms trigger is activated for each field
ποΈ Data is passed to the database connector and stored in the database
π§© The Different Trigger Levels
Uniface organizes triggers in different hierarchy levels:
Level | Example Triggers | Description |
---|---|---|
ποΈ Component |
store , accept , preActivate , postActivate , receiveMessage , quit
|
Acts on the entire component |
π Occurrence |
write , delete , validate , validateKey , writeUp , deleteUp
|
Acts on record level |
π·οΈ Field |
loseFocus , formatToDbms , formatFromDbms , validate , error
|
Acts on individual fields |
β οΈ Important Note for Developers
Here's a critical point: If you omit the store
statement in the store
trigger, the write
trigger won't be activated! This means your data won't be saved to the database. π±
; β
Correct - activates write trigger
store
; β Wrong - write trigger won't be activated
; (store statement missing)
π Uniface 10 Specific Features
Explicit Trigger Declaration π
One of the most important changes in Uniface 10 is that triggers must be explicitly declared using the trigger
statement:
trigger triggerName
; Your trigger code here
; Example: validation logic, data processing, etc.
end
This is a significant departure from earlier versions where triggers could be implicitly defined. Every trigger you want to use must be explicitly declared, even if it only contains comments or whitespace.
Default Behavior Clarification π§
It's important to understand that most triggers have NO default behavior. This means:
- If you don't define a trigger, nothing happens when the corresponding event occurs
- Only a few specific triggers have implicit behavior that activates when no explicit trigger is defined
- This gives developers complete control over application behavior
Inheritance and Override Rules ποΈ
In Uniface 10, trigger inheritance follows strict rules:
- Local trigger declaration breaks inheritance - even if the trigger is empty
- When you declare a trigger locally, it completely overrides any inherited behavior
- This applies even to triggers that contain only comments or whitespace
; This breaks inheritance even though it's "empty"
trigger validate
; Even this comment breaks inheritance!
end
; This also breaks inheritance
trigger validate
end
π― The Complete Processing Flow
When a user performs a simple "modify and store" action, Uniface actually processes multiple triggers behind the scenes:
-
loseFocus
- field-level trigger -
leaveModifiedKey
- occurrence-level trigger -
leaveModified
- occurrence-level trigger -
store
- component-level trigger -
write
(orwriteUp
) - occurrence-level trigger for every occurrence that needs updating -
formatToDbms
- field-level trigger for every field stored in encrypted format -
delete
(ordeleteUp
) - occurrence-level trigger for every removed occurrence
Much of this processing can be handled with single ProcScript instructions like store
, write
, and delete
. If all triggers complete successfully, the user's data is correctly stored in the database.
πΌ Best Practices for Uniface 10 Developers
1. Always Declare Your Triggers Explicitly β
trigger validate
; Always use explicit trigger declaration
if (fieldvalue < 0)
error "Value must be positive"
endif
end
2. Understand Inheritance Impact π
; Be aware that this breaks inheritance
trigger validate
; Your custom validation
; Parent validation is NO LONGER called
end
3. Handle Cascading Carefully β‘
trigger store
; Remember: omitting 'store' prevents write triggers
store ; This line is CRITICAL
end
- Document Your Trigger Dependencies π
trigger write
; This trigger depends on:
; - validate trigger completing successfully
; - formatToDbms trigger for field formatting
; - store trigger activation
end
π Debugging Trigger Chains
When debugging complex trigger chains, consider:
- Enable trace logging to see trigger activation sequence
-
Use breakpoints in critical triggers like
validate
andwrite
- Check for missing explicit declarations - a common source of bugs in Uniface 10
- Verify inheritance behavior - ensure parent triggers are called when expected
πΌ Summary
Trigger activation in Uniface is like a perfectly orchestrated symphony:
- A single event can trigger a complex chain of triggers
- Uniface automatically handles data validation and integrity
- The hierarchy (Component β Occurrence β Field) ensures structured processing
- Each trigger has its specific role in the overall process
- Uniface 10 requires explicit declaration of all triggers
- Inheritance rules are strict - local declaration always overrides parent behavior
π€ Conclusion
Uniface's event-driven architecture may seem complex at first glance, but it provides a powerful and flexible foundation for robust applications. The automatic cascading processing ensures that your data remains consistent and validated β even when much more is happening behind the scenes than the user sees! π
Uniface 10 brings additional structure and control through explicit trigger declarations, giving developers complete control over application behavior while maintaining the powerful cascading capabilities that make Uniface unique.
The beauty of this system lies in its implicit intelligence β developers don't need to manually orchestrate every step of the validation and storage process. Uniface handles the complexity while providing clear extension points through triggers.
Understanding these concepts is crucial for building maintainable, robust Uniface applications. The explicit nature of Uniface 10 triggers might require more initial setup, but it provides better code clarity and prevents many common inheritance-related bugs.
Have you worked with Uniface triggers before? How has your experience been with the transition to Uniface 10's explicit trigger declarations? Share your experiences in the comments! π¬
Based on Uniface Documentation 10.4 - Trigger Activation (last updated: August 22, 2024)
Top comments (0)