jspstruts2eltaglibstruts-tags

How to inject the value of a Struts <s:property /> tag into another tag


I want to take the value of an attribute in the action class by using Struts2 property tag <s:property value="id"/> and give it to another tag, something like this (wrong code, just to give the idea):

<t:tag id="<s:property value="id"/>"/>

How can I do this?

Note: <t: is mapped to a custom taglibrary.


Solution

  • You can't nest (server-side) tags like that;

    If you don't know exactly what you are doing, I'd suggest to stick with the existing taglibraries, standing on the shoulders of the giants; if instead you are inheriting it, and can't drop it, then try with JSP EL syntax:

    <t:tag id="${id}"/>
    

    (Objects in the Value Stack are made available to JSP EL by the Struts2 request wrapper)