You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/01/17 03:54:41 UTC

svn commit: r496919 - in /tapestry/tapestry5/tapestry-core/trunk/src/test: app1/WEB-INF/ToDoList.html java/org/apache/tapestry/integration/app1/pages/ToDoList.java

Author: hlship
Date: Tue Jan 16 18:54:40 2007
New Revision: 496919

URL: http://svn.apache.org/viewvc?view=rev&rev=496919
Log:
Refine the PrimaryKeyEncoder interface and DefaultPrimaryKeyEncoder implementation.
Refine and test the Loop component's serialization of state in to the enclosing Form, both in volatile and non-volatile mode.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/ToDoList.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/ToDoList.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/ToDoList.html?view=diff&rev=496919&r1=496918&r2=496919
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/ToDoList.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/ToDoList.html Tue Jan 16 18:54:40 2007
@@ -1,17 +1,17 @@
 <html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
-
+    
     <h1>ToDo List</h1>
-
+    
     <form t:id="form">
-
+        
         <t:comp type="Errors"/>
-
+        
         <table class="t-data-table" cellspacing="0px">
             <tr>
                 <th> Title </th>
                 <th> Reorder </th>
             </tr>
-            <tr t:type="Loop" source="database.findAll()" value="item">
+            <tr t:type="Loop" source="items" value="item" encoder="encoder">
                 <td>
                     <input t:type="TextField" t:id="title" value="item.title" size="30"
                         validate="validate:required"/>
@@ -20,11 +20,17 @@
             </tr>
             <tr>
                 <td colspan="2">
-                   <input type="submit" value="Update ToDos"/>
-                   <input t:type="Submit" value="'Add new ToDo'"/>
-                                   </td>
+                    <input type="submit" value="Update ToDos"/>
+                    <input t:type="Submit" t:id="addNew" value="'Add new ToDo'"/>
+                </td>
             </tr>
- 
+            
         </table>
     </form>
+    
+    
+    <p>
+        <a t:type="ActionLink" t:id="reset">reset the database</a>
+    </p>
+    
 </html>

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java?view=diff&rev=496919&r1=496918&r2=496919
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java Tue Jan 16 18:54:40 2007
@@ -14,6 +14,10 @@
 
 package org.apache.tapestry.integration.app1.pages;
 
+import java.util.List;
+
+import org.apache.tapestry.DefaultPrimaryKeyEncoder;
+import org.apache.tapestry.PrimaryKeyEncoder;
 import org.apache.tapestry.annotations.Component;
 import org.apache.tapestry.annotations.ComponentClass;
 import org.apache.tapestry.annotations.Inject;
@@ -29,9 +33,16 @@
 
     private ToDoItem _item;
 
+    private DefaultPrimaryKeyEncoder<Long, ToDoItem> _encoder;
+
     @Component
     private Form _form;
 
+    public List<ToDoItem> getItems()
+    {
+        return _encoder.getValues();
+    }
+
     public ToDoItem getItem()
     {
         return _item;
@@ -45,5 +56,50 @@
     public ToDoDatabase getDatabase()
     {
         return _database;
+    }
+
+    public PrimaryKeyEncoder getEncoder()
+    {
+        return _encoder;
+    }
+
+    void onPrepare()
+    {
+        List<ToDoItem> items = _database.findAll();
+
+        _encoder = new DefaultPrimaryKeyEncoder<Long, ToDoItem>();
+
+        for (ToDoItem item : items)
+        {
+            _encoder.add(item.getId(), item);
+        }
+    }
+
+    void onSuccess()
+    {
+        int order = 0;
+
+        for (ToDoItem item : _encoder.getValues())
+        {
+            item.setOrder(order++);
+            _database.update(item);
+        }
+    }
+
+    void onSelectedFromAddNew()
+    {
+        if (_form.isValid())
+        {
+            ToDoItem item = new ToDoItem();
+            item.setTitle("<New To Do>");
+            item.setOrder(_encoder.getValues().size());
+
+            _database.add(item);
+        }
+    }
+
+    void onActionFromReset()
+    {
+        _database.reset();
     }
 }