开发者

Ajax Not Working with h:inputSecret

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜