Kilokahn
Kilokahn

Reputation: 2311

Using custom JSTL tags in a Struts tag attribute

I have a custom JSTL tag say foo which writes a said property to the writer. Now I want to use the value that the tag wrote in a Struts tag. As an example, the custom tag is invoked as

<foo:property name="bar"/>

The Struts tag here is say <s:form/>. I want to be able to determine the value of the action attribute of the <s:form/> using the value from <foo:property/> like:

<s:form action="<foo:property name='bar'/>"/>

I understand that Struts tag attributes by default evaluate from objects on the ValueStack and we can use OGNL to precisely access those. The question really is if there is a way that we can put the value obtained from the custom JSTL on the ValueStack and then use OGNL to access it in the expression used to interpolate the action attribute.

Overall, is this possible at all? If so, a quick code snippet would really help clarify the solution.

Please let me know if I should clarify something.

Upvotes: 1

Views: 1145

Answers (1)

Roman C
Roman C

Reputation: 1

The value that is written by the custom tag can be use as a body of the set tag, which put the value in the ValueStack, then you can access it via OGNL in the form tag attribute.

If the tag is used with body content, the evaluation of the value parameter is omitted. Instead, the String to which the body evaluates is set as value for the scoped variable.

<s:set var="foo"><foo:property name="bar"/></s:set> 
<s:form action="%{#foo}">

Upvotes: 2

Related Questions