java - Ajax 无法与 h :inputSecret 一起使用

标签 java ajax validation jsf jsf-2

尝试显示密码字段的必填消息,但是它不适用于 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 :)

最佳答案

您已添加 render="@this"到输入元素,这会导致在 ajax 请求完成时重新渲染整个输入元素。默认情况下, <h:inputSecret> 由于安全原因,表单提交后不会重新显示值。 tag documentation还从字面上讲:

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".

同样的情况也适用于 <h:inputSecret> 的 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>

关于java - Ajax 无法与 h :inputSecret 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5313828/

相关文章:

java - 从队列中获取 O(1) 时间内的最小值/最大值?

javascript - 如何将 IEnumerable 列表从 Ajax 发送到 Controller

algorithm - TNT.com 追踪号码使用什么校验和(如果有)?

各种日期格式的正则表达式

java - 抽象类上的 Hibernate/JPA 映射

java - sun.java2d.opengl=true 不适用于 Windows Netbeans 平台应用程序

java - 保存临时数组列表以在适配器中使用

javascript - 从 ajax 接收结果后打开一个弹出框

ajax - AJAX问题: server is not returning proper status code in the event of a error

javascript - Parsley.js - 密码验证未提交