Title: [waffle-scm] [480] trunk/waffle-taglib/src/main/resources/META-INF: messages tag together with the acceptance tests

Diff

Modified: trunk/integration/waffle-taglib/src/main/java/org/codehaus/waffle/taglib/acceptance/ProductsController.java (479 => 480)

--- trunk/integration/waffle-taglib/src/main/java/org/codehaus/waffle/taglib/acceptance/ProductsController.java	2007-12-14 20:25:32 UTC (rev 479)
+++ trunk/integration/waffle-taglib/src/main/java/org/codehaus/waffle/taglib/acceptance/ProductsController.java	2007-12-14 20:28:20 UTC (rev 480)
@@ -4,6 +4,7 @@
 import org.codehaus.waffle.validation.ErrorsContext;
 import org.codehaus.waffle.validation.FieldErrorMessage;
 import org.codehaus.waffle.validation.GlobalErrorMessage;
+import org.codehaus.waffle.i18n.MessagesContext;
 
 /**
  * @Author Fabio Kung
@@ -14,4 +15,9 @@
     public void add(String name, Double price) {
         // has validation errors...
     }
+
+    public void showMessages(MessagesContext messages) {
+        messages.addMessage("success", "Successful!");
+        messages.addMessage("operation", "Operation done.");
+    }
 }

Modified: trunk/integration/waffle-taglib/src/main/webapp/index.jsp (479 => 480)

--- trunk/integration/waffle-taglib/src/main/webapp/index.jsp	2007-12-14 20:25:32 UTC (rev 479)
+++ trunk/integration/waffle-taglib/src/main/webapp/index.jsp	2007-12-14 20:28:20 UTC (rev 480)
@@ -15,7 +15,7 @@
     <a href="" />
     <a href="" />
     <a href="" />
-    <a href="" />
+    <a href="" w:messages and w:message</a><br />
 
 </body >
 </html>

Modified: trunk/integration/waffle-taglib/src/main/webapp/products.jsp (479 => 480)

--- trunk/integration/waffle-taglib/src/main/webapp/products.jsp	2007-12-14 20:25:32 UTC (rev 479)
+++ trunk/integration/waffle-taglib/src/main/webapp/products.jsp	2007-12-14 20:28:20 UTC (rev 480)
@@ -2,6 +2,7 @@
 <html>
 <head><title>Errors tag acceptance test</title></head>
 <body>
+<h1>Errors tag test:</h1>
 <h2>All errors:</h2>
 <ul id="allErrors">
   <w:errors>
@@ -37,5 +38,16 @@
   </w:errors>
 </ul>
 
+<h1>Messages tag test:</h1>
+<p><a id="showMessagesAction" href="" Messages</a></p>
+<ul id="messages">
+  <w:messages>
+    <li>${message}</li>
+  </w:messages>
+</ul>
+
+<p id="successMessage"><w:message key="success"/></p>
+<p id="failureMessage"><w:message key="failure"/></p>
+
 </body>
-</html>
\ No newline at end of file
+</html>

Copied: trunk/integration/waffle-taglib/src/test/java/org/codehaus/waffle/taglib/acceptance/MessagesTest.java (from rev 475, trunk/integration/waffle-taglib/src/test/java/org/codehaus/waffle/taglib/acceptance/ErrorsTest.java) (0 => 480)

--- trunk/integration/waffle-taglib/src/test/java/org/codehaus/waffle/taglib/acceptance/MessagesTest.java	                        (rev 0)
+++ trunk/integration/waffle-taglib/src/test/java/org/codehaus/waffle/taglib/acceptance/MessagesTest.java	2007-12-14 20:28:20 UTC (rev 480)
@@ -0,0 +1,25 @@
+package org.codehaus.waffle.taglib.acceptance;
+
+/**
+ * @Author Fabio Kung
+ */
+public class MessagesTest extends IntegrationTest {
+
+    public void testEmptyMessagesContextGivesNoMessage() {
+        open("products.waffle");
+        int messagesCount = selenium.getXpathCount("//[EMAIL PROTECTED]'messages']/li").intValue();
+        assertEquals(0, messagesCount);
+        assertTrue(selenium.getText("successMessage").trim().length() == 0);
+        assertTrue(selenium.getText("failureMessage").trim().length() == 0);
+    }
+
+    public void testShowMessagesActionGivesTwoMessages() {
+        open("products.waffle");
+        selenium.click("showMessagesAction");
+        selenium.waitForPageToLoad("2000");
+        int messagesCount = selenium.getXpathCount("//[EMAIL PROTECTED]'messages']/li").intValue();
+        assertEquals(2, messagesCount);
+        assertFalse(selenium.getText("successMessage").trim().length() == 0);
+        assertTrue(selenium.getText("failureMessage").trim().length() == 0);
+    }
+}

Modified: trunk/waffle-taglib/src/main/java/org/codehaus/waffle/taglib/Functions.java (479 => 480)

--- trunk/waffle-taglib/src/main/java/org/codehaus/waffle/taglib/Functions.java	2007-12-14 20:25:32 UTC (rev 479)
+++ trunk/waffle-taglib/src/main/java/org/codehaus/waffle/taglib/Functions.java	2007-12-14 20:28:20 UTC (rev 480)
@@ -7,6 +7,7 @@
 import org.codehaus.waffle.validation.ErrorMessage;
 import org.codehaus.waffle.validation.ErrorsContext;
 import org.codehaus.waffle.validation.ErrorMessage.Type;
+import org.codehaus.waffle.i18n.MessagesContext;
 
 /**
  * A collection of utility functions accessible in taglibs
@@ -55,4 +56,7 @@
         }
     }
 
+    public static String findMessageForKey(MessagesContext messagesContext, String key) {
+        return messagesContext.getMessage(key);
+    }
 }

Added: trunk/waffle-taglib/src/main/resources/META-INF/tags/message.tag (0 => 480)

--- trunk/waffle-taglib/src/main/resources/META-INF/tags/message.tag	                        (rev 0)
+++ trunk/waffle-taglib/src/main/resources/META-INF/tags/message.tag	2007-12-14 20:28:20 UTC (rev 480)
@@ -0,0 +1,12 @@
+<%@ taglib uri="http://waffle.codehaus.org" prefix="w" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
+<%@ attribute name="messages" type="org.codehaus.waffle.i18n.MessagesContext" required="false" %>
+<%@ attribute name="key" required="true" %>
+
+<c:if test="${empty messages}">
+  <c:set var="messages" value="${requestScope.messages}"/>
+</c:if>
+<c:if test="${not empty messages}">
+  ${w:findMessageForKey(messages, key)}
+</c:if>

Copied: trunk/waffle-taglib/src/main/resources/META-INF/tags/messages.tag (from rev 475, trunk/waffle-taglib/src/main/resources/META-INF/tags/errors.tag) (0 => 480)

--- trunk/waffle-taglib/src/main/resources/META-INF/tags/messages.tag	                        (rev 0)
+++ trunk/waffle-taglib/src/main/resources/META-INF/tags/messages.tag	2007-12-14 20:28:20 UTC (rev 480)
@@ -0,0 +1,15 @@
+<%@ taglib uri="http://waffle.codehaus.org" prefix="w" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ attribute name="messages" type="org.codehaus.waffle.i18n.MessagesContext" required="false" %>
+<%@ variable name-given="message" scope="NESTED" %>
+
+<c:if test="${empty messages}">
+  <c:set var="messages" value="${requestScope.messages}"/>
+</c:if>
+<c:if test="${not empty messages}">
+  <c:if test="${messages.messageCount gt 0}">
+    <c:forEach var="message" items="${messages.messages}">
+      <jsp:doBody/>
+    </c:forEach>
+  </c:if>
+</c:if>

Modified: trunk/waffle-taglib/src/main/resources/META-INF/waffle.tld (479 => 480)

--- trunk/waffle-taglib/src/main/resources/META-INF/waffle.tld	2007-12-14 20:25:32 UTC (rev 479)
+++ trunk/waffle-taglib/src/main/resources/META-INF/waffle.tld	2007-12-14 20:28:20 UTC (rev 480)
@@ -49,11 +49,30 @@
     </function-signature>
   </function>
 
+  <function>
+    <name>findMessageForKey</name>
+    <description>Find message for the ginven key</description>
+    <function-class>org.codehaus.waffle.taglib.Functions</function-class>
+    <function-signature>
+      java.lang.String findMessageForKey(org.codehaus.waffle.i18n.MessagesContext, java.lang.String)
+    </function-signature>
+  </function>
+
   <tag-file>
 		<name>errors</name>
 		<path>/META-INF/tags/errors.tag</path>
 	</tag-file>
 
+  <tag-file>
+		<name>messages</name>
+		<path>/META-INF/tags/messages.tag</path>
+	</tag-file>
+
+  <tag-file>
+		<name>message</name>
+		<path>/META-INF/tags/message.tag</path>
+	</tag-file>
+
   <!-- checkbox tag -->
   <tag>
     <name>checkbox</name>


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to