2010-11-20 50 views
1

早些時候,我們有一個標籤ifRole這樣根據另一個屬性,我們可以在jstl標籤中有一個可選的atrribute嗎?

<op:ifRole role="role1"> 
    <li id="menu3SubMenu4">This will be shown only to the user with role1</li> 
</op:ifRole> 

在這個標籤,我們有一個必填字段role和另一個可選字段secondaryRole。現在,我又增加了可選屬性excluding這樣

<op:ifRole excluding="role2"> 
    <li id="menu3SubMenu4">This will be shown to all users except the one with role=role2</li> 
</op:ifRole> 

另外,我從需要可選更改屬性role。現在,我不想讓任何人使用這個標籤:

<op:ifRole excluding="role2" role="role1"> 

這個東西不應該被允許。一種方法是在提供這兩個參數時在doStartTag中拋出異常。但我想要其他方式。

+1

你是什麼意思「相反方向」? – skaffman 2010-11-20 09:23:03

+0

@skaffman:我的意思是用xml來做 – 2010-11-20 12:31:10

回答

3

您可以將您的標記與javax.servlet.jsp.tagext.TagExtraInfo類相關聯,該類可以執行屬性的運行時驗證。這可能是一種比在標籤類本身進行驗證更簡潔的方式。

JavaEE教程涵蓋了它here

相關問題