• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

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?
Posts: 2292
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?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic