Bugfixes for browser history management. Documentation.
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / state / StateManager.java
index d185559..04c9c3f 100644 (file)
@@ -12,7 +12,6 @@ import javax.enterprise.context.SessionScoped;
 import org.apache.log4j.Logger;\r
 \r
 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
-import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
 import com.indexdata.mkjsf.utils.Utils;\r
 \r
 @SessionScoped\r
@@ -90,33 +89,45 @@ public class StateManager implements Serializable {
    * Changes the current state key. Invoked from the UI to have the state \r
    * manager switch to another state than the current one. \r
    * \r
+   * @See  The state field in pz2watch.xhtml<br/> \r
+   *       The state listeners windowlocationhashListener() and StateListener()\r
+   *       in listeners.js<br/>\r
+   *       The method {@link com.indexdata.mkjsf.pazpar2.Pz2Bean#handleQueryStateChanges}<br/>\r
+   *       The class {@link com.indexdata.mkjsf.pazpar2.state.Pazpar2State}<br/> \r
+   * ... for a complete picture of browser history handling.\r
+   * \r
    * @param key\r
    */\r
   public void setCurrentStateKey(String key) {    \r
     if (currentKey.equals(key)) {\r
-      logger.debug("setCurrentStateKey: no key change detected");\r
+      logger.debug("Ignoring request from UI to set state key, already has that key [" + key + "]");\r
     } else {\r
-      logger.debug("State key change. Was: [" + currentKey + "]. Will be ["+key+"]");\r
+      logger.debug("Request from UI to change state key from: [" + currentKey + "] to ["+key+"]");\r
       if (states.get(key)==null) {\r
-        logger.error("The back-end received an unknow state key, probably UI generated: ["+ key +"].");\r
+        logger.error("Have no state registered for the key ["+ key +"].");\r
         if (key == null || key.length()==0) {\r
-          logger.info("Empty key received, treating it as identical to current key going forward.");\r
+          logger.info("Recived an empty key, retaining currentKey [" + currentKey + "]");\r
           key = currentKey;\r
         } else {\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
+            if (key.equals("#1")) {\r
+              logger.info("Initial key created [" + key + "], but already got a state registered for the current key [" + currentKey + "]. Retaining current key.");\r
+              key = currentKey;\r
+            } else {\r
+              logger.info("Current search state cached under both new key [" + key + "] and current key [" + currentKey + "]");\r
+              states.put(key,states.get(currentKey));\r
+            }\r
           }\r
         }\r
       }\r
       \r
       if (states.get(key).getCommand("search").equals(states.get(currentKey).getCommand("search"))) {\r
-        logger.debug("No search change detected");\r
+        logger.debug("No search change detected as a consequence of processing the key ["+key+"]");\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.debug("No record change detected as a consequence of processing the key ["+key+"]");\r
       } else {\r
         hasPendingStateChange("record",true);\r
       }\r