0

I am tring to do some interactive select with JSF. I have that code:

<h:form>
     <h:selectOneMenu value="#{booksController.book}" immediate="true">
          <f:selectItems value="#{booksController.books}" var="book" itemValue="#{book}" itemLabel="#{book.title}" />
          <f:ajax execute="@this" render="book" />
     </h:selectOneMenu>
     <h:panelGroup id="book">
          <div>#{booksController.book.title}</div>
          #{booksController.book.details}
     </h:panelGroup>
</h:form>

And the controller:

@ManagedBean
@ViewScoped
public class BooksController extends Controller {

    private Book book;

    public BooksController() {}

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public Book[] getBooks() {
        return new Book[] { ... };
    }
}

In that example I want to create selectOneMenu of books, that each item is book's title, and on change, the details below will update.

Everything that I tried didn't update the book element correctly. It seems that
#{booksController.book} is not updates at all (booksController is defined as ViewScoped).

How can I make it update correctly?

nrofis
  • 8,975
  • 14
  • 58
  • 113
  • 1
    Give us a brief view of the book controller, including the properties you're using in this examples. – Sam Orozco May 23 '16 at 21:55
  • 1
    Also, Try removing the immediate true. – Sam Orozco May 23 '16 at 21:57
  • @SamOrozco Added the controller to the question. BTW, removing the immediate didn't help... – nrofis May 24 '16 at 10:53
  • For starters, as explicitly mentioned in the above linked duplicate, set JSF project stage to `Development` in web.xml and add `` to view to get notified about development warnings and missing faces messages. Those warnings/messages are in turn [quite](http://google.com/search?q=conversion+error+setting+value+for+null+converter) [googlable](http://google.com/search?q=validation+error+value+is+not+valid). – BalusC May 24 '16 at 11:22
  • I already set the project stage to Development. Why do you think that the code returns validation error? – nrofis May 24 '16 at 11:28
  • Solve the problem with this answer: http://stackoverflow.com/a/13189326/1725836 – nrofis May 24 '16 at 11:58

0 Answers0