2012-06-06 46 views
4

我不是JSTL和表達式語言方面的專家,所以我的問題可能是愚蠢的......表達式語言和接口

我與Spring MVC和我的控制器工作,我有:

@ModelAttribute("export_types") 
public ExportType[] getExportTypes() { 
    return edService.getTypes(); 
} 

ExportType是一個自定義接口:

public interface ExportType { 

    String getName(); 

    //... 
} 

在我的網頁我有:

<c:forEach var="item" items="${export_types}"> 
    <tr> 
     <td><input type="checkbox" value="${item.name}"></td> 
     <td>${item.name}</td> 
    </tr> 
</c:forEach> 

但是當我跑我的web應用程序我得到這個厚望:javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String

奇怪的是,除了說on type java.lang.String而不是在ExportType類型。所以我的問題是:不能使用接口的表達式語言嗎?


注1

edService.getTypes()返回一個ExportType[]陣列與所述接口的具體實現。

爲了清楚起見,我有一個抽象類,實現了ExportType接口。具體類型從這個繼承:

public abstract class AbstractExportType implements ExportType { 
    protected String name; 

    protected AbstractExportType() { 
     this.name = this.getClass().getSimpleName(); 
    } 

    @Override 
    String getName(){ 
     return this.name; 
    } 

    //... 
} 

注2:

轉發到export.jsp控制器的方法很簡單:

​​
+0

'edService.getTypes();'這是什麼確切返回? –

+0

@JigarJoshi看注意 – davioooh

+2

確保你不會覆蓋'export_types'屬性的某處。 – axtavt

回答

0

我不認爲這與接口有關。最有可能的是@doublep說,export_types其實不是ExportType[]。我試圖重現你在做什麼,它工作正常。

+0

好的,也許返回的數組類型有問題。感謝您的幫助! – davioooh