49

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?
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
bali208
  • 2,257
  • 7
  • 40
  • 43

2 Answers2

76

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}"/>
adarshr
  • 61,315
  • 23
  • 138
  • 167
  • Thank you, i will re-refer to the code once again and try it out! can you tell me what will happen if i make rtexprvalue false?? What should i type in tag-lib file in between tag ?? – bali208 Jan 09 '12 at 11:31
  • Generally `rtexprvalue` and `elexprvalue` are only made false when you don't want users of your taglib providing a runtime value. I have seen the `id` attributes being declared as `false` in some tag libraries. – adarshr Jan 09 '12 at 12:35
  • Just to mention. With `rtexprvalue=true`, some implementations allow the concatenation, e.g. `requiredattr="<%=xxxx%>yyy"` , some others do not. – luca.vercelli Jul 21 '22 at 15:31
11

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.

Noumenon
  • 5,099
  • 4
  • 53
  • 73
Veaceslav Serghienco
  • 1,880
  • 2
  • 12
  • 6