How to specify error message text within the Java code of an edit validate rule
A developer asks: I want to learn the best way to present friendly, meaningful error messages for invalid property values.
Our application includes a flow action that allows users to specify a list of dates entered into Date-Calendar-formatted properties. The properties use the standard edit validate rule named IsValidDate. This has the advantage that validation occurs every time a user submits the flow action. A red X appears with the tooltip:
Invalid date specified for IsValidDate.
However, users would like a friendlier error message, one that refers them to the correct date format.
Rule-Message rules are designed to allow configurable messages. What is the best way to associate a Rule-Message with a Rule-Edit-Validate rule? We could use a Rule-Obj-Validate rule,but that needs to be called from within an activity. This would require that we create at least two more rules just to change an error message.
We tried the calling the PublicAPI function theProperty.addMessage() to pass a (optionally parameterized) Rule-Message into the error message that is returned from the Java in the Rule-Edit-Validate. However, this function adds a second Rule-Message text to the property; it doesn't alter the above message.
The error message that appears when a property fails to pass a Rule-Edit-Validate rule is always from the Rule-Message named PropertyInfo-EditValidate. You cannot override this message.
However, when writing an edit validate rule, you can access the property value being edited through the ClipboardProperty Java variable named
theProperty. Two other Java variables established are:
theValue —the String value of the property
itsType — a char representing the type of the property (one of the constants from PropertyInfo TYPE_*.
Therefore, your Java code can add an additional message to the property .
This is the best way to tailor the message.
Published October 17, 2005 — Updated November 15, 2015