之前我们有一个标签 ifRole
这样
<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
中抛出异常。但我想反过来。
最佳答案
您可以将您的标记与 javax.servlet.jsp.tagext.TagExtraInfo
类相关联,该类可以执行属性的运行时验证。与在标记类本身中进行验证相比,这可能是一种更简洁的验证方法。
JavaEE 教程涵盖了它 here
关于java - 我们可以在 jSTL 标签中有一个可选属性取决于另一个属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4231987/