I have a Linkedlist with 3 products, I would like to display in the input text the values of one of the products according to the button that I clicked. I am using Primefaces. I don't know how to create my the void to do so.
class Product :
public class Product {
private String idp;
private String brand;
private String price;
public Product() {
}
public Product(String idp, String brand, String price) {
this.idp = idp;
this.brand = brand;
this.price = price;
}
public String getIdp() {
return idp;
}
public void setIdp(String idp) {
this.idp = idp;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
class Shop :
public class Shop {
private LinkedList<Product> listprod;
public Shop() {
listprod = new LinkedList<>();
Product product1 = new Product("01","brand1","15");
Product product2 = new Product("02","brand2","30");
Product product3 = new Product("03","brand3","60");
listprod.add(product1);
listprod.add(product2);
listprod.add(product3);
}
public LinkedList<Product> getListprod() {
return listprod;
}
public void setListprod(LinkedList<Product> listprod) {
this.listprod = listprod;
}
}
view index :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta charset="utf-8" />
<title>Products</title>
</h:head>
<h:body id="mybody">
<h:form id="myform">
<ui:repeat var="temp" value="#{mybean.shop.listprod}" >
<h:panelGrid columns="2" cellpadding="5" id="mygrid">
<h:outputLabel for="idp" value="Id :"/>
<p:inputText id="idp" value="#{temp.idp}"/>
<h:outputLabel for="brand" value="Brand :"/>
<p:inputText id="brand" value="#{temp.brand}"/>
<h:outputLabel for="price" value="Price :"/>
<p:inputText id="price" value="#{temp.price}"/>
<p:commandButton value="Product 1" actionListener="#{mybean.showdata()}" />
<p:commandButton value="Product 2" actionListener="#{mybean.showdata()}" />
<p:commandButton value="Product 3" actionListener="#{mybean.showdata()}" />
</h:panelGrid>
</ui:repeat>
</h:form>
</h:body>
</html>
My the bean :
@SessionScoped
@ManagedBean(name="mybean")
public class Mybean {
private Product product;
private Shop shop;
public void showdata(){
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Shop getShop() {
return shop;
}
public void setShop(Shop shop) {
this.shop = shop;
}
}