Attempts to fix state handling accross XHTML pages.
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 14 May 2013 18:31:06 +0000 (14:31 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Tue, 14 May 2013 18:31:06 +0000 (14:31 -0400)
Approach may also handle UI generated locationhashes - to be seen though.

src/main/java/com/indexdata/mkjsf/pazpar2/state/StateManager.java

index ef6d2f7..5f5aaf4 100644 (file)
@@ -97,20 +97,29 @@ public class StateManager implements Serializable {
     } else {\r
       logger.debug("State key change. Was: [" + currentKey + "]. Will be ["+key+"]");\r
       if (states.get(key)==null) {\r
-        logger.error("The back-end received an unknow state key: ["+ key +"].");        \r
-      } else {\r
-        if (states.get(key).getCommand("search").equals(states.get(currentKey).getCommand("search"))) {\r
-          logger.debug("No search change detected");\r
-        } else {\r
-          hasPendingStateChange("search",true);\r
-        }\r
-        if (states.get(key).getCommand("record").equals(states.get(currentKey).getCommand("record"))) {\r
-          logger.debug("No record change detected");\r
+        logger.error("The back-end received an unknow state key, probably UI generated: ["+ key +"].");\r
+        if (key == null || key.length()==0) {\r
+          logger.info("Empty key received, treating it as identical to current key going forward.");\r
+          key = currentKey;\r
         } else {\r
-          hasPendingStateChange("record",true);\r
+          if (states.get(currentKey) != null) {\r
+            logger.info("Current search state cached under both of [" + key + "] and [" + currentKey + "]");\r
+            states.put(key,states.get(currentKey));\r
+          }\r
         }\r
-        currentKey = key;\r
-      }      \r
+      }\r
+      \r
+      if (states.get(key).getCommand("search").equals(states.get(currentKey).getCommand("search"))) {\r
+        logger.debug("No search change detected");\r
+      } else {\r
+        hasPendingStateChange("search",true);\r
+      }\r
+      if (states.get(key).getCommand("record").equals(states.get(currentKey).getCommand("record"))) {\r
+        logger.debug("No record change detected");\r
+      } else {\r
+        hasPendingStateChange("record",true);\r
+      }\r
+      currentKey = key;            \r
     }\r
   }\r
 \r