0

I have code:

                <p:inputText id="inputNumber value="#{BookSearcher.form.inputNumber}" onkeypress="if(event.which &lt; 48 || event.which &gt; 57 ) if(event.which != 8) return false;" />

                <p:commandButton value="Submit" actionListener="#{BookSearcher.submit}" update="book"/>
                <h:outputText id="book" value="#{BookSearcher.form.book}" ></h:outputText>

 public void submit(){
   long number;
   number=form.getInputNumber();

   Book book; 
   book = bookService.getBook(number);
   form.setBook(book);
   }

I want to input number in box and output book name from database Ex: input :12084---> out put :Harry Potter but it's not working and error:bind => [0] If I change code in Bean as book = bookService.getBook(12084); it's working.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
dsadffg
  • 65
  • 1
  • 1
  • 5

1 Answers1

0

You need to put all <h:inputXxx/> components in a <h:form> to bind their value to the Bean. See How to send form input values and invoke a method in JSF bean

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
mpoqq
  • 96
  • 5
  • How would submit would have been called if the form had been missing? – Jasper de Vries Mar 16 '18 at 19:30
  • Based on the the empty line in the minimal example I assumed it is probably that the form covers only the commandButton and the outputText. – mpoqq Mar 16 '18 at 20:46
  • @b3taa: the example is minimal (maybe too minimal) but not complete... So before 'guessing', always ask for a [mcve] first (typing [ mcve ] without the spaces is a shortcut). And if the question is basically a duplicate of an existing one, you can vote to close it as a duplicate... Thanks for trying to help out though, appreciated. – Kukeltje Mar 17 '18 at 08:34