3

The generation / use of IDs is fairly clear, for reassociating submitted components to the view tree.

But why does JSF generate names as well? Does it use them internally?

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71

1 Answers1

3

It's required by HTML specification and used by Servlet API. Webbrowsers use input field names as HTTP request parameter names. They do not use input field IDs for that as it would otherwise be impossible to send multiple values per name (select multiple, checkbox groups, etc).

I.e.

<h:inputText id="foo">

generates

<input type="text" id="formId:foo" name="formId:foo" />

which gets in client side prepared (by webbrowser's internal code) in HTTP request as

element.getAttribute("name") + "=" + element.getAttribute("value")

and gets in server side extracted (by UIComponent#decode()) from the HTTP request as

String foo = request.getParameter(component.getClientId());

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555