Don't know if this will be useful to anyone else, but I wanted my 
error/warning/notice messages to replace a default bit of text (a 
tagline). After some fiddling, I came up with this, which works quite 
nicely. (Feel free to suggest improvements.)

(Note: I removed some other code I didn't need and this is my own 
version, hence "Messages.")

class Messages {
   def render(styles: NodeSeq): NodeSeq = {
     val f = noIdMessages _
     val msgs = List((f(S.errors),
                     (styles \\ "error_msg"), S.??("msg.error"),
                     ((styles \\ "error_class") ++
                      (styles \\ "error_msg" \\ "@class")), 0),
                    (f(S.warnings),
                     (styles \\ "warning_msg"), S.??("msg.warning"),
                     ((styles \\ "warning_class")++
                      (styles \\ "warning_msg" \\ "@class")), 1),
                    (f(S.notices),
                     (styles \\ "notice_msg"), S.??("msg.notice"),
                     ((styles \\ "notice_class")) ++
                     (styles \\ "notice_msg" \\ "@class"), 2)).flatMap
     {
       case (msg, titleList, defaultTitle, styleList, ord) =>
         val title: String = titleList.toList. filter(_.prefix == 
"lift"). map(_.text.trim).filter(_.length > 0) headOr defaultTitle
         val styles = styleList.toList.map(_.text.trim)
         if (!styles.isEmpty) {
           ord match {
             case 0 => MsgsErrorMeta(Full(AjaxMessageMeta(Full(title), 
Full(styles.mkString(" ")))))
             case 1 => MsgsWarningMeta(Full(AjaxMessageMeta(Full(title), 
Full(styles.mkString(" ")))))
             case 2 => MsgsNoticeMeta(Full(AjaxMessageMeta(Full(title), 
Full(styles.mkString(" ")))))
          }
         }
         msg.toList.map(e => (<li>{e}</li>) ) match {
           case Nil => Nil
           case msgList => val ret = (<div><ul>{msgList}</ul></div>)
             styles.foldLeft(ret)((xml, style) => xml % new 
UnprefixedAttribute("class", Text(style), Null))
         }
     }
     <div>{if (msgs.isEmpty) styles \\ "default" else msgs}</div>
   }
}

Then I do this in the template:

<lift:Messages>
   <lift:error_class>errorBox</lift:error_class>
   <lift:warning_class>warningBox</lift:warning_class>
   <lift:notice_class>noticeBox</lift:notice_class>
   <lift:default><span id="tagline">Just do it</span></lift:default>
</lift:Messages>

So now I get a span with "Just do it" that is replaced by the error, 
warning, or notice message.

Chas.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to