Reputation: 167
I have a custom JSP tag tag file, which is a wrapper around HTML input controls - dropdown etc, like so -
<mytag:dropdown table="customer_master" style="display:block;" class="dblist"/>
Here "table" is a declared attribute of the tag where as style, class are dynamic-attributes.
Now I would like to wrap this is in another tag like so -
<mytag:search-filter type="dropdown" validate="true" table="mytable" style="display:block;" class="dblist">
I am trying to implement mytag:search-filter as follows -
<@tag .... dynamic-attributes="dynattrs">
<@attribute name="type" required="true">
<c:if test="${type == 'dropdown'}">
<mytag:dropdown table="$dynattrs['table']">
</c:if>
The outer tag has its own set of declared attributes and I want the inner tag's attributes to be passed in as dynamic attributes to the outer tag. The outer tag will then pass its dynamic attributes to the inner tag
I have tried the following and none of them seem to work -
<c:set var="attrs">
<c:forEach items="${dynattrs}" var="a">
${a.key}="${a.value}"
</c:forEach>
</c:set>
<mytag:dropdown table="$dynattrs['table']" ${attrs}/>
The above gives a "Unterminated Tag %lt;mytag:dropdown" Error
<mytag:dropdown table="$dynattrs['table']">
<c:forEach items="${dynattrs}" var="a">
<jsp:attribute name="${a.key}" trim="true">${a.value}</jsp:attribute>
</c:forEach>
</mytag:dropdown>
** The above does not throw any error, but the attribute value inside the inner tag is always empty.
Constraints I have :
a) I want to stick to tag files and do not want to use Java class implementation of TagSupport.
b) As far as possible, do not want to change the inner tag implementation because it is widely used in its current form and any change to it means a huge effort on rework.
Is it possible to achieve what I am trying to do ?
Why do the above not work (especially the second one) ?
Upvotes: 2
Views: 971