Dear Wiki user, You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.
The following page has been changed by MichaelJouravlev: http://wiki.apache.org/struts/StateManagement ------------------------------------------------------------------------------ Work in progress! - || - |||||| Client Techniques |||| Server Techniques || + || - |||||||| Client Techniques |||| Server Techniques || - || - || Cookies || HTML form hidden fields || Query parameters || Session || Database || + || - || Cookies || HTML form hidden fields |||| Rewritten URLs || Session || Database || + || - || - || - || Query parameters || Meaningful URLs || || || - |||||||||||| Advantages || + |||||||||||||| Advantages || - || Relatively easy to code || + || || || + || + || + || Relatively easy to code || + || || || || + || + || - || Can store complex data types || || || || + || || + || Can store complex data types || || || || || + || || - || Works well in load balancing environments || + || + || + || || - || + || Works well in load balancing environments || + || + || + || + || || - || |||||||||||| Disadvantages || - || User can tamper with state information || + || + || + || || || + || User can tamper with state information || + || + || + || + || || || - || Requires cookies || + || || || + || || + || Requires cookies || + || || || || + || || - || Requires coding || + || || || + || || + || Requires coding || + || || || || + || || - || Can store only small amount of data (~2,000 bytes) || || || + || || || + || Can store only small amount of data (~2,000 bytes) || || || + || + || || || - || Increased network traffic and slightly slower response times || + || + || + || || || + || Increased network traffic and slightly slower response times || + || + || + || + || || || - || Requires server resources to save state information || || || || + || + || + || Requires server resources to save state information || || || || || + || + || - || Application logic tightly coupled to the user interface implementation || || + || || || || + || Application logic tightly coupled to the user interface implementation || || + || || || || || - |||||||||||| Neither Advantages Or Disadvantages || + |||||||||||||| Neither Advantages Or Disadvantages || - || State and view not related || + || || || + || || + || State and view not related || + || || || || + || || + + - === Rewritten URLs === + == Rewritten URLs == - * State can be preserved on redirection + === Query parameters === + + By year, vehicle, make: + {{{ + www.tirestore.com/selectVehicle.do?yr=2002&mk=TOYOTA&model=mr2spyder + }}} + Pro: * Easy to create: by submitting a form using GET method, by clicking on a link or by manually editing the resource address. * Reloading a page that was previously obtained with GET method does not cause POSTDATA dialog. @@ -43, +52 @@ === Meaningful URLs === + + By year, vehicle, make: + {{{ + www.tirestore.com/vehicle/2002/toyota/mr2spyder/ + }}} + + Pro: * Such URLs look nice and professional. * Such URLs are more likely to be saved by search engines and crawling machines. @@ -56, +72 @@ Best fit: stateless applications like online catalogs or magazines that have hierarchical structure and should be represented as a static website. - === Hidden fields === + == HTML form hidden fields == + + By year, vehicle, make: + {{{ + <form action="..."> + <input type="hidden" name="yr" value="2002"/> + <input type="hidden" name="mk" value="TOYOTA"/> + <input type="hidden" name="model" value="mrspyder"/> + ... + </form> + }}} + Pro: * No size limitations as for query parameters. * URLs are short @@ -80, +107 @@ Implications: Application must provide explicit navigational links and buttons so users would not have to use standard browser navigation buttons. Application must recognize and handle double-submit situations. Application must be able to synchronize client and server state. - === Cookies === + == Cookies == Pro: * Not visible to a user * Can be submitted to originating server only - better security @@ -98, +125 @@ Best fit: non-critical user/client information usually employed for user profiling, like zip code or preferred language. - === Browser objects (DOM elements, Javascript variables, Flash storage) === + == Browser objects (DOM elements, Javascript variables, Flash storage) == Pro: * Can store complex structures and objects. * Depending on application requirements, state can be made relative or non-relative to page address. @@ -111, +138 @@ Best fit: Ajax-style Single Page applications. - === Server session object === + == Server session object == + + === Server session object only === Pro: * Can be tied to model state, not affected by browser state or current page. * Allows to separate the concerns, keeping state safely and securely where model resides, while treating browser as an agent providing interface with a user. @@ -143, +172 @@ Best fit: applications that treat server state as primary state source. Non-Ajax Single Page Applications. - == TODO == - - Select year and make: - www.tirestore.com/initHomeVehicleStyles.do?yr=2002&mk=TOYOTA - - Select model: - www.tirestore.com/assignHomeVehicle.do?yr=2002&mk=TOYOTA&vid=006522 - - Select location: - www.tirestore.com/vehicleSizesStaggered.do?rcz=92078&mk=TOYOTA&rc=CASINT&yr=2002&vid=006522 - - Select size for the car: - www.tirestore.com/searchTiresByVehicleAndSize.do?rcz=92078&mk=TOYOTA&rc=CASINT&yr=2002&cs=205&vid=006522&rd=15&ar=50 - - Refine by brand: - www.tirestore.com/filterTireProducts.do?rc=CASINT&yr=2002&c=1&cf=false&rf=true&rcz=92078&mk=TOYOTA&cs=205&dVeh=dVeh&rd=15&vid=006522&ar=50&ct=&fcb=Kumho&fcsr=*&x=29&y=9 - - Get total price (add to cart): - www.tirestore.com/addToCart.do?rcz=92078&mk=TOYOTA&rc=CASINT&yr=2002&pt=t&pc=33500&vid=006522 - - Store area code in the cookie, so the next search would use already selected area code. - - By year, vehicle, make: - www.tirestore.com/vehicle/2002/toyota/mr2spyder/185-55-15 - www.tirestore.com/vehicle/2002/toyota/mr2spyder/185-55-15/HR/93/KumhoEcstaSPT - - By tire size, speed rating, load rating: - www.tirestore.com/size/185-55-15 - www.tirestore.com/size/185-55-15/HR/93 - www.tirestore.com/size/185-55-15/HR/93/KumhoEcstaSPT - - By brand: - www.tirestore.com/brand/Kumho/185-55-15 - www.tirestore.com/brand/Kumho/185-55-15/HR/93/KumhoEcstaSPT -