2011-03-15 88 views
2

试图显示一个必需消息用于密码字段,但它不能与Ajax一起使用,一旦输入密码消失。
目前它完全由需要h:inputSecret的属性,但是在做HTTP提交之前Ajax会好很多。
相关摘录:Ajax不能与h一起工作:inputSecret

<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 :)

+0

所以,验证是可以的。但唯一的问题是该领域重新设置? – bluefoot 2011-03-15 15:37:31

+0

确认无误,因为输入密码并尝试输入确认后,输入的密码消失。 – camiloqp 2011-03-15 15:45:48

回答

3

你已添加到render="@this"导致的输入元素的说明解释的答案当一个jax请求完成时,整个input元素将被重新渲染。默认情况下,由于安全原因,表单提交后,<h:inputSecret>值不会重新显示。该tag documentation还告诉它从字面上:

呈现组件的当前值的“值”属性的值,当且仅当在“重新显示”组件属性字符串“true”。

同样的故事适用于ajax rerendering的<h:inputSecret>字段。但是,您可以通过添加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> 
+0

“默认情况下,由于安全原因,表单提交后密码字段值不会重新显示。”这正是我一直在寻找的东西,非常感谢! – camiloqp 2011-03-15 16:19:20

+0

不客气。请注意,我改进了一些答案以添加一些文档链接。 – BalusC 2011-03-15 16:19:46