我有一個Struts 2 JSP用下面的代碼...支柱2,如果:比較枚舉
<s:iterator value="categories" id="category" status="iteratorStatus">
<s:if test='#category == "M" '> snip </s:if>
問題是類別背後的Java代碼..
private static final CategoryEnum[] PRIVATE_VALUES = {A,B,C,M };
public static final List<CategoryEnum> VALUES = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
public List<CategoryEnum> getCategories() {
return CategoryEnum.VALUES;
}
所以IF聲明不起作用,它從來沒有真正的評價。 我試過逃離字母等,但沒有成功。
我更願意用'category'值回調Action類,並決定要做什麼。例如
<s:if test='renderCategory(#category)> snip </s:if>
但我不知道如何將#category傳回給操作。
因此,任何人都可以幫助我解決如何傳回值或使Struts IF標記與枚舉一起工作。
我已經讀完了這一點:這是沒有太大的幫助,在這裏,但無論如何,我會引用IY:
Struts 2: Why won't the 'if' tag evaluate a one char string
誰能幫助我嗎?
傑夫·波特
就是我正在尋找的!非常感謝... – Nischal