disabling second text field after data validation through ajax of first text field

独自空忆成欢 提交于 2019-12-21 23:26:24

问题


As I was experimenting with JSF 2.0 , i came across a scenario like this .

I have two text fields - based on input of first field an ajax call is fired using

<f:ajax ... />

After the response is back I am re rendering the second text field ..but i want to disable the second text field based on some server side validation of first field value.

I don't want to set the disabled using style based on a third property which is being set in the bean after validation.

Is there any alternative ways..

thanks in advance


回答1:


Bind the first input component to the view by binding attribute and use UIInput#isValid() in the disabled attribute of the second input field. It will return false if validation has failed on the given input component.

<h:inputText binding="#{input1}" value="#{bean.input1}">
    <f:validator validatorId="yourValidator" />
    <f:ajax event="blur" render="input2" />
</h:inputText>
<h:inputText id="input2" value="#{bean.input2}" disabled="#{!input1.valid}" />


来源:https://stackoverflow.com/questions/9589063/disabling-second-text-field-after-data-validation-through-ajax-of-first-text-fie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!