• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Design patterns for Conditional Views.

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am working on one shopping application. I have a header which acts like a container. Sometimes it acts like a container for recommended product, sometimes for advertisement. Right now I am conditionally changing innerHTML of header container for displaying advertisement or recommended product. I may add more categories to display in the header. I kind of feel that this if else will grow with time. Specially every category for example advertisement has more priority than recommended product. So if I get both from the feed I will show advertisement not recommended product. I would like to know what will be the good design for implementing such kind of thing. Is there any design pattern?
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Pawan!

Well champ, this "if-else" thing isn't certainly the best way. Especially in the actual page itself: it is better to keep this logic away from it and have it on the server side. It is better to use HTML/XHTML/JSF/JSP only to display things. Eventually, you might have an "if" there (e.g. to verify if the user can see a particular button), but the less logic you have on pages, the better.

But I think we could use more details to give you some advice. It looks like we're talking about something like an e-commerce, right? You have a page, and you have a header that displays things. Categories have higher priority than products. How do you decide what is going to be displayed on the header? I mean, is it based on the product that is being displayed? How does it work?
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic