struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Newfield <>
Subject Re: [struts] parameter to custom tag
Date Thu, 28 Feb 2008 17:51:22 GMT
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 

<c:foreach var="customTagArg" 
   <custom:tag attr="${customTagArg}"/>


<s:iterator value="%{model.list}">
   <custom:tag attr="%{top}"/>


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message