VL-WEB - using #PRIM_WEB.MessageBox for message processing

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
Jiri
Posts: 43
Joined: Thu Feb 11, 2016 11:41 pm

VL-WEB - using #PRIM_WEB.MessageBox for message processing

Post by Jiri » Thu Mar 03, 2016 4:34 am

Hello,

Shipped #PRIM_WEB.MessageBox is fine base for message processing in VL-WEB.
The aim is use it (in client components) as message collector, which will simple show messages from both server and client side. The message box is used i.e. when a record is saved. It should be displayed in both cases (successful save or error) and it in both situations it should also show message from server module. If okay, the module reports i.e. ‘New record added’ or ‘Record updated’, if not, it should pass the error messages. For simple usage, the messages are collected with separate method, which also sets the Message box title, icon and buttons.
The basic logic:
* in definition part, we declare the component
Define_Com Class(#PRIM_WEB.MessageBox) Name(#MessageBox)

* usage in the save routine
Mthroutine Name(SAVE) Access(*PRIVATE)
Define_Com Class(#IS_Services1.SaveZM) Name(#Save)
#sys_msgq.clearall
#Save.ExecuteAsync Cmd_Type(#CMD_TYPE) Group(#ISZM) Status(#IO$STS)

Evtroutine Handling(#Save.Completed)
If ('#IO$STS *EQ OK')
#COM_SELF.ShowMSGS Messagebuttons(OK) Messagetitle(‘Record saved’) Messageimage(Information)
Else
#COM_SELF.ShowMSGS Messagebuttons(Cancel) Messagetitle(Errors found!') Messageimage(Error)
Endif
Endroutine
endroutine


* routine for message processing
Mthroutine Name(ShowMSGS) Access(*PRIVATE)
Define_Map For(*INPUT) Class(#STD_TEXTS) Name(#MessageTitle)
Define_Map For(*INPUT) Class(#STD_TEXTS) Name(#MessageImage)
Define_Map For(*INPUT) Class(#STD_TEXTS) Name(#MessageButtons)

#MessageBox.Title := #MessageTitle
#MessageBox.Image := #MessageImage
#MessageBox.buttons := #MessageButtons

For Each(#message) In(#sys_Msgq.messages)
#MessageBox.captions.add( #message.text )
Endfor
#MessageBox.Show
#sys_msgq.clearall
Endroutine


*In the Server module is a standard routine, which may issue messages:
Srvroutine Name(SaveZM) Session(*Required)
…….
Use Builtin(CLR_MESSAGES)
…….
Message Msgtxt(‘New task added’)


Problem and question:
Regardless of included #sys_msgq.clearall (on server side) or use Clr_Mesages on server side, the messages inside message box are always added.
It means, after update three records, I can see inside message box:
Task changed
Task changed
Task changed

All the messages are from server module (running on IBMi).
I will welcome any idea, how to successfully clear the older messages, as well as tips for improvement of this logic or simple reuse this logic over more VL-WEB components.

User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: VL-WEB - using #PRIM_WEB.MessageBox for message processing

Post by Stewart Marshall » Thu Mar 03, 2016 9:15 am

Hi Jiri

v14 introduces the #sys_msgq object. This collects all the messages that have been generated by the application, whether that's on the client or the server. It is down to the user to clear the messages whenever they want to. This allows for multiple server requests to be executed without previous messages disappearing. I find it's best to clear all messages (sys_msgq.clearall) immediately before creating a new set.

Once you reach a point where you want to show the messages, something like xDemoWebMessagesPopup is probably a better solution for showing them than the message box component. This is a simple popup panel reusable part that shows whatever messages are on the message queue. You'll note that it does not clear the queue itself.

With specific reference to your issue with the message box, all you need do is remove the captions before showing the messages.

#MessageBox.Captions.RemoveAll should do the trick

Regards
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

User avatar
Jiri
Posts: 43
Joined: Thu Feb 11, 2016 11:41 pm

Re: VL-WEB - using #PRIM_WEB.MessageBox for message processing

Post by Jiri » Thu Mar 03, 2016 9:12 pm

Thanks, that is the correct solution

Post Reply