开发者

Can we have an optional atrribute in a jstl tag depending upon another attribute?

Earlier we had a tag ifRole such that

<op:ifRole role="role1">
   <li id="menu3SubMenu4">This will be shown only to the user wit开发者_JAVA百科h role1</li>
</op:ifRole>

In this tag we had one required field role and another optional field secondaryRole. Now I added another optional attribute excluding such that

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

Also, I changed the attribute role from required to optional. Now, i don't want anybody to use this tag as:

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

This thing should not be allowed. One way is to throw the exception in doStartTag when both of these params are supplied. But I want other way round.


You can associate your tag with a javax.servlet.jsp.tagext.TagExtraInfo class, which can perform runtime validation of the attributes. This is perhaps a a cleaner way of doing this validation than doing it in the tag class itself.

The JavaEE tutorial covers it here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜