itemLabel =“#{client2.nomClient}”:在类型java.lang.String上找不到属性'nomClient'

时间:2014-09-13 13:51:59

标签: jsf primefaces

我将检索selectOneMenu的选择值,但是当我执行程序时,此异常会出现:

Etat HTTP 500 - /pages/T.xhtml @59,33 itemLabel="#{client2.nomClient}": Property 'nomClient' not found on type java.lang.String

这是我的观点:

<p:selectOneMenu value="#{ticketBean.maValeur}" 
                            style="width:210px; height:20px; font-size:10px; font-weight:1px;"
                            required="true" requiredMessage="REQUIRED">
                            <f:selectItem  itemLabel="Select Client"  itemValue=""/>
                            <f:selectItems  value="#{ticketBean.getMesElementsTest()}" var="client2" itemLabel="#{client2.nomClient}" itemValue="#{client2.nomClient}"
                                style="font-size:10px;">
                            </f:selectItems>

这是我的班级客户:

package com.model;

public class Client {
    private int idClient;
    private String nomClient;
    private String adresseClient;
    private String telephoneClient;
    private String mailClient;

// GETTERS && SETTERS 
}

这是我的函数getMesElementsTest:

 private static Map<String, Object> mesElementsTest;
    private static ClientDaoImp clientDaoImp= new ClientDaoImp();   
    public static Map<String, Object> getMesElementsTest() {
        mesElementsClient = new LinkedHashMap<String, Object>();
        List<Client> clientlist = clientDaoImp.getAllClients();
        Iterator<Client> i = clientlist.iterator();
        while(i.hasNext()){
            Client client=i.next();
            mesElementsClient.put(client.getNomClient(),client.getNomClient());

        }    
        return mesElementsClient;
    }

1 个答案:

答案 0 :(得分:0)

您只能使用List,并且具有以下内容:

...
public static List<Client> getMesElementsTest() {
        return clientDaoImp.getAllClients();    
        } 
...
页面上的

...    
<p:selectOneMenu value="#{ticketBean.maValeur}" style="..." required="true" requiredMessage="...">
       <f:selectItem  itemLabel="Select Client"  itemValue=""/>
       <f:selectItems  value="#{ticketBean.getMesElementsTest()}" var="client2" itemLabel="#{client2.nomClient}" itemValue="#{client2.nomClient}" style="...">
    </f:selectItems>
...

而且,这种形式更有效率,因为您不需要填充其他数据结构。

希望有所帮助