Expression Language In JSP Custom Tag Attributes

To use Expression Language (EL) in JSP custom tag attributes, you simply specify the <rtexprvalue> element as true for them.

hello.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
    
    <description>ByteNota Custom tag library</description>
    <tlib-version>1.0</tlib-version>
    <short-name>HelloCustomTag</short-name>
    <uri>https://bytenota.com/java</uri>
    
    <tag>
        <name>hello</name>
        <tag-class>com.bytenota.HelloTag</tag-class>
        <body-content>tagdependent</body-content>
        
        <attribute>
            <name>message</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

Then you now can pass an EL to the attribute:

example.jsp
<%@taglib prefix="bytenota" uri="https://bytenota.com/java"%>
 
<bytenota:hello message="${yourMessage}" />   

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x