尝试显示密码字段的必填消息,但是它不适用于 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 :)
最佳答案
您已添加 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/