Thank you Dale!
Dale Newfield schrieb:
Kropp, Henning wrote:
I must add that s:set printed out the string as well. I am not quit
sure if its supposed to, but it did.
I glossed over this--I wouldn't use s:set here, but rather c:set.
Neither one should print the value (are you sure you didn't do that
for debugging inside your custom tag?), but since you're trying to set
a value to be extracted with EL, I'd use the tag library that is
geared toward EL.
That would be:
<c:set var="stringArgForCustomTag"><s:property /></c:set>
<custom:tag attr="${stringArgForCustomTag}"/>
> My understanding of struts is not as experienced so if I may ask,
why would I need an extra jsp to pre-evaluate the OGNL as string as
you proposed?
You don't. If you want to use EL exclusively to extract the data,
don't use s:iterator, but rather one of the c: loop tags, then you
won't need the "set". If you want to use OGNL to name/manipulate/etc.
the data, then something needs to be able to take that OGNL expression
and evaluate it. Your current solution to that is to have s:property
do the work, and have c:set store the results of that work in a place
that can then be handed off to your custom tag. An alternate solution
would be to enable your custom tag to evaluate OGNL directly. So
you'd probably have within your tag a String setter for attr that just
stores the string expression (argExpr below), then in your doTag (or
doStartTag, or whatever) do something like the following:
PageContext pageContext = (PageContext) getJspContext();
ValueStack valueStack = TagUtils.getStack(pageContext);
argValue = valueStack.findString(argExpr);
to ask OGNL to evaluate the expression for you and give you the
resulting value.
So, two different solutions, neither of which need the :set tag:
(the first assumes the collection is in some space where it can be
grabbed by EL, the second that your custom tag does it's own OGNL
evaluation)
<c:foreach var="customTagArg"
items="${some.el.expression.that.returns.the.collection}">
<custom:tag attr="${customTagArg}"/>
</c:foreach>
or
<s:iterator value="%{model.list}">
<custom:tag attr="%{top}"/>
</s:iterator>
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]