Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing expressions to custom tags in JSP

Hi I just created custom tag being used in my JSP The .tld of the tag is something like this

<?xml version="1.0" encoding="UTF-8"?>
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>acma</shortname>
<info>AccountManag</info>
<tag>
    <name>clookup</name>
    <tagclass>taglib.acm</tagclass>
    <info>Customer Lookup</info>
    <attribute>
      <name>cust_id</name>
      <required>true</required>
    </attribute>
</tag>
</taglib>

Now the tag works great when i use it with an int value like so cust_id="1"

  <dd:clookup cust_id="1"></dd:clookup>

but it doesnt work when i use EL .with it like

 <dd:clookup cust_id="${sessionScope.cust.id}"></dd:clookup>

All the tutorials start of with int or other data type so i cant locate any resource that might help here.. any suggestions ?

like image 475
MistyD Avatar asked Jun 06 '12 14:06

MistyD


People also ask

How do I pass parameters to a custom tag?

Passing values to and from custom tags To pass data from the calling page to the custom tag, you can specify attribute name-value pairs in the custom tag, just as you do for normal HTML and CFML tags. In the custom tag, you use the Attributes scope to access attributes passed to the tag.

What is a JSP custom tag what is JSP Expression language?

Custom tags are user-defined tags. They eliminates the possibility of scriptlet tag and separates the business logic from the JSP page. The same business logic can be used many times by the use of custom tag.

Can we create custom tags in JSP?

You can include one or more custom JSP tags in a tag library. You define a tag library by a tag library descriptor ( . tld ) file. The TLD describes the syntax for each tag and ties it to the Java classes that execute its functionality.

How are custom tags in JSP created?

The JSP 2.0 specification introduced the Simple Tag Handlers for writing these custom tags. To write a custom tag, you can simply extend SimpleTagSupport class and override the doTag() method, where you can place your code to generate content for the tag.


1 Answers

Specify rtexprvalue in your tld:

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

See Tag Library Descriptors for more details.

like image 54
Beau Grantham Avatar answered Nov 09 '22 15:11

Beau Grantham