【问题标题】:Why does JSF generate names in addition to IDs?为什么 JSF 除了生成 ID 之外还生成名称?
【发布时间】:2016-06-01 12:53:12
【问题描述】:

ID 的生成/使用非常清楚,用于将提交的组件重新关联到视图树。

但是为什么 JSF 也会生成名称呢?它在内部使用它们吗?

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    HTML 规范为required,Servlet API 为used。 Web 浏览器使用输入字段名称作为 HTTP 请求参数名称。他们不为此使用输入字段 ID,否则不可能为每个名称发送多个值(选择多个、复选框组等)。

    <h:inputText id="foo">
    

    生成

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

    在 HTTP 请求中进入客户端(通过浏览器的内部代码)

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

    并从 HTTP 请求中提取(通过UIComponent#decode())进入服务器端

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

    另见:

    【讨论】:

      猜你喜欢
      • 2011-06-24
      • 2016-11-19
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 2013-10-05
      • 2012-01-06
      • 1970-01-01
      相关资源
      最近更新 更多