Jsp custom tag with value of an attribute as another custom tag

1.8k Views Asked by At

I am creating some jsp custom tags.Now I have a requirement as follows :

<bb:custom1 id="id1" attr1="<bb:custom2 attr2='attr2val'></bb:custom2>"></bb:custom1>

ie the value for an attribute should be another custom tag which will be resolved by the corresponding tag handler. I could see that this works with all the html tags.But when i tried with my custom tags it does not work.Can some one please tell me how this can be attained.

I am creating custom tags using tag handlers.

2

There are 2 best solutions below

2
On

You nead to define custom EL function, not a custom tag bb:custom2. Than you can call it:

<bb:custom1 id="id1" attr1="${bb:custom2(attr2val)}"></bb:custom1>

You can read about EL functions here.

0
On

I resolved the problem by using a temporary variable:

<c:set name="val_attr">
    <bb:custom2 attr2='attr2val' />
</c:set>

<bb:custom1 id="id1" attr1="${val_attr}"></bb:custom1>

And it will works with any taglibs (e.g. custom2 can be from cc:custom2).

Another advantage is that you does not need to know the function syntax (e.g. if many parameters are needed, which order to put):

<c:set name="val_attr">
    <cc:custom2 param2='myparam2' param1='myparam1' />
</c:set>

<bb:custom1 id="id1" attr1="${val_attr}"></bb:custom1>