I ran into the same issue recently and I was able to implement a workaround. Its not perfect, but it seems to be working ok so far. Its for VLF-ONE, but it should be expandable to any web page.
The problem is that when the response from the server comes back, there is no reference to the control (field) that caused the message in the Message Queue. So my solution was to include the field name in the message text. This means we can't use message files, but I am ok with that.
Here is a rule for a field that has the control name specified in the message.

- rule.png (14.71 KiB) Viewed 6923 times
Now we need to collect all the fields on the page. I am using a Keyed Collection so that I can refer to the control by name.
Code: Select all
define_com class(#PRIM_KCOL<#PRIM_EVP #STD_STRNG>) name(#PanelFields) style(Collection)
mthroutine name(CollectEditableControls)
define_map for(*INPUT) class(#PRIM_PCOL<#PRIM_CTRL>) name(#controls) pass(*BY_REFERENCE)
define_com class(#PRIM_EVP) name(#tempField) reference(*DYNAMIC)
define_com class(#PRIM_CPST) name(#tempContainer) reference(*DYNAMIC)
for each(#control) in(#controls)
if_ref com(#control) is(*INSTANCE_OF #PRIM_EVP)
#tempField <= #control *As #PRIM_EVP
#PanelFields<#tempField.Name> <= #tempField
else
if_ref com(#control) is(*INSTANCE_OF #PRIM_CPST)
#tempContainer <= #control *As #PRIM_CPST
#COM_OWNER.CollectEditableControls( #tempContainer.ComponentControls )
endif
endif
endfor
endroutine
That method gets called in the the initialize routine.
Code: Select all
#COM_OWNER.CollectEditableControls( #COM_OWNER.ComponentControls )
Then after the call to the server, I call this method to highlight errors.
Code: Select all
mthroutine name(HighlightProblems)
define_map for(*INPUT) class(#PRIM_KCOL<#PRIM_EVP #STD_STRNG>) name(#fields) pass(*BY_REFERENCE)
define field(#control) type(*STRING)
define field(#errorMessage) type(*STRING)
define field(#separatorIndex) type(*INT)
#avFrameworkManager.avRecordTrace component(#COM_OWNER) event("Highlighting Problems")
#avFrameworkManager.avRecordTrace component(#COM_OWNER) event(("&1 Messages In Queue").Substitute( #SYS_MSGQ.Messages.ItemCount.AsString ))
for each(#message) in(#SYS_MSGQ.Messages)
if (#message.Text.Contains( ":" ))
#separatorIndex := #message.Text.LastPositionOf( ":" )
#control := #message.Text.Substring( 1 (#separatorIndex - 1) )
#errorMessage := #message.Text.Substring( (#separatorIndex + 1) #message.Text.CurChars )
#avFrameworkManager.avRecordTrace component(#COM_OWNER) event(("Message for Control: &1 Message: &2").Substitute( #control #errorMessage ))
if (#fields<#control> *IsNot *NULL)
#fields<#control>.Styles.Add( #Error )
#SYS_MSGQ.Add control(#fields<#control>) text(#errorMessage)
endif
else
* even though we don't have a seperator, we should still display the message
#avFrameworkManager.avIssueMessage text(#message.Text) requester(#COM_OWNER) tomainform(False) clearexistingmessages(False)
endif
endfor
endroutine
You can see that I just parse the name out of the message and use the control collection to get a reference to the problem control.
Also have a custom Error style defined
Code: Select all
define_com class(#PRIM_VS.Style) name(#Error) backgroundbrush(#Brush2) borderbottom(1) borderbrush(#Brush3) borderleft(1) borderright(1) bordertop(1) foregroundbrush(#Brush4)
define_com class(#PRIM_VS.SolidBrush) name(#Brush4) color(255:8:2)
define_com class(#PRIM_VS.SolidBrush) name(#Brush3) color(255:6:0)
define_com class(#PRIM_VS.SolidBrush) name(#Brush2) color(255:215:215)
Now when a field is in error it looks like

- validation error.png (4.66 KiB) Viewed 6923 times
I can clear the errors by this method.
Code: Select all
mthroutine name(ClearProblemHighlights)
define_map for(*INPUT) class(#PRIM_KCOL<#PRIM_EVP #STD_STRNG>) name(#fields) pass(*BY_REFERENCE)
#avFrameworkManager.avRecordTrace component(#COM_OWNER) event("Clearing Problem Hightlights")
for each(#field) in(#fields)
#field.Styles.Remove( #Error )
endfor
#avFrameworkManager.avClearMessages requester(#COM_OWNER)
* this may be redundant
#SYS_MSGQ.ClearAll
endroutine
Like I said, its not perfect, but its working out ok so far.
Joe