From f2b616670e73050d049ab39bcf5db0025fd4e693 Mon Sep 17 00:00:00 2001 From: RAU Date: Tue, 28 Jul 2015 22:19:18 +0200 Subject: [PATCH] added a demo to show trees and tables --- TreeAndTable/.gitignore | 8 + TreeAndTable/README.md | 9 + TreeAndTable/pom.xml | 103 ++++++++++ .../bootsfaces/examples/Person.java | 34 ++++ .../jsf/sample/carshop/BasicView.java | 62 ++++++ .../de/beyondjava/jsf/sample/carshop/Car.java | 111 +++++++++++ .../jsf/sample/carshop/CarBean.java | 73 +++++++ .../jsf/sample/carshop/CarPool.java | 180 ++++++++++++++++++ .../jsf/sample/carshop/DynamicOptionBean.java | 138 ++++++++++++++ .../jsf/sample/carshop/SelectionBean.java | 56 ++++++ .../jsf/sample/carshop/SettingsBean.java | 54 ++++++ .../jsf/sample/carshop/StaticOptionBean.java | 138 ++++++++++++++ .../src/main/webapp/WEB-INF/faces-config.xml | 8 + TreeAndTable/src/main/webapp/WEB-INF/web.xml | 23 +++ TreeAndTable/src/main/webapp/index.xhtml | 66 +++++++ 15 files changed, 1063 insertions(+) create mode 100644 TreeAndTable/.gitignore create mode 100644 TreeAndTable/README.md create mode 100644 TreeAndTable/pom.xml create mode 100644 TreeAndTable/src/main/java/de/beyondjava/bootsfaces/examples/Person.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/BasicView.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/Car.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarBean.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarPool.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/DynamicOptionBean.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SelectionBean.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SettingsBean.java create mode 100644 TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/StaticOptionBean.java create mode 100644 TreeAndTable/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 TreeAndTable/src/main/webapp/WEB-INF/web.xml create mode 100644 TreeAndTable/src/main/webapp/index.xhtml diff --git a/TreeAndTable/.gitignore b/TreeAndTable/.gitignore new file mode 100644 index 0000000..8d629d4 --- /dev/null +++ b/TreeAndTable/.gitignore @@ -0,0 +1,8 @@ +/target/ +rebel.xml +.metadata +.settings +dist +.faces-config.xml.jsfdia +.project +.classpath \ No newline at end of file diff --git a/TreeAndTable/README.md b/TreeAndTable/README.md new file mode 100644 index 0000000..762e79d --- /dev/null +++ b/TreeAndTable/README.md @@ -0,0 +1,9 @@ +# BootsFaces-Examples: PrimeFaces, Trees and Tables +This demo is a sketch how to use a tree to filter the content of a data table2 + +Run this as a Tomcat application. The URL to start typically is http://localhost:8080/BootsFacesTreeAndTable/index.jsf + +Tested on: + diff --git a/TreeAndTable/pom.xml b/TreeAndTable/pom.xml new file mode 100644 index 0000000..ac2773f --- /dev/null +++ b/TreeAndTable/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + de.beyondjava + BootsFacesTreeAndTable + 1.0.0-SNAPSHOT + war + BootsFacesTreeAndTable + http://www.beyondjava.net + + UTF-8 + 1.7 + 1.7 + + + + prime-repo + PrimeFaces Maven Repository + http://repository.primefaces.org + default + + + + + net.bootsfaces + bootsfaces + 0.8.0-SNAPSHOT + + + org.primefaces + primefaces + 5.2 + compile + + + org.primefaces.themes + bootstrap + 1.0.10 + runtime + + + de.beyondjava + angularFaces-core + 2.1.2 + + + + + ApplicationServer + + false + + + + com.sun.faces + jsf-api + 2.2.12 + provided + + + + + Mojarra + + true + + + + com.sun.faces + jsf-api + 2.2.12 + compile + + + com.sun.faces + jsf-impl + 2.2.12 + runtime + + + + + MyFaces + + false + + + + org.apache.myfaces.core + myfaces-api + 2.2.7 + compile + + + org.apache.myfaces.core + myfaces-impl + 2.2.7 + runtime + + + + + \ No newline at end of file diff --git a/TreeAndTable/src/main/java/de/beyondjava/bootsfaces/examples/Person.java b/TreeAndTable/src/main/java/de/beyondjava/bootsfaces/examples/Person.java new file mode 100644 index 0000000..62ddd3e --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/bootsfaces/examples/Person.java @@ -0,0 +1,34 @@ +package de.beyondjava.bootsfaces.examples; + +import java.util.Date; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ViewScoped; + +@ViewScoped +@ManagedBean +public class Person { + + private String firstName; + private String lastName; + private Date birthdate; + public Date getBirthdate() { + return birthdate; + } + public void setBirthdate(Date birthdate) { + this.birthdate = birthdate; + } + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/BasicView.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/BasicView.java new file mode 100644 index 0000000..cd28c22 --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/BasicView.java @@ -0,0 +1,62 @@ +package de.beyondjava.jsf.sample.carshop; + +import java.io.Serializable; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.ViewScoped; +import org.primefaces.model.DefaultTreeNode; +import org.primefaces.model.TreeNode; + +@ManagedBean(name = "treeBasicView") +@ViewScoped +public class BasicView implements Serializable { + + private TreeNode root; + + @ManagedProperty("#{dynamicOptionBean}") + private DynamicOptionBean dynamicOptions; + + @ManagedProperty("#{staticOptionBean}") + private StaticOptionBean staticOptions; + + public StaticOptionBean getStaticOptions() { + return staticOptions; + } + + public void setStaticOptions(StaticOptionBean staticOptions) { + this.staticOptions = staticOptions; + } + + public DynamicOptionBean getDynamicOptions() { + return dynamicOptions; + } + + public void setDynamicOptions(DynamicOptionBean dynamicOptions) { + this.dynamicOptions = dynamicOptions; + } + + @PostConstruct + public void init() { + root = new DefaultTreeNode("Root", null); + TreeNode all = new DefaultTreeNode("Car pool", root); + List brands = staticOptions.getBrands(); + for (String brand : brands) { + if (brand != null && brand.length() > 0) { + TreeNode b = new DefaultTreeNode(brand, all); + List types = dynamicOptions.getTypesToBrand(brand); + for (String type : types) { + if (type != null && type.length() > 0) { + TreeNode t = new DefaultTreeNode(type, b); + } + } + } + } + } + + public TreeNode getRoot() { + return root; + } +} \ No newline at end of file diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/Car.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/Car.java new file mode 100644 index 0000000..bf73907 --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/Car.java @@ -0,0 +1,111 @@ +/** + * (C) 2013-2014 Stephan Rauh http://www.beyondjava.net + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.beyondjava.jsf.sample.carshop; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; + +public class Car { + String brand; + + public int getMileage() { + return mileage; + } + + public void setMileage(int mileage) { + this.mileage = mileage; + } + + public String getFuel() { + return fuel; + } + + public void setFuel(String fuel) { + this.fuel = fuel; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + String type; + + @Min(1886) + @Max(2014) + int year; + + @Min(0) + @Max(1000000) + int mileage; + + String fuel; + + @Min(1) + @Max(5000000) + int price; + + private boolean visible=true; + + public Car() { + } + + public Car(String brand, String type, int year, String color, int mileage, String fuel, int price) { + this.brand = brand; + this.type = type; + this.year = year; + this.mileage = mileage; + this.fuel = fuel; + this.price = price; + } + + public String getBrand() { + return brand; + } + + + public String getType() { + return type; + } + + public int getYear() { + return year; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public void setType(String type) { + this.type = type; + } + + public void setYear(int year) { + this.year = year; + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarBean.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarBean.java new file mode 100644 index 0000000..e6a1359 --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarBean.java @@ -0,0 +1,73 @@ +package de.beyondjava.jsf.sample.carshop; + +import java.io.Serializable; +import java.util.Map; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.context.FacesContext; + +@ManagedBean +@SessionScoped +public class CarBean implements Serializable { + private static final long serialVersionUID = 1L; + + + private Car car; + + public CarBean() { + + } + + public String showDetails(Car car) { + this.car = car; + return "details.jsf"; + } + + public String getBrand() { + return car.getBrand(); + } + + public void setBrand(String brand) { + car.setBrand(brand); + } + + public String getType() { + return car.getType(); + } + + public void setType(String type) { + car.setType(type); + } + + public int getPrice() { + return car.getPrice(); + } + + public void setPrice(int price) { + car.setPrice(price); + } + + public int getMileage() { + return car.getMileage(); + } + + public void setMileage(int mileage) { + car.setMileage(mileage); + } + + public int getYear() { + return car.getYear(); + } + + public void setYear(int year) { + car.setYear(year); + } + + public String getFuel() { + return car.getFuel(); + } + public void setFuel(String fuel) { + car.setFuel(fuel); + } +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarPool.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarPool.java new file mode 100644 index 0000000..c99678b --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/CarPool.java @@ -0,0 +1,180 @@ +/** + * (C) 2013-2014 Stephan Rauh http://www.beyondjava.net + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.beyondjava.jsf.sample.carshop; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.faces.application.FacesMessage; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.SessionScoped; +import javax.faces.context.FacesContext; + +import org.primefaces.event.NodeSelectEvent; +import org.primefaces.model.TreeNode; + +@ManagedBean +@SessionScoped +public class CarPool implements Serializable { + private static final long serialVersionUID = 1L; + + private final static int SIZE_OF_INITIAL_CAR_POOL = 1000; + + private TreeNode selectedNode; + + private String filterBrand = null; + private String filterType = null; + + @ManagedProperty("#{staticOptionBean}") + private StaticOptionBean staticOptions; + + public StaticOptionBean getStaticOptions() { + return staticOptions; + } + + public void setStaticOptions(StaticOptionBean staticOptions) { + this.staticOptions = staticOptions; + } + + public DynamicOptionBean getDynamicOptions() { + return dynamicOptions; + } + + public void setDynamicOptions(DynamicOptionBean dynamicOptions) { + this.dynamicOptions = dynamicOptions; + } + + @ManagedProperty("#{dynamicOptionBean}") + private DynamicOptionBean dynamicOptions; + + private List types; + + private int currentYear = Calendar.getInstance().get(Calendar.YEAR); + + private List carPool; + + public List getCarPool() { + return carPool; + } + + public List getVisibleCarPool() { + List vcp = new ArrayList(); + for (Car c: carPool) { + if (c.isVisible()) + vcp.add(c); + } + return vcp; + } + + private List selectedCars; + + public List getSelectedCars() { + return selectedCars; + } + + /** This method is also used as actionListener */ + @PostConstruct + public void initRandomCarPool() { + types = dynamicOptions.getTypesToBrand(null); + carPool = new ArrayList(); + for (int i = 0; i < SIZE_OF_INITIAL_CAR_POOL; i++) { + carPool.add(getRandomCar()); + } + selectedCars = carPool; + } + + public void setCarPool(List carpool) { + this.carPool = carpool; + } + + private Car getRandomCar() { + int typeIndex = (int) Math.floor(Math.random() * (types.size() - 1)); + String type = types.get(typeIndex + 1); + String brand = dynamicOptions.getBrandToType(type); + int year = (int) (Math.floor((currentYear - 1980) * Math.random())) + 1980; + int age = currentYear - year; + + int price = 60000 / (1 + age) + (int) Math.floor(Math.random() * 10000); + + int mileage = (int) (Math.floor((age + 1) * 20000 * Math.random())); + + int colorIndex = (int) Math.floor(Math.random() * (staticOptions.getColors().size() - 1)); + String color = staticOptions.getColors().get(colorIndex + 1); + + int fuelIndex = (int) Math.floor(Math.random() * (staticOptions.getFuels().size() - 1)); + String fuel = staticOptions.getFuels().get(fuelIndex + 1); + + Car c = new Car(brand, type, year, color, mileage, fuel, price); + return c; + } + + public TreeNode getSelectedNode() { + return selectedNode; + } + + public void setSelectedNode(TreeNode selectedNode) { + this.selectedNode = selectedNode; + } + + public void onNodeSelect(NodeSelectEvent event) { + TreeNode treeNode = event.getTreeNode(); + TreeNode parent = treeNode.getParent(); + if (parent.getParent()==null) { + setFilterBrand(null); + setFilterType(null); + } + else if (parent.getParent().getParent() != null) { + setFilterBrand(parent.getData().toString()); + setFilterType(treeNode.getData().toString()); + } + else { + setFilterBrand(treeNode.getData().toString()); + setFilterType(null); + } + + for (Car c: carPool) { + boolean visible = true; + if (getFilterBrand() != null) { + visible &= getFilterBrand().equals(c.getBrand()); + } + if (getFilterType() != null) { + visible &= getFilterType().equals(c.getType()); + } + c.setVisible(visible); + } + } + + public String getFilterBrand() { + return filterBrand; + } + + public void setFilterBrand(String filterBrand) { + this.filterBrand = filterBrand; + } + + public String getFilterType() { + return filterType; + } + + public void setFilterType(String filterType) { + this.filterType = filterType; + } +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/DynamicOptionBean.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/DynamicOptionBean.java new file mode 100644 index 0000000..daf2461 --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/DynamicOptionBean.java @@ -0,0 +1,138 @@ +/** + * (C) 2013-2014 Stephan Rauh http://www.beyondjava.net + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.beyondjava.jsf.sample.carshop; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +@ManagedBean +@SessionScoped +public class DynamicOptionBean implements Serializable { + + private static final long serialVersionUID = 1L; + private Map brand2Type = new HashMap(); + + private List types = new ArrayList(); + + public DynamicOptionBean() { + initBrandsAndTypes(); + + types.add(""); + types.add("A180"); + types.add("C200"); + types.add("E320"); + types.add("Civic"); + types.add("Golf"); + types.add("320"); + types.add("V50"); + types.add("Astra"); + types.add("Megane"); + types.add("Picasso"); + types.add("Ibiza"); + types.add("Punto"); + + types.add("Jazz"); + types.add("Passat"); + types.add("Polo" ); + types.add("C40"); + types.add("C60"); + types.add("V70"); + types.add("Corsa"); + types.add("Vectra"); + types.add("León" ); + types.add("Exeo" ); + types.add("500"); + types.add("Panda"); + types.add("Megane"); + + + } + + + public String getBrandToType(String type) { + if (type == null) + return ""; + return brand2Type.get(type); + } + + public List getTypes() { + return getTypesToBrand(brand); + } + + public List getTypesToBrand(String brand) { + if (brand == null || brand.length() == 0) + return types; + List l = new ArrayList(); + + Set> entrySet = brand2Type.entrySet(); + Iterator> iter = entrySet.iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + if (entry.getValue().equals(brand)) { + l.add(entry.getKey()); + } + } + if (l.size() > 0) + l.add(0, ""); + return l; + } + + public void initBrandsAndTypes() { + brand2Type.put("A180", "Mercedes"); + brand2Type.put("C200", "Mercedes"); + brand2Type.put("E320", "Mercedes"); + brand2Type.put("Civic", "Honda"); + brand2Type.put("Jazz", "Honda"); + brand2Type.put("Golf", "VW"); + brand2Type.put("Passat", "VW"); + brand2Type.put("Polo", "VW"); + brand2Type.put("320", "BMW"); + brand2Type.put("C40", "Volvo"); + brand2Type.put("V50", "Volvo"); + brand2Type.put("C60", "Volvo"); + brand2Type.put("V70", "Volvo"); + brand2Type.put("Corsa", "Opel"); + brand2Type.put("Astra", "Opel"); + brand2Type.put("Vectra", "Opel"); + brand2Type.put("Picasso", "Citroen"); + brand2Type.put("León", "Seat"); + brand2Type.put("Ibiza", "Seat"); + brand2Type.put("Exeo", "Seat"); + brand2Type.put("Punto", "Fiat"); + brand2Type.put("500", "Fiat"); + brand2Type.put("Panda", "Fiat"); + brand2Type.put("Megane", "Renault"); + } + + private String brand=null; + private String type=null; + public void setBrandAndType(String brand, String type) { + this.brand=brand; + this.type=type; + + } +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SelectionBean.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SelectionBean.java new file mode 100644 index 0000000..dbee4f9 --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SelectionBean.java @@ -0,0 +1,56 @@ +package de.beyondjava.jsf.sample.carshop; + +import java.util.List; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.RequestScoped; + +import de.beyondjava.angularFaces.components.puiSync.JSONUtilities; + +@ManagedBean +@RequestScoped +public class SelectionBean { + + @ManagedProperty("#{carPool.selectedCars}") + private List selectedCars; + + @ManagedProperty("#{carBean}") + private CarBean carBean; + + public CarBean getCarBean() { + return carBean; + } + + public void setCarBean(CarBean carBean) { + this.carBean = carBean; + } + + public List getSelectedCars() { + return selectedCars; + } + + public void setSelectedCars(List selectedCars) { + this.selectedCars = selectedCars; + } + + private String carAsJSon; + + public String getCarAsJSon() { + return carAsJSon; + } + + public void setCarAsJSon(String carAsJSon) { + this.carAsJSon = carAsJSon; + } + + public String showDetails() { + int pos = carAsJSon.indexOf(",\"$$hashKey\""); + if (pos > 0) + carAsJSon = carAsJSon.substring(0, pos) + "}"; + + Car car = (Car) JSONUtilities.readObjectFromJSONString(carAsJSon, Car.class); + return getCarBean().showDetails(car); + } + +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SettingsBean.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SettingsBean.java new file mode 100644 index 0000000..d586760 --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/SettingsBean.java @@ -0,0 +1,54 @@ +package de.beyondjava.jsf.sample.carshop; + +import java.io.Serializable; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +@ManagedBean +@SessionScoped +public class SettingsBean implements Serializable { + + private static final long serialVersionUID = 1L; + + private boolean updateImmediately = true; + + private boolean useAngularFacesAJAX = true; + + private boolean useHTML5Style = true; + + private boolean usePrimeFaces = true; + + public boolean isUpdateImmediately() { + return updateImmediately; + } + + public boolean isUseAngularFacesAJAX() { + return useAngularFacesAJAX; + } + + public boolean isUseHTML5Style() { + return useHTML5Style; + } + + public boolean isUsePrimeFaces() { + return usePrimeFaces; + } + + public void setUpdateImmediately(boolean immediateUpdate) { + this.updateImmediately = immediateUpdate; + } + + public void setUseAngularFacesAJAX(boolean useAngularFacesAJAX) { + this.useAngularFacesAJAX = useAngularFacesAJAX; + } + + public void setUseHTML5Style(boolean useHTML5Style) { + this.useHTML5Style = useHTML5Style; + } + + public void setUsePrimeFaces(boolean usePrimeFaces) { + this.usePrimeFaces = usePrimeFaces; + } + +} diff --git a/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/StaticOptionBean.java b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/StaticOptionBean.java new file mode 100644 index 0000000..c23803a --- /dev/null +++ b/TreeAndTable/src/main/java/de/beyondjava/jsf/sample/carshop/StaticOptionBean.java @@ -0,0 +1,138 @@ +/** + * (C) 2013-2014 Stephan Rauh http://www.beyondjava.net + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.beyondjava.jsf.sample.carshop; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; + +@ManagedBean +@SessionScoped +public class StaticOptionBean implements Serializable { + + private static final long serialVersionUID = 1L; + + private List brands = new ArrayList(); + + private List colors = new ArrayList(); + + private List fuels = new ArrayList(); + + private List mileages = new ArrayList(); + private List prices = new ArrayList(); + private List years = new ArrayList(); + + public StaticOptionBean() { + brands.add(""); + brands.add("Mercedes"); + brands.add("Honda"); + brands.add("VW"); + brands.add("BMW"); + brands.add("Volvo"); + brands.add("Opel"); + brands.add("Renault"); + brands.add("Citroen"); + brands.add("Seat"); + brands.add("Fiat"); + + colors.add(""); + colors.add("red"); + colors.add("white"); + colors.add("blue"); + colors.add("yellow"); + colors.add("green"); + colors.add("black"); + colors.add("white"); + colors.add("silver"); + + prices.add(""); + prices.add("< €500"); + prices.add("< €1000"); + prices.add("< €2000"); + prices.add("< €3000"); + prices.add("< €4000"); + prices.add("< €5000"); + prices.add("< €7500"); + prices.add("< €10000"); + prices.add("< €15000"); + prices.add("< €20000"); + prices.add("< €30000"); + prices.add("< €40000"); + prices.add("< €50000"); + + mileages.add(""); + mileages.add("< 100 km"); + mileages.add("< 2000 km"); + mileages.add("< 5000 km"); + mileages.add("< 10000 km"); + mileages.add("< 25000 km"); + mileages.add("< 50000 km"); + mileages.add("< 100000 km"); + mileages.add("< 200000 km"); + + fuels.add(""); + fuels.add("gasoline"); + fuels.add("diesel"); + fuels.add("hybrid"); + fuels.add("electric"); + + years.add(""); + int year = Calendar.getInstance().get(Calendar.YEAR); + for (int i = 0; i < 10; i++) { + years.add(new Integer(year - i).toString() + " or younger"); + } + for (int i = 10; i < 20; i += 3) { + years.add(new Integer(year - i).toString() + " or younger"); + } + for (int i = 20; i < 50; i += 5) { + years.add(new Integer(year - i).toString() + " or younger"); + } + } + + public List getBrands() { + return brands; + } + + public List getColors() { + return colors; + } + + public List getFuels() { + return fuels; + } + + public List getMileages() { + return mileages; + } + + public List getPrices() { + return prices; + } + + public List getYears() { + return years; + } +} diff --git a/TreeAndTable/src/main/webapp/WEB-INF/faces-config.xml b/TreeAndTable/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..e5deaf7 --- /dev/null +++ b/TreeAndTable/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,8 @@ + + + + diff --git a/TreeAndTable/src/main/webapp/WEB-INF/web.xml b/TreeAndTable/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..bf2f024 --- /dev/null +++ b/TreeAndTable/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + + + javax.faces.FACELETS_DECORATORS + + de.beyondjava.angularFaces.core.tagTransformer.AngularTagDecorator + + + + primefaces.THEME + bootstrap + + + + BootsFaces_USETHEME + true + + + index.jsf + + \ No newline at end of file diff --git a/TreeAndTable/src/main/webapp/index.xhtml b/TreeAndTable/src/main/webapp/index.xhtml new file mode 100644 index 0000000..6e6c704 --- /dev/null +++ b/TreeAndTable/src/main/webapp/index.xhtml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + Test text + + + + + + + + + + + + + + + + + + + + + #{car.brand} + #{car.type} + #{car.price} + #{car.mileage} + + + + + + + +