2013-11-07 6 views
0

Я создаю небольшой JavaEE приложение У меня есть проблема с именем vendorsProdcut выпадающего DropDownBox'м не отображается именем только объект массива, как это увидеть изображения enter image description hereПолучить имя продукта из объекта списка Массива

Просто хотят спросить, как я могу получить название продукта от 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; 
    } 
} 

ответ

0

Используйте itemLabel атрибут (docs):

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

(Я предполагаю, что prodnam свойство желаемое отображаемое имя, любое выражение EL будет делать, хотя)

+0

Что именно не работает? –

+0

получить его, чтобы работать, это проблема с развертыванием стеклянной рыбы –

2

Override toString() метод в поле ProductEJBDTO, чтобы вернуть имя.

public class ProductEJBDTO implements Serializable { 
    ... 
    ... 
    @Override 
    public String toString() { 
     return this.prodnam; // The product name you want to display. 
    } 
} 
Смежные вопросы