tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r306653 - in /jakarta/tapestry/trunk: examples/Vlib/src/context/ examples/Vlib/src/context/WEB-INF/ examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/ framework/src/java/org/apache/tapestry/util/
Date Thu, 06 Oct 2005 14:22:38 GMT
Author: hlship
Date: Thu Oct  6 07:22:29 2005
New Revision: 306653

URL: http://svn.apache.org/viewcvs?rev=306653&view=rev
Log:
Continue revving Virtual Library for Tapestry 4.0

Modified:
    jakarta/tapestry/trunk/examples/Vlib/src/context/EditUsers.html
    jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/EditUsers.page
    jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/util/DefaultPrimaryKeyConverter.java

Modified: jakarta/tapestry/trunk/examples/Vlib/src/context/EditUsers.html
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/EditUsers.html?rev=306653&r1=306652&r2=306653&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/EditUsers.html (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/EditUsers.html Thu Oct  6 07:22:29 2005
@@ -36,10 +36,10 @@
             <input type="checkbox" jwcid="lockedOut@Checkbox" selected="ognl:user.lockedOut"/>
           </td>
           <td class="checkbox">
-            <input type="checkbox" jwcid="resetPassword@Checkbox" selected="ognl:resetPassword"/>
+            <input type="checkbox" jwcid="resetPassword@Checkbox" selected="ognl:userConverter.resetPassword"/>
           </td>
           <td class="checkbox">
-            <input type="checkbox" jwcid="delete@Checkbox" selected="ognl:deleted"/>
+            <input type="checkbox" jwcid="delete@Checkbox" selected="ognl:userConverter.deleted"/>
           </td>
         </tr>
       </table>

Modified: jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/EditUsers.page
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/EditUsers.page?rev=306653&r1=306652&r2=306653&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/EditUsers.page (original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/EditUsers.page Thu Oct  6 07:22:29
2005
@@ -28,7 +28,7 @@
   </component>
     
   <component id="loop" type="For">
-  	<binding name="source" value="userList"/>
+  	<binding name="source" value="userConverter.values"/>
   	<binding name="value" value="user"/>
   	<binding name="converter" value="userConverter"/>
   	<binding name="element" value="literal:tr"/>

Modified: jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java?rev=306653&r1=306652&r2=306653&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java
(original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/pages/admin/EditUsers.java
Thu Oct  6 07:22:29 2005
@@ -16,10 +16,8 @@
 
 import java.rmi.RemoteException;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.ejb.FinderException;
@@ -31,10 +29,11 @@
 import org.apache.tapestry.annotations.InjectComponent;
 import org.apache.tapestry.annotations.InjectState;
 import org.apache.tapestry.annotations.Message;
-import org.apache.tapestry.components.IPrimaryKeyConverter;
 import org.apache.tapestry.event.PageBeginRenderListener;
+import org.apache.tapestry.event.PageDetachListener;
 import org.apache.tapestry.event.PageEvent;
 import org.apache.tapestry.form.IFormComponent;
+import org.apache.tapestry.util.DefaultPrimaryKeyConverter;
 import org.apache.tapestry.vlib.AdminPage;
 import org.apache.tapestry.vlib.VirtualLibraryEngine;
 import org.apache.tapestry.vlib.Visit;
@@ -48,7 +47,8 @@
  * 
  * @author Howard Lewis Ship
  */
-public abstract class EditUsers extends AdminPage implements PageBeginRenderListener
+public abstract class EditUsers extends AdminPage implements PageBeginRenderListener,
+        PageDetachListener
 {
     public abstract String getPassword();
 
@@ -58,20 +58,6 @@
 
     public abstract Person getUser();
 
-    public abstract void setUserList(List<Person> users);
-
-    public abstract void setUserMap(Map<Integer, Person> map);
-
-    public abstract Map<Integer, Person> getUserMap();
-
-    public abstract void setResetPasswordKeys(Set<Integer> set);
-
-    public abstract Set<Integer> getResetPasswordKeys();
-
-    public abstract void setDeleteKeys(Set<Integer> set);
-
-    public abstract Set<Integer> getDeleteKeys();
-
     @Message
     public abstract String outOfDate();
 
@@ -93,74 +79,50 @@
     @InjectComponent("password")
     public abstract IFormComponent getPasswordField();
 
-    public class UserConverter implements IPrimaryKeyConverter
+    public class UserConverter extends DefaultPrimaryKeyConverter
     {
+        private Set _resetPasswordValues;
 
-        public Object getPrimaryKey(Object value)
+        public void clear()
         {
-            Person user = (Person) value;
-
-            return user.getId();
+            _resetPasswordValues = null;
+            super.clear();
         }
 
-        public Object getValue(Object primaryKey)
+        public void setResetPassword(boolean resetPassword)
         {
-            Integer id = (Integer) primaryKey;
-
-            return getUserMap().get(id);
-
-            // TODO: Handle null
+            _resetPasswordValues = updateValueSetForLastValue(_resetPasswordValues, resetPassword);
         }
 
-    }
+        public boolean isResetPassword()
+        {
+            return checkValueSetForLastValue(_resetPasswordValues);
+        }
 
-    public IPrimaryKeyConverter getUserConverter()
-    {
-        return new UserConverter();
+        public Set getResetPasswordValues()
+        {
+            return createUnmodifiableSet(_resetPasswordValues);
+        }
     }
 
-    // public void synchronizeUser(IRequestCycle cycle)
-    // {
-    // UserListEditMap map = getListEditMap();
-    //
-    // Person user = (Person) map.getValue();
-    //
-    // if (user == null)
-    // {
-    // getValidationDelegate().record(null, outOfDate());
-    // throw new PageRedirectException(this);
-    // }
-    //
-    // setUser(user);
-    // }
+    private UserConverter _userConverter;
 
-    public boolean isDeleted()
+    public UserConverter getUserConverter()
     {
-        return false;
-    }
+        if (_userConverter == null)
+            _userConverter = new UserConverter();
 
-    public void setDeleted(boolean deleted)
-    {
-        if (deleted)
-            getDeleteKeys().add(getUser().getId());
-    }
-
-    public boolean isResetPassword()
-    {
-        return false;
+        return _userConverter;
     }
 
-    public void setResetPassword(boolean resetPassword)
+    public void pageBeginRender(PageEvent event)
     {
-        if (resetPassword)
-            getResetPasswordKeys().add(getUser().getId());
+        readUsers();
     }
 
-    public void pageBeginRender(PageEvent event)
+    public void pageDetached(PageEvent event)
     {
-        readUsers();
-        setDeleteKeys(new HashSet<Integer>());
-        setResetPasswordKeys(new HashSet<Integer>());
+        _userConverter = null;
     }
 
     private void readUsers()
@@ -171,8 +133,6 @@
         Integer userId = visit.getUserId();
         Person[] users = null;
 
-        List<Person> userList = new ArrayList<Person>();
-
         int i = 0;
         while (true)
         {
@@ -190,23 +150,21 @@
             }
         }
 
-        Map<Integer, Person> map = new HashMap<Integer, Person>();
+        UserConverter converter = getUserConverter();
+
+        converter.clear();
 
         for (i = 0; i < users.length; i++)
         {
             Integer id = users[i].getId();
 
-            // Skip the current user; they can't edit themself
+            // Skip the current user; you aren't allowed to edit yourself
 
             if (id.equals(userId))
                 continue;
 
-            map.put(id, users[i]);
-            userList.add(users[i]);
+            converter.add(id, users[i]);
         }
-
-        setUserMap(map);
-        setUserList(userList);
     }
 
     /**
@@ -219,21 +177,16 @@
 
         VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
 
-        Map<Integer, Person> userMap = getUserMap();
-
-        Set<Integer> deletedIds = getDeleteKeys();
-        Set<Integer> resetPasswordIds = getResetPasswordKeys();
-
-        // Remove any users who have been deleted
-
-        userMap.keySet().removeAll(deletedIds);
+        UserConverter converter = getUserConverter();
 
-        Person[] updates = userMap.values().toArray(new Person[0]);
+        Person[] updates = (Person[]) converter.getValues().toArray(new Person[0]);
+        Integer[] deletedIds = extractIds(converter.getDeletedValues());
+        Integer[] resetPasswordIds = extractIds(converter.getResetPasswordValues());
 
         String password = getPassword();
         setPassword(null);
 
-        if (HiveMind.isBlank(password) && !resetPasswordIds.isEmpty())
+        if (HiveMind.isBlank(password) && resetPasswordIds.length > 0)
         {
             getValidationDelegate().record(getPasswordField(), needPassword());
             return;
@@ -248,12 +201,7 @@
             {
                 IOperations operations = vengine.getOperations();
 
-                operations.updatePersons(
-                        updates,
-                        resetPasswordIds.toArray(new Integer[0]),
-                        password,
-                        deletedIds.toArray(new Integer[0]),
-                        adminId);
+                operations.updatePersons(updates, resetPasswordIds, password, deletedIds,
adminId);
                 break;
             }
             catch (RemoteException ex)
@@ -271,5 +219,24 @@
         }
 
         setMessage(usersUpdated());
+    }
+
+    private Integer[] extractIds(Set valueSet)
+    {
+        int count = valueSet.size();
+
+        Integer[] result = new Integer[count];
+
+        Iterator i = valueSet.iterator();
+        int index = 0;
+
+        while (i.hasNext())
+        {
+            Person person = (Person) i.next();
+
+            result[index++] = person.getId();
+        }
+
+        return result;
     }
 }

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/util/DefaultPrimaryKeyConverter.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/util/DefaultPrimaryKeyConverter.java?rev=306653&r1=306652&r2=306653&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/util/DefaultPrimaryKeyConverter.java
(original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/util/DefaultPrimaryKeyConverter.java
Thu Oct  6 07:22:29 2005
@@ -160,7 +160,7 @@
      */
     public final void setDeleted(boolean deleted)
     {
-        _deletedValues = updateSetForLastValue(_deletedValues, deleted);
+        _deletedValues = updateValueSetForLastValue(_deletedValues, deleted);
     }
 
     /**
@@ -175,7 +175,7 @@
      *            if false, the last value will be removed
      * @return the set passed in, or a new Set instance
      */
-    protected final Set updateSetForLastValue(Set set, boolean inSet)
+    protected final Set updateValueSetForLastValue(Set set, boolean inSet)
     {
         if (inSet)
         {
@@ -212,8 +212,20 @@
 
     public final Set getDeletedValues()
     {
-        return _deletedValues == null ? Collections.emptySet() : Collections
-                .unmodifiableSet(_deletedValues);
+        return createUnmodifiableSet(_deletedValues);
+    }
+
+    /**
+     * Converts a value set into a returnable value; null is converted to the empty set,
and
+     * non-null is wrapped as unmodifiable.
+     * 
+     * @param valueSet
+     *            the set to convert and return
+     * @return a non-null, non-modifiable Set
+     */
+    protected final Set createUnmodifiableSet(Set valueSet)
+    {
+        return valueSet == null ? Collections.emptySet() : Collections.unmodifiableSet(valueSet);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


Mime
View raw message