I don't like how JSF uses the colon to separate ID's in generated HTML, as it collides with CSS and JavaScript Selectors. And I don't like the idea of always escaping it. Thus I would like to replace it by some other character. Are there any drawbacks? And is there a common replacement?
2 Answers
Well... based on a short googling for the javax.faces.SEPARATOR_CHAR
value
It seems that the preferred values are -
or _
(at least for BalusC)
You only need to guarantee that you don't use it anywhere in JSF component IDs yourself
By default, JSF generates unusable ids, which are incompatible with css part of web standards
-
Are there any drawbacks, when using a `-` or a `_`? – Bruno Schäpper Sep 27 '12 at 10:46
-
Nope, And I don't think the following http://code.google.com/p/primefaces/issues/detail?id=490 is something that you should consider as a drawback , but INMO you can work just fine with the default `:` separator , I'm working with intense jquery usage and never had any issues with the `:` (don't consider escaping it from time to time as a real issue) – Daniel Sep 27 '12 at 10:52
I don't like how JSF uses the colon to separate ID's in generated HTML, as it collides with CSS and JavaScript Selectors. And I don't like the idea of always escaping it.
Just select elements by classname then? Is the HTML element's nature really so unique that it requires being selected by an ID? This is usually only the case for main layout components.
Thus I would like to replace it by some other character. Are there any drawbacks? And is there a common replacement?
You can use any character you want, provided that it's valid in HTML element ID/name which is specified as follows:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Next to the colon, the only sensible choices are the hyphen, the underscore and the period. As the period is at its own also a special character in CSS selectors, it would have the same problem as the colon. So logically you don't have much other choice than the hyphen -
and the underscore _
.
As to the drawbacks, certainly there are drawbacks. You need to ensure that you are not using the new separator character anywhere in JSF component IDs like so <h:someComponent id="foo_bar" />
in case of _
. Those characters are namely allowed in JSF component IDs (the colon isn't). It would break the UIComponent#findComponent()
lookup.