You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ben Anderson <be...@gmail.com> on 2004/11/10 20:37:09 UTC

Re: vs. onclick result

Lori,
notice I took this to the struts list.  The struts tags don't support
runtime expressions.  There is a subset of struts tags that supports
EL (expression language).  You might try the following approach:

<c_rt:set var="pathParam" value="<%= pathParm %>"/>
<html-el:img ... onclick="${pathParam}"/>

However, it'd be even better if you didn't need the first line.  There
are times when scriplet expressions must be used (static variables),
but you should try to avoid them when you can.

-Ben

On Wed, 10 Nov 2004 11:10:48 -0800, Cook, Lori A <lo...@hp.com> wrote:
> I am experiencing difficulty using tag libraries and the passing through
> of scripting variables in attributes. Specifically I'm trying to add an
> onclick value to an <html:img> tag but this is generic for any tag in
> the Struts libraries where the user can supply a value to an attribute.
> 
> When the following markup is used in a jsp:
>     <img src="minor.gif" alt="" onclick="confirmAction(<%= pathParam
> %>);" />
>     <img src="minor.gif" alt="" onclick=<%= "\"confirmAction(" +
> pathParam + ");\"" %> />
> The resulting HTML is:
>     <img src="minor.gif" alt="" onclick="confirmAction(Foo);" />
>     <img src="minor.gif" alt="" onclick="confirmAction(Foo);" />
> 
> As you can see either one of the jsp versions 'work' to create a good
> onclick method.
> 
> But when the code is changed to use the <html:img> tag it doesn't work.
> That is with the following jsp markup:
>     <html:img src="normal.gif" alt="" onclick="confirmAction(<%=
> pathParam %>);" />
>     <html:img src="normal.gif" alt="" onclick=<%= "\"confirmAction(" +
> pathParam + ");\"" %> />
> The resulting HTML is:
>     <img src="normal.gif" alt="" onclick="confirmAction(<%= pathParam
> %>);">
>     <html:img src="normal.gif" alt="" onclick="confirmAction(Foo);" />
> 
> While the first instance of <html:img> gets changed into the <img>
> markup the scripting variable pathParam does not get resolved. In the
> second case the scripting variable gets resolved but the <html:img> does
> not get changed into its appropriate <img>.
> 
> Why? And how do you get the correct behavior?
> 
> Any help is greatly appreciated.
> Lori Cook
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: vs. onclick result

Posted by Peng Tuck <pe...@bluebottle.com>.
Lori,
    If pathParam is a bean you pass in through the request or any scope  
you could use
<bean:write> to output the value of the bean without resorting to 
scriplets.



Ben Anderson wrote:

>Lori,
>notice I took this to the struts list.  The struts tags don't support
>runtime expressions.  There is a subset of struts tags that supports
>EL (expression language).  You might try the following approach:
>
><c_rt:set var="pathParam" value="<%= pathParm %>"/>
><html-el:img ... onclick="${pathParam}"/>
>
>However, it'd be even better if you didn't need the first line.  There
>are times when scriplet expressions must be used (static variables),
>but you should try to avoid them when you can.
>
>-Ben
>
>On Wed, 10 Nov 2004 11:10:48 -0800, Cook, Lori A <lo...@hp.com> wrote:
>  
>
>>I am experiencing difficulty using tag libraries and the passing through
>>of scripting variables in attributes. Specifically I'm trying to add an
>>onclick value to an <html:img> tag but this is generic for any tag in
>>the Struts libraries where the user can supply a value to an attribute.
>>
>>When the following markup is used in a jsp:
>>    <img src="minor.gif" alt="" onclick="confirmAction(<%= pathParam
>>%>);" />
>>    <img src="minor.gif" alt="" onclick=<%= "\"confirmAction(" +
>>pathParam + ");\"" %> />
>>The resulting HTML is:
>>    <img src="minor.gif" alt="" onclick="confirmAction(Foo);" />
>>    <img src="minor.gif" alt="" onclick="confirmAction(Foo);" />
>>
>>As you can see either one of the jsp versions 'work' to create a good
>>onclick method.
>>
>>But when the code is changed to use the <html:img> tag it doesn't work.
>>That is with the following jsp markup:
>>    <html:img src="normal.gif" alt="" onclick="confirmAction(<%=
>>pathParam %>);" />
>>    <html:img src="normal.gif" alt="" onclick=<%= "\"confirmAction(" +
>>pathParam + ");\"" %> />
>>The resulting HTML is:
>>    <img src="normal.gif" alt="" onclick="confirmAction(<%= pathParam
>>%>);">
>>    <html:img src="normal.gif" alt="" onclick="confirmAction(Foo);" />
>>
>>While the first instance of <html:img> gets changed into the <img>
>>markup the scripting variable pathParam does not get resolved. In the
>>second case the scripting variable gets resolved but the <html:img> does
>>not get changed into its appropriate <img>.
>>
>>Why? And how do you get the correct behavior?
>>
>>Any help is greatly appreciated.
>>Lori Cook
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org