Gaurav Goyal
Gaurav Goyal

Reputation: 1

ajax not called when h:inputText is empty

I have an input Text box and 1 button on my screen. I want to enable button only when input Text has some value in it. I have implemented following code and it is working OK when i enter some value and it enables the button. But ajax call is not made when i remove string from input Text and hence button is enabled even when i do not have any value.

code that i tried is

 <h:inputText id="inputText" value="#{bean.value1}" label="Value1" required="true"       
    requiredMessage="value is empty" class="form-control">

    <f:ajax event="keyup" render="clearButton"></f:ajax>

  </h:inputText>

Upvotes: 0

Views: 1201

Answers (1)

Tiago Vieira Dos Santos
Tiago Vieira Dos Santos

Reputation: 1004

try this code without the required true

<h:inputText id="inputText" value="#{bean.value1}" label="Value1" class="form-control">
   <f:ajax event="keyup" render="clearButton"></f:ajax>
</h:inputText>

If this solved your problem you can see more about in http://docs.oracle.com/javaee/1.4/tutorial/doc/JSFIntro10.html

It's a problem with the life circle of JSF, when you set the required like true and the input have no value your method never will be called.

Also you can try put the tag immediate for ignore the validation phase.

Upvotes: 3

Related Questions