【问题标题】:specify one of two attributes as required in custom JSP tag在自定义 JSP 标记中根据需要指定两个属性之一
【发布时间】:2016-01-05 15:40:46
【问题描述】:

自定义JSP标签中的属性可以通过如下sn-p来设置:

<attribute>
    <name>imageId</name>
    <required>true</required>
    <rtexprvalue>true</rtexprvalue>
</attribute>

有没有办法根据需要指定两个属性之一?

【问题讨论】:

  • 一个需要一个不需要?,一个必须为true,另一个为false。
  • 两者之一是必需的。示例:我有 2 个属性 - Id、Name。我的要求是一定要提供 ID 或名称。

标签: jsp jsp-tags


【解决方案1】:

您可以将属性设为可选或强制。没有办法设置一个条件来检查其中一个是否存在。

来自文档

<required>true | false</required>

  (Optional) Defines whether this attribute has optional use in the JSP page.

  If not defined here, the default is false — that is, the attribute is optional by
  default.

  If true is specified, and the attribute is not used in a JSP page, a
  translation-time error occurs.

另见

【讨论】:

    猜你喜欢
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    相关资源
    最近更新 更多