简体   繁体   English

javax.faces.SEPARATOR_CHAR是否有通用替代品?

[英]Is there a common replacement for javax.faces.SEPARATOR_CHAR?

I don't like how JSF uses the colon to separate ID's in generated HTML, as it collides with CSS and JavaScript Selectors. 我不喜欢JSF如何使用冒号分隔生成的HTML中的ID,因为它与CSS和JavaScript选择器冲突。 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? 有通用替代品吗?

Well... based on a short googling for the javax.faces.SEPARATOR_CHAR value 好吧……基于对javax.faces.SEPARATOR_CHAR值的简短搜索

It seems that the preferred values are - or _ (at least for BalusC ) 似乎首选值是-_ (至少对于BalusC

You only need to guarantee that you don't use it anywhere in JSF component IDs yourself 您只需要保证自己不在JSF组件ID中的任何地方使用它

By default, JSF generates unusable ids, which are incompatible with css part of web standards 默认情况下,JSF生成不可用的ID,这些ID与Web标准的CSS部分不兼容

How to use JSF generated HTML element ID in CSS selectors? 如何在CSS选择器中使用JSF生成的HTML元素ID?

Disadvantages of JSF, a bit of history JSF的缺点,有点历史

I don't like how JSF uses the colon to separate ID's in generated HTML, as it collides with CSS and JavaScript Selectors. 我不喜欢JSF如何使用冒号分隔生成的HTML中的ID,因为它与CSS和JavaScript选择器冲突。 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? HTML元素的性质真的如此独特,以至于需要由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: 您可以使用任何想要的字符,只要它在HTML元素ID /名称中有效,该ID /名称指定如下:

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 ("."). IDNAME令牌必须以字母([A-Za-z])开头,后跟任意数量的字母,数字([0-9]),连字符(“-”),下划线(“ _”) ,冒号(“:”)和句点(“。”)。

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. 由于句点本身也是CSS选择器中的特殊字符,因此它与冒号有相同的问题。 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 _ . 你需要确保你没有使用JSF组件ID新的分隔符的任何地方,像这样<h:someComponent id="foo_bar" />中的情况下_ Those characters are namely allowed in JSF component IDs (the colon isn't). 在JSF组件ID中即允许使用这些字符( 不允许使用冒号)。 It would break the UIComponent#findComponent() lookup. 它将破坏UIComponent#findComponent()查找。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM