• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best Practices: JavaScript, CSS and Custom Tags?

 
J. Gregory Wright
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please point me in the direction of any information regarding "best practices" for combining JavaScript and/or CSS with JSP custome tags? I ask this question because of concerns raised at work over writing custom tags that do one or both of the following:

- Rely on certain JavaScript libraries (such as Prototype or Script.aclulo.us, or application-sepecific JavaScript) being present, because the "onchange" or "onclick" attributes on generated HTML tags would invoke functions from those libraries.

- Rely on certain CSS classes to be present when rendering HTML tags vs. embedding a default set of style selectors to apply if no "styleClass" attribute is specified for the tag.

I'm not really concerned about supporting one approach or the other - I'm more interested in what people have been doing that actually works. TIA...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me, the JSP and custom tags are just there to write the HTML for you, so if it's something you'd do in HTML, it's ok to do in custom tags.
 
J. Gregory Wright
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Bear, are you basically saying that if you were on the receiving end of a custom tag library that had dependencies on external JavaScript libraries, you would not have a problem with it (as long as the documentation that accompanied the custom tag libraries explicitly named those libraries and their versions)?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J. Gregory Wright:
So Bear, are you basically saying that if you were on the receiving end of a custom tag library that had dependencies on external JavaScript libraries, you would not have a problem with it (as long as the documentation that accompanied the custom tag libraries explicitly named those libraries and their versions)?


Ah, are these for internal use or public consumption? These two are horses of very different colors. I assumed the former, where you have much greater control and knowledge of the page environment.

For public consumption I'd think much harder about using external libraries. Forcing someone to use Protoype who prefers jQuery, or vice versa, in order to use your tags might tick people off.

If however the tags were specifically targetted at one audience or another, or if their purpose is to extend a particular library's capabilities, that's a different matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regards to CSS, I almost always provide a default internal set of style class names (so the user doesn't have to define his/her own if they don't want to) but alos allow them to override these names with names of their own choosing if they prefer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!