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

View File

@ -1,29 +1,34 @@
package de.hsel.itech.jsf; package de.hsel.itech.jsf;
import de.hsel.itech.db.Database; import de.hsel.itech.db.Database;
import de.hsel.itech.db.pojo.Book;
import de.hsel.itech.db.pojo.Category; import de.hsel.itech.db.pojo.Category;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ManagedBean @ManagedBean
@ApplicationScoped @ViewScoped
public class CategoryBean implements Serializable { 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() { public List<Category> getCategories() {
return Database.getInstance().getCategories(); return Database.getInstance().getCategories();
} }
public String test() { public List<Book> getBooks() {
return ""; return Database.getInstance().getBooks(category);
} }
} }

View File

@ -6,15 +6,24 @@
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"> xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head> <h:head>
<title>Amazon light</title> <title>Amazon light</title>
</h:head> </h:head>
<h:body> <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/> <br/>
</ui:repeat> </ui:repeat>
</h:body> </h:body>
</html> </html>