我正在创建小型javaEE应用程序我遇到问题,vendorProdcut名称下拉框没有显示名称这样的数组对象,请参阅图像
我想问一下如何从arraylist获取产品名称来解决我的问题? 只是想知道有没有带来arraylist产品名称 productViewModel.getAllProductForVendor
<div class="ui-block-a">
<h:selectOneMenu id="productname" value="#{productViewModel.prodname}" onchange="javascript: return this.form.submit();">
<f:selectItems value="#{productViewModel.getAllProductForVendor(vendorViewModel.vendorno)}"></f:selectItems>
</h:selectOneMenu>
</div>
public ArrayList<ProductEJBDTO> getAllProductForVendor(int vendorno) {
ArrayList<ProductEJBDTO> Products = new ArrayList() ;
//model.getProducts(vendorno);
try
{
Products = productFacadeBean.getAllProductsForVendor(vendorno);
}
catch(Exception e)
{
System.out.println("can't get products for vendors " + e);
}
return Products;
}
package case2dtos;
import java.io.Serializable;
import java.math.BigDecimal;
/**
*
* @author abdallaelnajjar
*/
public class ProductEJBDTO implements Serializable {
public ProductEJBDTO(){}
private int vendorno;
private String prodcd;
private String vensku;
private String prodnam;
private BigDecimal costprice;
private BigDecimal msrp;
private int rop;
private int eoq;
private int qoh;
private int qoo;
private byte[] qrcode;
/**
* @return the prodcd
*/
public String getProdcd() {
return prodcd;
}
/**
* @param prodcd the prodcd to set
*/
public void setProdcd(String prodcd) {
this.prodcd = prodcd;
}
/**
* @return the vensku
*/
public String getVensku() {
return vensku;
}
/**
* @param vensku the vensku to set
*/
public void setVensku(String vensku) {
this.vensku = vensku;
}
/**
* @return the prodnam
*/
public String getProdnam() {
return prodnam;
}
/**
* @param prodnam the prodnam to set
*/
public void setProdnam(String prodnam) {
this.prodnam = prodnam;
}
/**
* @return the costprice
*/
public BigDecimal getCostprice() {
return costprice;
}
/**
* @param costprice the costprice to set
*/
public void setCostprice(BigDecimal costprice) {
this.costprice = costprice;
}
/**
* @return the msrp
*/
public BigDecimal getMsrp() {
return msrp;
}
/**
* @param msrp the msrp to set
*/
public void setMsrp(BigDecimal msrp) {
this.msrp = msrp;
}
/**
* @return the rop
*/
public int getRop() {
return rop;
}
/**
* @param rop the rop to set
*/
public void setRop(int rop) {
this.rop = rop;
}
/**
* @return the eoq
*/
public int getEoq() {
return eoq;
}
/**
* @param eoq the eoq to set
*/
public void setEoq(int eoq) {
this.eoq = eoq;
}
/**
* @return the qoh
*/
public int getQoh() {
return qoh;
}
/**
* @param qoh the qoh to set
*/
public void setQoh(int qoh) {
this.qoh = qoh;
}
/**
* @return the qoo
*/
public int getQoo() {
return qoo;
}
/**
* @param qoo the qoo to set
*/
public void setQoo(int qoo) {
this.qoo = qoo;
}
/**
* @return the qrcode
*/
public byte[] getQrcode() {
return qrcode;
}
/**
* @param qrcode the qrcode to set
*/
public void setQrcode(byte[] qrcode) {
this.qrcode = qrcode;
}
/**
* @return the vendorno
*/
public int getVendorno() {
return vendorno;
}
/**
* @param vendorno the vendorno to set
*/
public void setVendorno(int vendorno) {
this.vendorno = vendorno;
}
}
答案 0 :(得分:2)
覆盖toString()
中的ProductEJBDTO
方法以返回名称。
public class ProductEJBDTO implements Serializable {
...
...
@Override
public String toString() {
return this.prodnam; // The product name you want to display.
}
}
答案 1 :(得分:0)
使用itemLabel
属性(docs):
<f:selectItems value="..." var="x" itemLabel="#{x.prodnam}"></f:selectItems>
(我假设prodnam
属性是所需的显示名称;但任何EL表达式都可以。)