从Array list object获取产品名称

时间:2013-11-07 12:23:46

标签: java java-ee arraylist

我正在创建小型javaEE应用程序我遇到问题,vendorProdcut名称下拉框没有显示名称这样的数组对象,请参阅图像enter image description here

我想问一下如何从arraylist获取产品名称来解决我的问题? 只是想知道有没有带来arraylist产品名称 productViewModel.getAllProductForVendor

HTML

<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>

Java Beans

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;
}

DTO

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;
    }
}

2 个答案:

答案 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表达式都可以。)