Use JSPTag file in Java Tag Handler - Stack Overflow

admin2025-04-18  3

I am trying to create a reusable module to display a table based off a list of objects passed to the JSP

Several of these lists are passed at a time, and each need to display their own table

The most sensible way I've found to do this would be through a custom tag, but it would be a few hundred lines of HTML that it needs to build, and I can't find a good way to do that

tag-file doesn't seem to accept attributes to pass the list to the tag, and tag programmatically through Java doesn't seem to have a way to give it a file to use as a template

Whoever worked on this code before me took the long way by building the entire HTML section line by line with a StringBuilder in the Java-side doTag() method, and I'd rather avoid doing that if at all possible

Is there anything that I'm missing here as to how custom tags work?

The tag declaration is as follows:

<tag>
    <name>dropdown</name>
    <tag-class>{tag class location}</tag-class>
    <body-content>empty</body-content>
    <info>Displays dropdown information</info>
    <attribute>
        <name>drpList</name>
        <required>true</required>
        <description>list for dropdown</description>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
    <name>drpTitle</name>
        <required>true</required>
        <description>column titles</description>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
    <name>factLink</name>
        <required>false</required>
        <description>list of values</description>
        <rtexprvalue>true</rtexprvalue>
    </attribute>            
</tag>

I am trying to create a reusable module to display a table based off a list of objects passed to the JSP

Several of these lists are passed at a time, and each need to display their own table

The most sensible way I've found to do this would be through a custom tag, but it would be a few hundred lines of HTML that it needs to build, and I can't find a good way to do that

tag-file doesn't seem to accept attributes to pass the list to the tag, and tag programmatically through Java doesn't seem to have a way to give it a file to use as a template

Whoever worked on this code before me took the long way by building the entire HTML section line by line with a StringBuilder in the Java-side doTag() method, and I'd rather avoid doing that if at all possible

Is there anything that I'm missing here as to how custom tags work?

The tag declaration is as follows:

<tag>
    <name>dropdown</name>
    <tag-class>{tag class location}</tag-class>
    <body-content>empty</body-content>
    <info>Displays dropdown information</info>
    <attribute>
        <name>drpList</name>
        <required>true</required>
        <description>list for dropdown</description>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
    <name>drpTitle</name>
        <required>true</required>
        <description>column titles</description>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
    <name>factLink</name>
        <required>false</required>
        <description>list of values</description>
        <rtexprvalue>true</rtexprvalue>
    </attribute>            
</tag>
Share Improve this question edited Jan 29 at 17:46 BalusC 1.1m376 gold badges3.7k silver badges3.6k bronze badges asked Jan 29 at 15:26 Nathan SNathan S 237 bronze badges 2
  • The final rendered page contains proprietary information that I can't share. All I wanted to know is if there was a way to make the Java-side tag handling use a JSP or Tag file as a template, then pass it to the JspWriter to output to the page – Nathan S Commented Jan 29 at 15:54
  • I'm not trying to use a forEach. The JSP is getting multiple lists, and I'm trying to set up a template that will take each one of those lists and make a table from it. I could do this through a custom tag, I just want a way to use a template file in a tag handler instead of what the previous developer did and building a few hundred lines of HTML with a StringBuilder. – Nathan S Commented Jan 29 at 16:08
Add a comment  | 

1 Answer 1

Reset to default 1

Solved my own problem, and yes I was just missing something

I was looking at the configuration declarations of tag and tag-file, and didn't see that attributes in tag-file are declared in the header of the file itself

转载请注明原文地址:http://anycun.com/QandA/1744956213a90001.html