+ dropdown with categories, not working fully

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-05-17 08:38:11 +02:00
parent 3f727eae72
commit 32896e0cc3
3 changed files with 58 additions and 44 deletions

View File

@ -45,7 +45,7 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
@ -76,7 +76,7 @@
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>

View File

@ -1,29 +1,34 @@
package de.hsel.itech.jsf;
import de.hsel.itech.db.Database;
import de.hsel.itech.db.pojo.Book;
import de.hsel.itech.db.pojo.Category;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import java.util.List;
@ManagedBean
@ApplicationScoped
@ViewScoped
public class CategoryBean implements Serializable {
private String hello = "Hallo Welt";
private Category category;
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
public String getHello() {
return hello;
}
public List<Category> getCategories() {
return Database.getInstance().getCategories();
}
public String test() {
return "";
public List<Book> getBooks() {
return Database.getInstance().getBooks(category);
}
}

View File

@ -6,15 +6,24 @@
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Amazon light</title>
<title>Amazon light</title>
</h:head>
<h:body>
<ui:repeat value="#{categoryBean.categories}" var="category">
<h:outputText value="#{category.name}"/>
<h:form>
<h:selectOneMenu value="#{categoryBean.category}" onchange="this.form.submit()">
<f:selectItems value="#{categoryBean.categories}" var="category" itemValue="#{category.id}" itemLabel="#{category.name}"/>
</h:selectOneMenu>
</h:form>
<ui:repeat value="#{categoryBean.books}" var="book" rendered="not empty #{categoryBean.category}">
<h:outputText value="#{book.title}"/>
<h:graphicImage value="https://source.unsplash.com/#{book.image}/150x150"/>
<br/>
</ui:repeat>
</ui:repeat>
</h:body>
</html>