How to specify name attribute in h:inputText?
我需要将
1 2 | <input id="yourName" type="text" name="name" /> <input id="email" type="text" name="email" /> |
但是
您无法使用
无论如何,您基本上有两种选择来实现具体的功能要求:
如果没有其他命名容器父项,请指示父表单不要在其ID之前添加ID:
1 | <h:form prependId="false"> |
但是,这将导致
使用纯HTML元素而不是JSF组件:
1 2 | <input name="name" value="#{bean.name}" /> <input name="email" value="#{bean.email}" /> |
您只需要通过
1 2 3 4 5 | @ManagedProperty("#{param.name}") private String name; @ManagedProperty("#{param.email}") private String email; |
而且您会错过JSF内置的验证/转换工具和Ajax Magic。
但是,还有另一种完全不同的选择:使用HTML5
1 | <h:inputText type="email" ... /> |
从JSF 2.2开始更新,您最终可以轻松声明传递属性,而无需自定义渲染工具包。
1 2 3 | <... xmlns:a="http://xmlns.jcp.org/jsf/passthrough"> ... <h:inputText a:type="email" ... /> |
您无需指定name属性就可以执行所需的操作。 id属性就足够了。根据示例尝试以下操作:
1 2 3 4 5 6 | < h:inputText id="email" ... /> ... $("#email input").click(function (event) { ... } |
代替
1 | $("#email input[name='email']").click(function (event) |
希望这是您正在寻找的:)