This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JSP and the fly likes Custom Tag Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom Tag Question" Watch "Custom Tag Question" New topic

Custom Tag Question

Vic Newman
Ranch Hand

Joined: Mar 01, 2002
Posts: 33
I want to be able to create reusable components for a page. For example a component that displays name and address information that i would be able to place on different pages without having to code the same thing on multiple pages. Can I do this with a custom tag? A simple example or link to an example would be appreciated. Thanks
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63349

Can I do this with a custom tag?


You didn't mention how the address data is making its way to the page, so I will assume you are using a modern Model 2 design.

Let's say that your servlet controller is placing an object of type Address that holds your address data onto the request as a scoped variable named "billingAddress", and another named "shippingAddress".

You could write a custom tag along the lines of:

which will spit out the approriate HTML-formatted data according to what it finds in the scoped variable identified by the "data" attribute.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Custom Tag Question
It's not a secret anymore!