<a:form> <a:commandButton value="View" icon="ui-icon-extlink" actionListener="#{dfView.viewCars}" /> <a:commandButton value="Options" icon="ui-icon-extlink" actionListener="#{dfView.viewCarsCustomized}" /> </a:form>
package com.jarch.showcase.view.df; import java.util.HashMap; import java.util.Map; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.context.FacesContext; import org.primefaces.context.PrimeRequestContext; import org.primefaces.event.SelectEvent; import org.primefaces.showcase.domain.Car; @ManagedBean(name = "dfView") public class DFView { public void viewCars() { Map<String,Object> options = new HashMap<String, Object>(); options.put("resizable", false); RequestContext.getCurrentInstance().openDialog("viewCars", options, null); } public void viewCarsCustomized() { Map<String,Object> options = new HashMap<String, Object>(); options.put("modal", true); options.put("width", 640); options.put("height", 340); options.put("contentWidth", "100%"); options.put("contentHeight", "100%"); options.put("headerElement", "customheader"); RequestContext.getCurrentInstance().openDialog("viewCars", options, null); } public void chooseCar() { RequestContext.getCurrentInstance().openDialog("selectCar"); } public void onCarChosen(SelectEvent event) { Car car = (Car) event.getObject(); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Car Selected", "Id:" + car.getId()); FacesContext.getCurrentInstance().addMessage(null, message); } public void showMessage() { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "What we do in life", "Echoes in eternity."); RequestContext.getCurrentInstance().showMessageInDialog(message); } }
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <h:head> <title>Cars</title> <style type="text/css"> .ui-widget { font-size: 90%; } </style> </h:head> <h:body> <i id="customheader" class="fa fa-fw fa-car" style="display:none"></i> <a:dataTable var="car" value="#{dfCarsView.cars}"> <a:column headerText="Id"> <h:outputText value="#{car.id}" /> </a:column> <a:column headerText="Year"> <h:outputText value="#{car.year}" /> </a:column> <a:column headerText="Brand"> <h:outputText value="#{car.brand}" /> </a:column> <a:column headerText="Color"> <h:outputText value="#{car.color}" /> </a:column> </a:dataTable> </h:body> </html>
package com.jarch.showcase.view.df; 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.context.PrimeRequestContext; import org.primefaces.showcase.domain.Car; import org.primefaces.showcase.service.CarService; @ManagedBean(name = "dfCarsView") @ViewScoped public class DFCarsView implements Serializable { private List<Car> cars; @ManagedProperty("#{carService}") 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; } }