Re: [struts] parameter to custom tag

2008-02-28 Thread Kropp, Henning

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:



> 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)


items="${some.el.expression.that.returns.the.collection}">

  


or


  


-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]



Re: [struts] parameter to custom tag

2008-02-28 Thread Dale Newfield

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:



> 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)


items="${some.el.expression.that.returns.the.collection}">

  


or


  


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [struts] parameter to custom tag

2008-02-28 Thread Kropp, Henning

Dale Newfield schrieb:

Kropp, Henning wrote:

I figured it out. I used  for this. Thanks.


   
   
   



That will only work if the value you're trying to pass is a string.
It might also add whitespace to either end of that value (due to the 
whitespace inside your s:set tag.


Why not pass the OGNL expression to your tag as a string and evaluate 
it inside your custom tag, instead?  If you use this custom tag in 
many places, I predict the extra jsp required to pre-evaluate the 
OGNL->string will be error-prone...


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



I must add that s:set printed out the string as well. I am not quit sure 
if its supposed to, but it did. Therefor I even had to encapsulate 
s:property with a s:param statement. Like this



  

  

  
 



This is quite a big block for little I wanted to achieve.

I thought about passing the whole list to the tag too, but somehow it 
did not feel like the right thing to do, at least as I would have done 
it. 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?


thx

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [struts] parameter to custom tag

2008-02-27 Thread Dale Newfield

Kropp, Henning wrote:

I figured it out. I used  for this. Thanks.


   
   
   



That will only work if the value you're trying to pass is a string.
It might also add whitespace to either end of that value (due to the 
whitespace inside your s:set tag.


Why not pass the OGNL expression to your tag as a string and evaluate it 
inside your custom tag, instead?  If you use this custom tag in many 
places, I predict the extra jsp required to pre-evaluate the 
OGNL->string will be error-prone...


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]