288 CHAPTER 9 STATE NAVIGATION PATTERN asynch.username (Web hosting top)
288 CHAPTER 9 STATE NAVIGATION PATTERN asynch.username = this.username; asynch.password = this.password; var splitLocation = location.href.split( “#”); asynch.get( splitLocation[ 0] + this.constURLStateIdentifier); } }, In the implementation of loadState, the Asynchronous class that was explained in Chapter 2 is used. The implementation is relatively straightforward in that an HTTP GET is executed, as illustrated by the method call asynch.get. To let the server know that the request is a state request, the HTTP headers identifying the state (X-Page-State, X-Page-Window-Name) are sent by using the method xmlhttp.setRequestHeader. If the HTTP headers were not present, the server side would consider the request as a generic HTTP GET. The HTTP headers are used, as they are easy to verify for existence. Another approach would have been to search for the state keyword in the URL, but that would require parsing the URL. The method thisReference. verifyWindowNameis used to generate a State Navigation pattern compliant window name if there is no window name. Additionally, to identify the request as a state request, the /stateis appended to the URL when the asynch.get method is called. Not adding the /state would result in confusing the proxy and potentially having two different representations with a single URL, and as per the Permutations pattern, doing so would be incorrect. In the implementation of the asynch.complete inlined function, the returned XML docu ment is processed. The XMLIterateElements function is used to find the XML node that contains the HTML page state. If the XML node (objData.foundElement) is found, the loading of the state is passed to the HTML page implemented function onLoadState. Because a state is retrieved and the server has the power to determine the state identifier, the State Navigation layer must replace the current state identifier. The state identifier is replaced by using the location.replacemethod so that the old page will be replaced in the history log. Not using the location.replace method would result in the addition of an HTML page to the history, and that would confuse the user from a Forward and Back button navigation perspective. For example, if the history contained /other/url, /resource, /resource2, not using the replace method would generate a history /other/url, /resource, /resource#11, /resource2, instead of /other/url, /resource#11, /resource2. Saving the State The implementation of saving the state requires three methods: onSaveState implemented by the client to save the state, the helper method saveForm to convert an HTML form into a state, and saveState to initiate the state persistence. The method onSaveState needs to be implemented by the HTML page, but the default is that the StateController provides an empty implementation that does nothing. If StateController did not provide a default implementation, a JavaScript error would result. Following is the default empty implementation of the method onSaveState: onSaveState : function() { return “”; }, The default implementation of onSaveState illustrates the most important thing that any implementation must do: return a buffer that contains the persisted state. It is expected that
You want to have a cheap webhost for your apache application, then check apache web hosting services.