/** * This methods main purpose is to support browser history. * * <p>When the browsers back or forward buttons are pressed, a re-search /might/ be required - * namely if the query changes. So, as the UI requests updates of the page (show,facets, etc) this * method checks if a search must be executed before those updates are performed. * * <p>It will consequently also run a search if the UI updates a search parameter without actually * explicitly executing the search before setting of the polling. * * @see {@link com.indexdata.mkjsf.pazpar2.state.StateManager#setCurrentStateKey} * @param commands */ protected void handleQueryStateChanges(String commands) { if (stateMgr.hasPendingStateChange("search") && hasQuery()) { logger.info( "Triggered search: Found pending search change [" + pzreq.getCommand("search").toString() + "], doing search before updating " + commands); pzreq.getSearch().run(); pzresp.getSearch().setIsNew(false); } if (stateMgr.hasPendingStateChange("record") && !commands.equals("record")) { logger.debug("Found pending record ID change. Doing record before updating " + commands); stateMgr.hasPendingStateChange("record", false); pzreq.getRecord().run(); } }
@PostConstruct public void postConstruct() throws MissingConfigurationContextException { logger.info("Pz2Service PostConstruct of " + this); stateMgr = new StateManager(); pzreq = new Pazpar2Commands(); pzresp = new Responses(); errors = new ErrorCentral(); pzresp.setErrorHelper(errors.getHelper()); logger.debug("Pz2Service PostConstruct: Configurator is " + configurator); logger.debug(Utils.objectId(this) + " will instantiate a Pz2Client next."); pz2Client = new Pz2Client(); spClient = new ServiceProxyClient(); stateMgr.addStateListener(this); try { configureClient(pz2Client, configurator); configureClient(spClient, configurator); this.configure(configurator); } catch (MissingConfigurationContextException mcc) { logger.info("No configuration context available at this point"); logger.debug("Configuration invoked from a Servlet filter before application start?"); throw mcc; } catch (ConfigurationException e) { logger.warn("There was a problem configuring the Pz2Service and/or clients (\"pz2\")"); e.printStackTrace(); } }
/** * Sets the current state key, i.e. when user clicks back or forward in browser history. Would * normally be automatically handled by the frameworks components. * * @param key corresponding to browsers hash string */ public void setCurrentStateKey(String key) { stateMgr.setCurrentStateKey(key); }
/** * Returns the current hash key, used for internal session state tracking and potentially for * browser history entries * * <p>A UI author would not normally be concerned with retrieving this. It's used by the framework * internally * * @return string that can be used for browsers window.location.hash */ public String getCurrentStateKey() { return stateMgr.getCurrentState().getKey(); }