3 Replies Latest reply on Sep 16, 2008 6:28 PM by Richard Ogin

    Map empties itself

    Richard Ogin Newbie

      The problem boils down to a Map<String, ZipCode> (w/about 40k items) in a conversation scoped bean emptying itself.

      public class ZipCodeManager implements Serializable
           private Session session;
           private Map<String, ZipCode> unassigned = new HashMap< String, ZipCode>();
           private Map<String, ZipCode> test = new HashMap< String, ZipCode>();
           public void initialize()
                List<ZipCode> results = session.createQuery("...").list();
                for(ZipCode z : results)
                     unassigned.put(z.getValue(), z);
                test.put("1", new ZipCode("ONE"));
                test.put("2", new ZipCode("TWO"));
                test.put("3", new ZipCode("THREE"));
              public int getAvailableCount()
                System.err.println("zipCodeManager.getAvailableCount() actual: " + unassigned.size());
                System.err.println("zipCodeManager.getAvailableCount() test: " + test.size());
                return test.size();
              <snip methods that do nothing but print the name of the method being called>

      Calling getAvailableCount() will always have test print 3 but actual can end up emptying itself.

      I have two beans that brought this to light. One is mapped to a page and has a dropdown of states. The user selects one and clicks a button. The method the button is tied to calls the proper ZipCodeManager method and all is well. The other bean allows the user to select a state and then the counties within that state. The user selects a state and the county listbox gets updated by an onchange event on the dropdown (calling stateChanged()). The user then selects some counties and clicks the button. Here's the odd part: If I put a call to zipCodeManager.getAvailableCount() within stateChanged(), everything works okay. When removed, the Map count is zero when I get to the method that the button is tied to. Finally, if I change the Map to a List<ZipCode>, it never empties itself.

      I'm using Seam 2.0.0.GA, JBoss 4.2, zipCodeManager gets injected into the two beans mentioned above, and this is all in a long running conversation.

      Thanks for any help.