Is there a general replacement for javax.faces.SEPARATOR_CHAR?

I don't like the way JSF uses a colon to separate the identifier in the generated HTML, as it interferes with CSS and JavaScript Selectors. And I do not like the idea of ​​always avoiding this. Therefore, I would like to replace him with another character. Are there any disadvantages? And is there a general replacement?

+4
source share
2 answers

I don't like the way JSF uses a colon to separate the identifier in the generated HTML, as it interferes with CSS and JavaScript Selectors. And I do not like the idea of ​​always avoiding this.

Just select items by class name then? Is the nature of the HTML element really so unique that an identifier is required to select it? This usually applies only to the main components of the layout.


So, I would like to replace him with another character. Are there any disadvantages? And is there a general replacement?

You can use any character you want, provided that it is valid in the ID / name of the HTML element, which is specified as follows:

Signs

ID and NAME must begin with a letter ([A-Za-z]), followed by any number of letters, numbers ([0-9]), hyphens ("-"), underscores ("_"), colons ( ":") and periods (".").

Next to the colon, the only reasonable choices are hyphen, underscore, and period. Since this period itself is a special character in CSS selectors, it will have the same problem as the colon. Therefore, logically you have no choice but a hyphen - and an underscore _ .

As for the flaws, then of course there are flaws. You need to make sure that you are not using the new separator character anywhere in the JSF component identifiers, for example <h:someComponent id="foo_bar" /> in the case of _ . These characters are allowed in the identifiers of JSF components (colon is not specified). This will violate the search for UIComponent#findComponent() .

See also:

+3
source

Well ... based on a short search by value javax.faces.SEPARATOR_CHAR

It seems that the preferred values ​​are - or _ (at least for BalusC )

You only need to ensure that you do not use it anywhere in the JSF component identifiers yourself

By default, JSF generates unusable identifiers that are incompatible with part of the css web standards

How to use JSF generated HTML element identifier in CSS selectors?

JSF disadvantages, a bit of history

+3
source

Source: https://habr.com/ru/post/1436525/


All Articles