What are <required> and <rtexprvalue> used for?

六眼飞鱼酱① 提交于 2019-12-03 04:06:21

问题


I was working on custom tag libraries and I was confused how the <required> and <rtexprvalue> tags are used in the TLD file to define a custom tag attribute.

  1. What are these tags?
  2. What should we write in-between them?
  3. What behavior do we get after writing these tags?

回答1:


required quite simply implies what it says. The attribute is required or mandatory.

rtexprvalue means Runtime Expression Value. It means the attribute can support scriptlet values.

elexprvalue means it can support EL (expression language) values.

So, if you have requiredattr defined as both required=true and rtexprvalue=true and elattribute is defined as elexprvalue=true, you can write as follows:

<myprefix:mytag requiredattr="<%=baz.getId()%>" elattribute="${foo.bar}"/>



回答2:


The <rtexprvalue> element defined in a TLD captures the dynamic behavior of an attribute. The value can be either true or false. A false value in the dynamic column means that only a static string value can be specified for the attribute. A true value means that a request-time attribute value can be specified. As defined in the JSP specification, a “request-time attribute value” can be either a Java expression, an EL expression, or a value set by a <jsp:attribute>.

The <required> element defines if the nesting attribute is required or optional. If not present then the default is "false", i.e the attribute is optional.



来源:https://stackoverflow.com/questions/8787582/what-are-required-and-rtexprvalue-used-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!