Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Tags

 
Raj Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I want to display product prices on JSPs. This is how the prices are displayed:

If the current price of the product is less then the base price then display the base price striked out and the current price in red. Otherwise display the price as normal.

This has to be done on several pages. There is approx 10 lines of code to retreive the base price and the current price of the product, given a productId.

I was thinking of using JSP tags for this but at the same time I dont have much experience with tags.
Can somebody suggest a solution to this using tags?
Should the tag directly return the html to be displayed (red price & etc..)??

Thanks
Amit
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a perfect application for a custom action (formerly known as "custom tags"). It's a display-support operation, which makes it appropriate for on-page use, and will be reused in multiple places and perhaps on multiple pages.

Such tags usually emit the HTML that they are "replacing".

If you are using a JSP 2.0 engine, this custom action might best be implemented as a tag file making use of the JSTL for your logic. Under JSP 1.2, you'll need to use the classic JSP Tag API.
 
Raj Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i am using JSP 1.2 so I cant use custom actions.

More precisely my question is should the TAG class be generating the HTML or as in my case should I just pass back two variables currentPrice, basePrice back to the parent jsp which should determine if the currentPrice is lower than the base price and handle the display accordingly??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i am using JSP 1.2 so I cant use custom actions.


Yes, you can. That was answered by: "Under JSP 1.2, you'll need to use the classic JSP Tag API."


More precisely my question is should the TAG class be generating the HTML


And that was answered by: "Such tags usually emit the HTML that they are 'replacing'."
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!