0

i'm using jsf and ajax. I want to catch inputText change, and print text out to console. Here is xhtml file:

<h:form>
      <h:inputText id="name" name="string" value="#{class.string}" >
         <f:ajax listener="#{class.printString}" event="valueChange" execute="name"/>
      </h:inputText>

   </h:form>

and here managedBean, "printString" function

public void printString(AjaxBehaviorEvent event) {

        System.out.println(string);
    }
andy
  • 33
  • 5
  • Andy, next time when you ask a question, elaborate "not working" in developer's perspective instead of enduser's perspective. There are at least two red herrings in the code which you left unmentioned. Reading JS console and server log as instructed in the duplicate should already give clues. See further also http://stackoverflow.com/tags/jsf/info for guidelines. – BalusC Mar 22 '16 at 08:10
  • @BalusC Always a pleasure to get corrected by you ;) – Gimby Mar 22 '16 at 08:22
  • @BalusC thank you so much) – andy Mar 22 '16 at 09:22

1 Answers1

-2

Try this:

<h:inputText id="name" name="string" value="#{class.string}" >
  <f:ajax listener="#{class.printString}" event="keyup" execute="name"/>
</h:inputText>

Also change searchString to string in backing method. Because h:inputText have value for string

public void printString(AjaxBehaviorEvent event) {

        System.out.println(searchString);
    }

MORE

See official

Sarz
  • 1,970
  • 4
  • 23
  • 43