0

我正在创建小型 javaEE 应用程序我有问题 vendorProdcut name dropdownbox is not show name only array object like this 查看图片 在此处输入图像描述

只是想问我如何从arraylist 中获取产品名称来解决我的问题?只是想知道是否可以从 productViewModel.getAllProductForVendor 带来 arraylist 产品名称

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 Bean

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

2 回答 2

2

覆盖中的toString()方法ProductEJBDTO以返回名称。

public class ProductEJBDTO implements Serializable {
    ...
    ...
    @Override
    public String toString() {
        return this.prodnam; // The product name you want to display.
    }
}
于 2013-11-07T12:24:52.527 回答
0

使用itemLabel属性(docs):

<f:selectItems value="..." var="x" itemLabel="#{x.prodnam}"></f:selectItems>

(我假设该prodnam属性是所需的显示名称;但任何 EL 表达式都可以)

于 2013-11-07T12:29:06.077 回答