<style type="text/css"> .value { font-weight: bold; } .ui-carousel { margin-bottom: 20px; } </style> <h:form id="form"> <p:carousel value="#{carouselView.cars}" headerText="Responsive" var="car" itemStyle="text-align:center" responsive="true"> <p:panelGrid columns="2" style="width:100%;margin:10px 0px" columnClasses="label,value" layout="grid" styleClass="ui-panelgrid-blank"> <f:facet name="header"> <p:graphicImage name="demo/images/car/#{car.brand}.gif"/> </f:facet> <h:outputText value="Id:" /> <h:outputText value="#{car.id}" /> <h:outputText value="Year" /> <h:outputText value="#{car.year}" /> <h:outputText value="Color:" /> <h:outputText value="#{car.color}" style="color:#{car.color}"/> <h:outputText value="Price" /> <h:outputText value="$#{car.price}" /> </p:panelGrid> <f:facet name="footer"> In total there are #{fn:length(carouselView.cars)} cars. </f:facet> </p:carousel> <p:carousel value="#{carouselView.cars}" headerText="Custom" var="car" itemStyle="height:200px;text-align:center" numVisible="1" easing="easeOutBounce" style="width:250px" circular="true"> <h:panelGrid columns="2" style="width:100%" columnClasses="label,value"> <f:facet name="header"> <p:graphicImage name="demo/images/car/#{car.brand}.gif"/> </f:facet> <h:outputText value="Id:" /> <h:outputText value="#{car.id}" /> <h:outputText value="Year" /> <h:outputText value="#{car.year}" /> <h:outputText value="Color:" /> <h:outputText value="#{car.color}" style="color:#{car.color}"/> <h:outputText value="Price" /> <h:outputText value="$#{car.price}" /> <f:facet name="footer"> <p:commandButton update=":form:carDetail" oncomplete="PF('carDialog').show()" icon="pi pi-search"> <f:setPropertyActionListener value="#{car}" target="#{carouselView.selectedCar}" /> </p:commandButton> </f:facet> </h:panelGrid> </p:carousel> <p:carousel numVisible="1" effect="easeInStrong" headerText="Tabs" style="margin-bottom:0"> <p:tab title="Godfather Part I"> <h:panelGrid columns="2" cellpadding="10"> <p:graphicImage name="demo/images/godfather/godfather1.jpg" /> <h:outputText value="The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family." /> </h:panelGrid> </p:tab> <p:tab title="Godfather Part II"> <h:panelGrid columns="2" cellpadding="10"> <p:graphicImage name="demo/images/godfather/godfather2.jpg" /> <h:outputText value="Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, The_Godfather, parallels the young Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfather's depiction of the dark side of the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy, killing the local Black Hand Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows." /> </h:panelGrid> </p:tab> <p:tab title="Godfather Part III"> <h:panelGrid columns="2" cellpadding="10"> <p:graphicImage name="demo/images/godfather/godfather3.jpg" /> <h:outputText value="After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate." /> </h:panelGrid> </p:tab> </p:carousel> <p:dialog header="Car Info" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false"> <p:outputPanel id="carDetail" style="text-align:center;"> <p:panelGrid columns="2" rendered="#{not empty carouselView.selectedCar}" columnClasses="label,value"> <f:facet name="header"> <p:graphicImage name="demo/images/car/#{carouselView.selectedCar.brand}-big.gif"/> </f:facet> <h:outputText value="Id:" /> <h:outputText value="#{carouselView.selectedCar.id}" /> <h:outputText value="Year" /> <h:outputText value="#{carouselView.selectedCar.year}" /> <h:outputText value="Color:" /> <h:outputText value="#{carouselView.selectedCar.color}" style="color:#{carouselView.selectedCar.color}"/> <h:outputText value="Price" /> <h:outputText value="$#{carouselView.selectedCar.price}" /> </p:panelGrid> </p:outputPanel> </p:dialog> </h:form>
@Named @ViewScoped public class CarouselView implements Serializable { private List<Car> cars; private Car selectedCar; @Inject private CarService service; @PostConstruct public void init() { cars = service.createCars(9); } public List<Car> getCars() { return cars; } public void setService(CarService service) { this.service = service; } public Car getSelectedCar() { return selectedCar; } public void setSelectedCar(Car selectedCar) { this.selectedCar = selectedCar; } }
public class Car implements Serializable { public String id; public String brand; public int year; public String color; public int price; public boolean sold; public Car() {} public Car(String id, String brand, int year, String color) { this.id = id; this.brand = brand; this.year = year; this.color = color; } public Car(String id, String brand, int year, String color, int price, boolean sold) { this.id = id; this.brand = brand; this.year = year; this.color = color; this.price = price; this.sold = sold; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public boolean isSold() { return sold; } public void setSold(boolean sold) { this.sold = sold; } @Override public int hashCode() { int hash = 7; hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Car other = (Car) obj; if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) { return false; } return true; } }
@Named @ApplicationScoped public class CarService { private final static String[] colors; private final static String[] brands; static { colors = new String[10]; colors[0] = "Black"; colors[1] = "White"; colors[2] = "Green"; colors[3] = "Red"; colors[4] = "Blue"; colors[5] = "Orange"; colors[6] = "Silver"; colors[7] = "Yellow"; colors[8] = "Brown"; colors[9] = "Maroon"; brands = new String[10]; brands[0] = "BMW"; brands[1] = "Mercedes"; brands[2] = "Volvo"; brands[3] = "Audi"; brands[4] = "Renault"; brands[5] = "Fiat"; brands[6] = "Volkswagen"; brands[7] = "Honda"; brands[8] = "Jaguar"; brands[9] = "Ford"; } public List<Car> createCars(int size) { List<Car> list = new ArrayList<Car>(); for(int i = 0 ; i < size ; i++) { list.add(new Car(getRandomId(), getRandomBrand(), getRandomYear(), getRandomColor(), getRandomPrice(), getRandomSoldState())); } return list; } private String getRandomId() { return UUID.randomUUID().toString().substring(0, 8); } private int getRandomYear() { return (int) (Math.random() * 50 + 1960); } private String getRandomColor() { return colors[(int) (Math.random() * 10)]; } private String getRandomBrand() { return brands[(int) (Math.random() * 10)]; } private int getRandomPrice() { return (int) (Math.random() * 100000); } private boolean getRandomSoldState() { return (Math.random() > 0.5) ? true: false; } public List<String> getColors() { return Arrays.asList(colors); } public List<String> getBrands() { return Arrays.asList(brands); } }