[Coldbox 3.5.2] Trying out MessageBox - how to setMessage() with multiple messages?

I’m trying out MessageBox for the first time. In some of my code I call setMessage() and set a message, then later in other processing I call it again. But only the last message ends up displaying in my view when I call getPlugin(“messageBox”).renderit(true). Am I using it wrong? I know it can take an array of messages, but I need to report back status from different areas of code. It doesn’t all happen in one place where I can just put all the messages into an array.

Shouldn’t I be able to call setMessage() and queue up several messages to be displayed?

Yes when you render it, pass clearMessage=false will stop the render it from clearing the messages.

Hi Scott. Are you sure? From the documentation I understood that true would clear the queue of messages, and false would not. It seems like I’m having trouble getting more than one message queued.

I’m not seeing any difference between

<cfset getPlugin(“messagebox”).setMessage(“info”, “test1”)>
<cfset getPlugin(“messagebox”).setMessage(“warning”, “test2”)>
<cfset getPlugin(“messagebox”).setMessage(“error”, “test3”)>
#getPlugin(“messageBox”).renderit(false)#

and

<cfset getPlugin(“messagebox”).setMessage(“info”, “test1”)>
<cfset getPlugin(“messagebox”).setMessage(“warning”, “test2”)>
<cfset getPlugin(“messagebox”).setMessage(“error”, “test3”)>
#getPlugin(“messageBox”).renderit(true)#

I always only get “test3”.

If you read the documentation, or if you would like you can go to the coldbox folder and look in the plugins folder. There are a heap of methods that you should be looking at.

If you are doing that then you want to look at the append and appendArray etc., as these allow what you are trying to achieve.

So yeah I am sure, as sure as my name is Andrew :slight_smile:

Sorry, thank you Andrew. :slight_smile: Yes I have been looking at the documentation since I started (http://wiki.coldbox.org/wiki/Plugins:MessageBox.cfm). I saw the appendArray() method but I had missed append() so thanks for pointing that out. Unfortunately that doesn’t seem to work either, I end up with “test1test2test3” all in a “info” type of box, even though the other messages are other types.

I’m trying to replace an older home grown solution where I can say

addMsg(“error”,“process A failed”)
addMsg(“error”, “process B failed”)
addMsg(“info”, “process C passed”)

And in my template I have #showMsgs()# which would result in

(in red)
The following errors occurred:

  • process A failed
  • process B failed

(in green)
process C passed

That was in ModelGlue, and rather than bring it over to my new ColdBox site I thought I would try the built in MessageBox plugin but it seems that it can’t do what I need it to.

Thanks for the help.

np Ryan…

Are they arrays you adding?

No, not adding arrays. Just adding success or fail messages in one request but in different places in code as things are processed.

Just on another note, the message box is designed to be one type of box. Not mix n match error and info etc. If you want to do that then you will need to look at two messageBox objects.

Also I am sure most of the ones without arrays, require that the the text end with a

Now having said all that, what you could do is create a plugin that extends the original plugin and change the renderer to do what you need, or change the methods to do what you need.

Yes but you could do this

messageBox.AppendArray([myMessage]); It still does the same thing but as an array