2014-02-18 28 views
0

比較使用該代碼JSTL字符串的ArrayList元件

<c:forEach var="row" varStatus="loop" items="${court.monday}"> 
<tr> 
<c:choose> 
<c:when test='${row eq "Free Court"}'> 
<td class="inner">${loop.index} is Bookable </td> 
</c:when> 
<c:otherwise> 
<td class="inner">${row}</td> 
</c:otherwise> 
</c:choose> 
</tr> 
</c:forEach> 

實質上,我有一個時間表對象,其中包含字符串的7周的ArrayList。我可以在列表中循環訪問

<td class="inner">${row}</td> 

但我想檢查一下行值是否等於'Free Court'。如果有,則會顯示鏈接。如果沒有,則顯示該事件。我收到以下錯誤。

「$ {} court.monday」財產「星期一」不是java.lang.String類型發現

我認爲這是值得做一個ArrayList比較一個字符串,但我試過的東西像行[loop.index](其被正確顯示,如果我只是將其輸出。

這是控制器

@RequestMapping(value = "/gotoCourt", method=RequestMethod.POST) 
    public String chooseCourt(Model model, HttpServletRequest request){ 
     model.addAttribute("court", timetableService.getById(request.getParameter("courtID"))); 
     return "court"; 
    } 

時間表類是

public class MonaleenTTV1 implements Timetable { 

    @Id 
    @GeneratedValue 
    private int id; 

    @Size(min=5, max=10, message="Court must be between 5 and 10 characters",groups={PersistenceValidationGroup.class, FormValidationGroup.class}) 
    private String name; 

    @NotNull 
    //@Min(value = 1, message="Value must be 1 or greater") 
    private int slots; 

    private int startTime; 

    private int endTime; 

    private boolean enabled; 

    @ElementCollection 
    @CollectionTable (name = "monday", [email protected](name="id")) 
    List<String> monday; 

    @ElementCollection 
    @CollectionTable (name = "tuesday", [email protected](name="id")) 
    List<String> tuesday; 

    @ElementCollection 
    @CollectionTable (name = "wednesday", [email protected](name="id")) 
    List<String> wednesday; 

    @ElementCollection 
    @CollectionTable (name = "thursday", [email protected](name="id")) 
    List<String> thursday; 

    @ElementCollection 
    @CollectionTable (name = "friday", [email protected](name="id")) 
    List<String> friday; 

    @ElementCollection 
    @CollectionTable (name = "saturday", [email protected](name="id")) 
    List<String> saturday; 

    @ElementCollection 
    @CollectionTable (name = "sunday", [email protected](name="id")) 
    List<String> sunday; 
+0

您向我們展示不會導致問題的代碼。法庭是一個字符串,並且String中沒有getMonday()方法。這就是信息告訴你的。鑑於我們不知道你在哪裏以及如何得到法庭,我們無法提供幫助。 –

+0

法庭是一個時間表對象,其中包含7個字符串ArrayLists(court.monday是星期一列表等)我已更新帖子以顯示控制器和時間表部分類 –

+0

本質上,我可以遍歷每個列表,並顯示每個列表沒有問題的列表,但我想比較每個列表中的每個條目到一定的值,並將我的操作更改爲在某些情況下顯示列表項或不同的鏈接。 –

回答

0

呃!我的代碼沒有問題。重新啓動Tomcat使其工作! :)