Announcement Announcement Module
No announcement yet.
ROO Form Element ID Names Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ROO Form Element ID Names

    First, I have searched the forums and cannot find a similar thread. I am working on a team developing web applications with ROO and related technologies. I am new to JSP and ROO, so perhaps I'm missing something.

    When using JSP templates to create Web forms in concert with ROO, I notice that the HTML sent to the useragent includes illegal values for input IDs. I.e, it is best to avoid underscores completely, but AFAIK it is outright illegal to begin an ID value with anything other than [A-Za-z].

    When I try to validate using any of the HTML4+ or XHTML1+ doctypes, I get this:
    Line 10, Column 13: value of attribute "FOR" invalid: "_" cannot start a name

    <label for="_firstName_id">

    It is possible that you violated the naming convention for this attribute. For example, id and name attributes must begin with a letter, not a digit.

    I've spent several hours today reviewing best practices for HTML, XML, XHTML on ID and CLASS attributes to make sure I'm not going mad. Is "seems" that if IDs like "_firstName_id" are working, it must be browser forgiveness.

    Is there a specific reason, other than to avoid ID collision, that the IDs are automagically generated with leading underscores? Is anyone running into validation problems with this convention?

    Thanks in advance.

  • #2
    Some documentation of why not to use underscores

    The specs for HTML 4.01 and XHTML 1.0 are fairly old, but the proposed HTML5 spec is not scheduled for full adoption until 2022 I think. So these rules of the browser are going to be with us a while (and I cannot tell if HTML5 supports initial underscores in ID attributes or not):

    From the W3C HTML 4.01 Specification:
    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 (".").
    From the W3C XHTML 1.0 Specification:
    Note that the collection of legal values in XML 1.0 Section 2.3, production 5 is much larger than that permitted to be used in the ID and NAME types defined in HTML 4. When defining fragment identifiers to be backward-compatible, only strings matching the pattern [A-Za-z][A-Za-z0-9:_.-]* should be used. See Section 6.2 of [HTML4] for more information.
    From CSS guru Eric Meyer:
    Avoid Underscores: Because of their twisted support history, you are strongly encouraged not to use underscores in class and id values. Hyphens are permitted and are a common substitute (as in test-class).


    • #3
      Can you please raise this as a improvement ticket in our Jira? Most of the underscore use is already removed in current trunk (will be available with the Roo 1.1 release).