You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dennis Atkinson <de...@yahoo.com> on 2010/12/22 04:30:15 UTC

Invoking Javascript function from Struts 1.3

Greetings all.

I have a problem invoking Javascript that I can't seem to solve.  I'm hoping someone here has run into the same kind of thing.
 
When I am iterating through a List of items to display (via the <logic:iterate> tag), one cell I am trying to write has to be a link to a Javascript function, with three parameters.  If I wasn't using Struts, I'd write standard html, like so:

<a href="javascript:showStuffForPerson('405574', '459', '3')">405574</a>

But if I do this in Struts, I get that exact string in the cell, which isn't what I want. I need to have 405574 in the cell, and when I click on it, the javascript has to be invoked with those three parameters.  It really, really needs to work this
 way.

I tried experimenting with the <html:link> tag, and it *seems* like that's the way to go, but I am lost with respect to the associated <html:param> tags.  I assume I'll need three of them (one for each parameter), but I can't seem to make that work.  If I give them a name, it doesn't work, and if I don't give them a name that doesn't work any better.

Or maybe I'm going about this all wrong?

Any assistance would be very much appreciated.

Thanks in advance,

Dennis



      

Re: Invoking Javascript function from Struts 1.3

Posted by Dave Newton <da...@gmail.com>.
On Wed, Dec 22, 2010 at 12:16 PM, <Th...@barclayswealth.com> wrote:

> > Why use a struts tag to generate a non-struts link?
> And, this seems like a perfectly reasonable thing to do.


Not really. The whole point of the Struts tags is to access Struts
functionality, like action mappings. All this is is pure JavaScript. No
Struts. Accessing properties to use as parameters doesn't require the use of
a Struts link tag, because that's not what the Struts link tag is for.


> We do the same thing here and it's not complicated to do.  I don't think
> you need to mess with the <html:link> tag.  Just create the tag normally,
> the same way as you would sans Struts, and use your beans to supply the
> values.


Wth. That's precisely what I said.

Dave

RE: Invoking Javascript function from Struts 1.3

Posted by Th...@barclayswealth.com.
>
> Why use a struts tag to generate a non-struts link?
>
>Dave
>


Dave,

The OP wrote:

> It really, really needs to work this way.

So I am going to assume that it does.

And, this seems like a perfectly reasonable thing to do.  If a company has existing functionality in javascript, they want to link to it.  It is illogical to expect them to rewrite their javascript stuff in Struts.  Or in anything else, for that matter.


Dennis,

We do the same thing here and it's not complicated to do.  I don't think you need to mess with the <html:link> tag.  Just create the tag normally, the same way as you would sans Struts, and use your beans to supply the values.

The three properties are prop1, prop2, prop3.


<logic:iterate id="listdata" name="theList"  
	type="putTheFullClassNameHere" scope="page">     
	<tr>
         		
    <td>
		<a href="javascript:showStuffForPerson(
				'<bean:write name="listdata" property="prop1"/>', 
				'<bean:write name="listdata" property="prop2"/>', 
				'<bean:write name="listdata" property="prop3"/>')">
			<bean:write name="listdata" property="prop1"/>
		</a>
   </td>


Have fun.

--Tom





-----Original Message-----
From: Dave Newton [mailto:davelnewton@gmail.com] 
Sent: Wednesday, December 22, 2010 10:09 AM
To: Struts Users Mailing List
Subject: Re: Invoking Javascript function from Struts 1.3

Why use a struts tag to generate a non-struts link?

Dave

On Tuesday, December 21, 2010, Dennis Atkinson
<de...@yahoo.com> wrote:
> Greetings all.
>
> I have a problem invoking Javascript that I can't seem to solve.  I'm hoping someone here has run into the same kind of thing.
>
> When I am iterating through a List of items to display (via the <logic:iterate> tag), one cell I am trying to write has to be a link to a Javascript function, with three parameters.  If I wasn't using Struts, I'd write standard html, like so:
>
> <a href="javascript:showStuffForPerson('405574', '459', '3')">405574</a>
>
> But if I do this in Struts, I get that exact string in the cell, which isn't what I want. I need to have 405574 in the cell, and when I click on it, the javascript has to be invoked with those three parameters.  It really, really needs to work this
>  way.
>
> I tried experimenting with the <html:link> tag, and it *seems* like that's the way to go, but I am lost with respect to the associated <html:param> tags.  I assume I'll need three of them (one for each parameter), but I can't seem to make that work.  If I give them a name, it doesn't work, and if I don't give them a name that doesn't work any better.
>
> Or maybe I'm going about this all wrong?
>
> Any assistance would be very much appreciated.
>
> Thanks in advance,
>
> Dennis
>
>
>
>

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

This message is intended for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Barclays Capital Inc., its subsidiaries or affiliates. Barclays Wealth is the wealth management division of Barclays Bank PLC, functioning through Barclays Capital Inc. in the United States. Barclays Capital Inc. is a U.S. registered broker-dealer and is regulated by the U.S. Securities & Exchange Commission. Member SIPC. For more information, visit us at: www.barcap.com. 

IRS Circular 230 Disclosure: Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.

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


Re: Invoking Javascript function from Struts 1.3

Posted by Dave Newton <da...@gmail.com>.
Why use a struts tag to generate a non-struts link?

Dave

On Tuesday, December 21, 2010, Dennis Atkinson
<de...@yahoo.com> wrote:
> Greetings all.
>
> I have a problem invoking Javascript that I can't seem to solve.  I'm hoping someone here has run into the same kind of thing.
>
> When I am iterating through a List of items to display (via the <logic:iterate> tag), one cell I am trying to write has to be a link to a Javascript function, with three parameters.  If I wasn't using Struts, I'd write standard html, like so:
>
> <a href="javascript:showStuffForPerson('405574', '459', '3')">405574</a>
>
> But if I do this in Struts, I get that exact string in the cell, which isn't what I want. I need to have 405574 in the cell, and when I click on it, the javascript has to be invoked with those three parameters.  It really, really needs to work this
>  way.
>
> I tried experimenting with the <html:link> tag, and it *seems* like that's the way to go, but I am lost with respect to the associated <html:param> tags.  I assume I'll need three of them (one for each parameter), but I can't seem to make that work.  If I give them a name, it doesn't work, and if I don't give them a name that doesn't work any better.
>
> Or maybe I'm going about this all wrong?
>
> Any assistance would be very much appreciated.
>
> Thanks in advance,
>
> Dennis
>
>
>
>

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