• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom tag use output of another tag

 
Mike Dalton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty new with jsp.
I've created a custom tag and I need to use the output of another tag.
e.g:
<customtagfile:nameOfTag text="${user.name}"/>
<customtagfile:nameOfTag2 "/>

nameOfTag2 needs to use the output from nameOfTag.
How can this be done and what needs to be set in the tag file?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you specifically mean by "output"? What's emitted to the response? Something else?

If the former, using the JSTL <c:set> tag to wrap the first tag can capture its "output" into a scoped variable that can be passed into the second tag.
 
Mike Dalton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With output I mean the result of the first tag.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Dalton wrote:With output I mean the result of the first tag.

"Result" as in what gets inserted into the response? If so, then already answered. if you mean something else, we need to know what.
 
Mike Dalton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Result as what comes out of the first tag.
e.g. "some text" now I need to use this in the second tag.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the result of the first tag also need to appear on the page? Or is it just for use by the subsequent tag?

If this is something that you're just going to use once, I'd use the <c:set> approach I mentioned earlier.

If it's going to be reused a lot, I'd set up something more formal where you'd provide a name and scope to the first tag so that it could create a scoped variable with a result that could be used elsewhere on the page, including as an argument to another tag.
 
Mike Dalton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The result of the first tag doesn't appear on the page only of the second tag. The result of the first tag is used by the second tag.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I'm wandering why they are separate tags? If the processing of the first doesn't emit anything when it is invoked, and its processing is needed by the second tag, why isn't the processing just part of the second tag?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!