I don’t want to change the java code whenever there is addition of tag if the business logic will be remain same. I can access it by using Enumeration set of attributes(request.getAttributeNames()).
e.g.
<car:built
maker="ford" wheel="four" name="endeavor" engine="dohc" power="72bhp"
tyre="4" interior="mobile-charger,cigratte-lighter, music player"
/>
Rather than doing comma separated the interior, i wish to add in following way:
<car:built maker="ford" wheel="four" name="endeavor" engine="dohc" power="72bhp"
tyre="4" interior-mobile-charger="true" interior-cigratte-lighter="true"
interior-music-player-maker="JVC" interior-music player-bass="true"/>
So that, i can iterate and check whether attribute name contains "interior" word and store in a map and send it to the reports. It can also help me to define new attribute without changing the java code.
Is there any way to create custom attribute in jsp tag library without defining setter method?
What you’re looking for is called “dynamic attributes”.
See this previous question to see how to do it:
Problem in interpreting dynamic attributes in Jsp
Essentially, you add
To the
.tlddescriptor, indicating that any old attributes can be passed to the tag. Your tag class must then implement theDynamicAttributesinterface, and the undeclared attributes will be passed in to your tag as a map: