如何在JSF2中显示Linkedlist?
我有一个带有3个产品的Linkedlist,我想根据我单击的按钮在输入文本中显示其中一个产品的值。我用的是素面。 我不知道如何创建我的虚拟空间 类别产品:如何在JSF2中显示Linkedlist?,jsf,jakarta-ee,primefaces,linked-list,Jsf,Jakarta Ee,Primefaces,Linked List,我有一个带有3个产品的Linkedlist,我想根据我单击的按钮在输入文本中显示其中一个产品的值。我用的是素面。 我不知道如何创建我的虚拟空间 类别产品: public class Product { private String idp; private String brand; private String price; public Product() { } public Product(String idp, String brand, String price) {
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;
}
}
班级商店:
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;
}
}
使用
ui:repeat
标记对其进行迭代
<ui:repeat var="temp" value="#{mybean.listprod}">
<tr>
<td>#{temp.idp}</td>
<td>#{temp.brand}</td>
<td>#{temp.price}</td>
</tr>
</ui:repeat>
#{temp.idp}
#{临时品牌}
#{临时价格}
类似的问题如果您正在使用primefaces并希望显示列表,为什么不使用
产品
#{product.idp}、{product.brand}、{product.price}
或(可编辑)数据表
产品
只需使用ui:repeat
标记迭代listprod
元素。我在索引中包含了一个ui repeat标记,是否正确?那怎么做呢?我甚至不确定我声明Linkedlist的方式是否正确。我已经在索引视图中更新了我的代码,现在ui中的所有内容:repeat没有显示在屏幕上(没有标签、没有输入文本、没有按钮),请查看DOM树(通常是浏览器的f12)。找出正在渲染的内容。
@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;
}
}
<ui:repeat var="temp" value="#{mybean.listprod}">
<tr>
<td>#{temp.idp}</td>
<td>#{temp.brand}</td>
<td>#{temp.price}</td>
</tr>
</ui:repeat>
<p:dataList value="#{mybean.listprod}" var="product" type="ordered">
<f:facet name="header">
Products
</f:facet>
#{product.idp}, #{product.brand}, #{product.price}
</p:dataList>
<p:dataTable var="product" value="#{mybean.listprod}" editable="true">
<f:facet name="header">
Products
</f:facet>
<p:column headerText="idp">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{product.idp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{product.idp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="brand">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{product.brand}" /></f:facet>
<f:facet name="input"><p:inputText value="#{product.brand}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="price">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{product.price}" /></f:facet>
<f:facet name="input"><p:inputText value="#{product.price}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>