Ajax 无法使用 h:inputSecret
尝试显示密码字段的必填消息,但是它不适用于 Ajax,一旦输入密码,它就会消失。
目前,它仅由 h:inputSecret
的 required 属性完成,但是在进行 HTTP 提交之前,Ajax 会更好。
相关片段:
<h:inputSecret id="newPassword"
value="#{changePassword.password}"
autocomplete="off"
required="true"
requiredMessage="#{i18n['javax.faces.component.UIInput.REQUIRED']}">
<f:ajax event="blur"
render="@this Password_Message"/>
</h:inputSecret>
<h:message id="Password_Message" for="newPassword" errorClass="error"
tooltip="true" />
非常感谢对为什么会发生这种情况进行说明性解释的答案,仍在学习 JSF 2.0 :)
Trying to display a Required Message for a Password field, however it is not working with Ajax, once the password is entered it disappears.
Currently its solely done by the required property of the h:inputSecret
, however the Ajax would be much better, before doing the HTTP submit.
Relevant Snippet:
<h:inputSecret id="newPassword"
value="#{changePassword.password}"
autocomplete="off"
required="true"
requiredMessage="#{i18n['javax.faces.component.UIInput.REQUIRED']}">
<f:ajax event="blur"
render="@this Password_Message"/>
</h:inputSecret>
<h:message id="Password_Message" for="newPassword" errorClass="error"
tooltip="true" />
An answer with an illustrative explanation of why is this happening is very appreciated, still learning JSF 2.0 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将
render="@this"
添加到输入元素,这会导致在 ajax 请求完成时重新呈现整个输入元素。默认情况下,
值。 标签文档还告诉从字面上看:同样的情况也适用于
字段的 ajax 重新渲染。不过,您可以通过添加redisplay="true"
来强制重新显示。或者干脆去掉
render="@this"
,因为这本质上是完全没有必要的。You've added a
render="@this"
to the input element which causes that the whole input element will be rerendered when ajax request has finished. By default,<h:inputSecret>
values are not redisplayed after a form submit due to security reasons. The tag documentation also tells it literally:The same story applies on ajax rerendering of
<h:inputSecret>
fields. You can however force redisplaying by addingredisplay="true"
.Or just get rid of
render="@this"
, because this is in essence completely unnecessary.