Project Pods - robjshawtag:www.projectpods.com,2008:/projectpods/Mango 1.1Developing a Global Messaging Notification Objecturn:uuid:E33C47CC-3048-79ED-99E34E18121CB9822008-07-02T03:07:23Z2008-07-02T03:07:02ZRob Shaw
<p>For a while now I have been using <a title="Redballoon's Messaging Custom Tag" href="http://labs.redbd.net/projects/msgHandler.cfm">Redballoon's Messaging Custom Tag</a> however I find creating the messages at the VIEW level messy and hard to track down, especially when the VIEW level is not where validation and results happen. So after a fair amount of thinking and talking with my co-workers I developed a messaging object that gets passed into the controller and has the ability to sets messages like this anywhere within the controller. But only in the controller.</p>
<p>
<code>messageHelper.addMessage(<span class='cc_value'>"error"</span>, <span class='cc_value'>"Please Choose a number of students above 0"</span>);</code></p>
<p>Now all I do is push this entire object back to the view and handle it in the main template via a custom tag.</p>
<p>
<code>messages = viewstate.getValue(<span class='cc_value'>"messageHelper"</span>);<br /> <br /> <span class='comment'><!--- html code ---></span></code></p>
<p>This is an abstract from the custom tag that deals with the message object.</p>
<p>
<code>oMsg.clearMsgs();</code></p>
<div class="error">
<p>#aErrors[j]#</p>
</div>
<p>Just a quick note that the <em>oMsg.clearMsgs();</em> is highly important especially when dealing with model-glue. All it does is clear the error array after the messages have been prepared for the UI so they won't build up with every user action with the old messages!</p>
<p>Now all you need to do is make the class <em>error</em> look hot... I personally am very satisfied with <a title="Awesome CSS Framework" href="http://code.google.com/p/blueprintcss/">blueprint</a> which has the class and much much more built into it. But will leave that for another entry.</p>