Parameters Management for complete website!
On my website's Start page I have a Search Mask where user set select different Search Criteria. When user doee't then the default values will be set for the search parameters.
By clicking on Search buttom user comes on preview page, where the user has possibility to refine his search parameters agaian. And there can by many different types of preview pages. For examples if users searches in Cars category then the preview page be other and the search mask will other as the have searched in Motorcycle category.
But again the detail page is single for all Kind of products.
Now I want to write a component that can hold the start page'S search options and for all different kinds of overview pages.
And I would also like to track that information that from which preview page I landed on detail page and when the user comes from detail page back to Preview page I was to load the desired mask with the values that the user already refined.
What will be the best practice to solv开发者_开发问答e this problem and is there any design pattern available for such kind of problem?
Thanks a lot.
Generally, speaking there's no design pattern for the specific problem you've described. Depending on how you want to model it, you could implement patterns such as Strategy, State and/or Command. Where each of these provides some facility for encapsulating state (e.g. what type of preview and criteria) and some related behavior.
Three options for keeping track of search criteria using different ColdFusion variable scopes:
- session
- cookie
- client
Session scope
This is server memory linked to a give user via a cookie that a developer can place information into. It's designed to expire after a period of inactivity and ColdFusion provides event handling around its initialization and expiration via Application.cfc
. Useful if you decide to have stateful objects attached to each user. Disadvantage is you can run out of memory if a lot of information is put there and/or long lived sessions are used.
Cookie
Sets client cookies. Can easily capture simple data. Cannot capture objects - you would need to serialize and deserialize their state. Scales well because only a cookie is tracked by the server. Easily hacked.
Client
Reads and writes data associated with a user session from persistence. By default this is the registry on Windows - don't use this as it will likely crash your server with dire consequences if the registry becomes corrupted. Instead access the administrator and set it to use a database. Useful when you want to track lots of information about your users as they move about the site, but only scales as well as the backing database. Need to serialize data as with cookie scope.
精彩评论