• Post Reply Bookmark Topic Watch Topic
  • New Topic

nesting tags in arguments?  RSS feed

 
Ulrich Doe
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'd like to use a bean:message tag as argument for 'content' in the template:insert tag:


<%@ taglib uri="/WEB-INF/template.tld" prefix="template" %>

<template:insert template="/some/file.jsp">
<template:put name='title' content='<bean:message key="some.key"/>' direct='true' />
...
</template:insert>


brief:

<template:put .. content='<bean:message key="some.key"/>' .. />


It does not work when I test it. Can it be done somehow? Is there some configuration option for template.tld?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cannot nest a custom tag in another custom tag.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In cases like these there are two alternative approaches.
1 - put the value as the body of the tag (if the tag supports it)
2 - use a runtime expression for the value

I don't think the tag you are using supports a body content. If it did it look something like:
<template:put name='title' direct='true'><bean:message key="some.key"/></template:put>

So that leaves option 2.
Here is how I would do it using JSTL/EL



Actually I think I would use the JSTL tag in place of the bean:message tag which would simplify it a bit more


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan makes an excellent point. I think a lot people still use old Struts tags in lieu of the JSTL out of habit.

If a JSTL tag exists that does what you want, always use it rather than a proprietary tag. It's likely to be much more versatile.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!