开发者

Trigger JSF validation using ajax after focus lost

How do you trigger validation on an input component when the component loses f开发者_如何学JAVAocus using ajax instead of waiting for the form to be manually submitted?


Put a <f:ajax event="blur"> in the UIInput component which re-renders a <h:message> associated with the component in question.

<h:inputText id="foo" value="#{bean.foo}" required="true">
    <f:ajax event="blur" render="fooMessage" />
</h:inputText>
<h:message id="fooMessage" />

See also JSF 2.0 tutorial with Eclipse and Tomcat - the view and finetuning validation


Try this code:

<h:inputText value="#{bean.value}" valueChangeListener="#{bean.validateValue}">
    <f:ajax event="blur" render="valueError"/>
</h:inputText>

<h:outputText id="valueError" value="#{bean.valueErrorMessage}" style="color: red;" />

If the user changes the value in your input component you can validate it with your valueChangeListener. If the user then moves to another input component the ouputText component will be rendered. There you can display a message if the validation failed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜