You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Cook, Lori A" <lo...@hp.com> on 2004/11/10 20:10:48 UTC

vs. onclick result

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


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


Re: vs. onclick result

Posted by Ben Anderson <be...@gmail.com>.
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 Martin Cooper <mf...@gmail.com>.
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 %>);" />

This doesn't work because it is not legal to mix literals and
expressions in the value of an attribute. If part of it needs to be an
expression, then all of it needs to be an expression, as you tried to
do below.

>    <html:img src="normal.gif" alt="" onclick=<%= "\"confirmAction(" +
> pathParam + ");\"" %> />

You have the right idea here, but you have the quotes in the wrong
place. Try this instead:

<html:img src="normal.gif" alt=""
  onclick='<%= "confirmAction(" + pathParam + ");" %>'
  />

--
Martin Cooper


> 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: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org