DataScroller - Basic
DataScroller displays data with on demand loading using scroll.
Documentation
<style type="text/css">
.logo {
width: 5%
}
.detail {
width: 95%;
padding-left: 25px;
}
.detail td {
font-size: 24px;
}
.ui-datascroller .ui-datascroller-item {
border-bottom: 1px solid #A8A8A8;
padding: 25px 10px;
/* with the exported variables from Nova and Luna Themes*/
border-bottom-color: var(--input-border-color, #A8A8A8);
}
</style>
<h:form>
<p:dataScroller value="#{dataScrollerView.cars}" var="car" chunkSize="10">
<f:facet name="header">
Scroll Down to Load More Cars
</f:facet>
<h:panelGrid columns="2" style="width:100%" columnClasses="logo,detail">
<p:graphicImage name="demo/images/car/#{car.brand}-big.gif" />
<p:outputPanel>
<h:panelGrid columns="2" cellpadding="5">
<h:outputText value="Id:" />
<h:outputText value="#{car.id}" style="font-weight: bold"/>
<h:outputText value="Year:" />
<h:outputText value="#{car.year}" style="font-weight: bold"/>
<h:outputText value="Color:" />
<h:outputText value="#{car.color}" style="font-weight: bold"/>
</h:panelGrid>
</p:outputPanel>
</h:panelGrid>
</p:dataScroller>
</h:form>
@Named
@ViewScoped
public class DataScrollerView implements Serializable {
private List<Car> cars;
@Inject
private CarService service;
@PostConstruct
public void init() {
cars = service.createCars(100);
}
public List<Car> getCars() {
return cars;
}
public void setService(CarService service) {
this.service = service;
}
}
@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);
}
}