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?