java - A pattern for stack of urls -
i have following question. have application set of jsps , action classes control interaction user. actions set parameters required page display properly. urls in system contain name of event defines page should go next.
now, every page has cancel button should lead previous page. start each cancel button url strictly defined, eventually, system grew larger , larger, turned out quite hard program logic button lead previous page.
for example, suppose have 3 pages, a, b , c. page has link leading page b, , b has link leading c. therefore c has url leading b (and contains key of entity display on b). however, suppose page modified , has link on c. need check on c page there came , set url appropriately, , logic becomes pretty mixed.
so, proposed team following solution. user session should contain special object called cancelstack. every action, leads page, should push it's url inside stack (containing event , additional data required). on every page cancel button should have url leading special event, called cancelstack.
what cancelstack action this:
- retrieve cancel stack session.
- pop last url , not use it.
- pop url again , redirect url.
why retrieve last url without using? suppose have pages , b, leading b. action places it's url inside stack, , should cancel url b page. now, action b places it's url inside stack. therefore pop without using, , pop first url, redirect action, , action adds url again stack (therefore stack size decreases 1, not 2).
it seems pretty scheme, seems rather strange top element of stack popped without using. therefore have question. there design patter in order store sequence of urls inside session in order organise cancel buttons properly?
what did seems reasonable me. honest can't think of design pattern addressing issue right now, think if besides cancelstack keep reference currenturl push currenturl stack if don't end in cancel page rid of pop annoys you.
otherwise pop top of cancelstack.
e.g. in example:
suppose have pages , b, leading b...
currenturl a. action not cancel currenturl i.e. a pushed cancelstack. action b , currenturl b action cancel b not placed in stack. top of cancelstack a (while currenturl b). if pop cancelstack retrieve a (no pop needed)
Comments
Post a Comment