Map empties itself
gimpy21 Sep 12, 2008 5:59 PMThe problem boils down to a Map<String, ZipCode> (w/about 40k items) in a conversation scoped bean emptying itself.
@Name("zipCodeManager") @Scope(ScopeType.CONVERSATION) public class ZipCodeManager implements Serializable { @In(required=false) private Session session; private Map<String, ZipCode> unassigned = new HashMap< String, ZipCode>(); private Map<String, ZipCode> test = new HashMap< String, ZipCode>(); @Create 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.