Ajax 无法使用 h:inputSecret

发布于 2024-10-22 05:17:22 字数 685 浏览 2 评论 0原文

尝试显示密码字段的必填消息,但是它不适用于 Ajax,一旦输入密码,它就会消失。
目前,它仅由 h:inputSecretrequired 属性完成,但是在进行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2024-10-29 05:17:22

您已将 render="@this" 添加到输入元素,这会导致在 ajax 请求完成时重新呈现整个输入元素。默认情况下, 值。 标签文档还告诉从字面上看:

当且仅当“redisplay”组件属性为字符串“true”时,将组件的当前值渲染为“value”属性的值。

同样的情况也适用于 字段的 ajax 重新渲染。不过,您可以通过添加 redisplay="true" 来强制重新显示。

<h:inputSecret redisplay="true">
    <f:ajax event="blur" render="@this messageid" />
</h:inputSecret >

或者干脆去掉 render="@this",因为这本质上是完全没有必要的。

<h:inputWhatever>
    <f:ajax event="blur" render="messageid" />
</h:inputWhatever>

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:

Render the current value of the component as the value of the "value" attribute, if and only if the "redisplay" component attribute is the string "true".

The same story applies on ajax rerendering of <h:inputSecret> fields. You can however force redisplaying by adding redisplay="true".

<h:inputSecret redisplay="true">
    <f:ajax event="blur" render="@this messageid" />
</h:inputSecret >

Or just get rid of render="@this", because this is in essence completely unnecessary.

<h:inputWhatever>
    <f:ajax event="blur" render="messageid" />
</h:inputWhatever>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文