You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Varun Ratra <vr...@symcor.com> on 2008/02/22 20:58:51 UTC

How to call javascript from Struts tag

Hello everyone,

I have been researching on the web on how to call javascript from Struts
tag. 
I am using struts 2 to develop JSP. Following is the piece of code in JSP,
which calls javascript
<td class="nowrap">
	<script type="text/javascript">
	     document.write(shortenTextLength('${defaultReturnReason}',
'${displayLength}'))
	</script>	
</td>
The script returns a shortened value of defaultReturnReason based
displayLength
I want to use struts tag to call javascript shortenTextLength(). In other
words, I want to embed javascript inside struts tag.
Please suggest how I can achieve this.
-- 
View this message in context: http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p15641406.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: How to call javascript from Struts tag

Posted by Musachy Barroso <mu...@gmail.com>.
like:

<s:a onclick="alert('hey!')"/>click me </s:a>

?

musachy

On Thu, Feb 28, 2008 at 11:43 AM, Varun Ratra <vr...@symcor.com> wrote:
>
>  Hi,
>
>  Thanks for the valuable information. The problem is my company is not using
>  ajax at the moment. Is there any other way to call the javascipt funtion in
>  struts tag. I have a java script function placed in web project. This
>  function returns a value
>
>  function shortenTextLength(text, textlength)
>  {
>         var textValue = text;
>         if (textValue.length > textlength){
>                 var shortenedText = textValue.substring(0,textlength) + "...";
>         }else{
>                 var shortenedText = text;
>         }
>         return (shortenedText);
>  }
>
>  I want to call function shortenTextLength(text, textlength) in JSP using
>  struts tag.
>  regards,
>  Varun
>
>
>  mgainty wrote:
>  >
>  > lets say you have some tag which has its base function called
>  > updateReports()
>  >
>  > assuming the div tag has theme="ajax"  referencing
>  > http://struts.apache.org/2.0.11/docs/ajax-div-template.html
>  > <saf:head theme="ajax" />
>  > function doit(){  document.login_form.hidden_id.value="01420";}</script>
>  > <script type="text/javascript">
>  >     function updateReports(id)     {       doit(); //this modifies the
>  > zipcode (id) for the weather       id =
>  > document.login_form.hidden1.value;
>  > var reportDiv= window['reportDivId'];       reportDiv.href =
>  > '/../reportListRemote.action?selectedId='+id;
>  >        reportDiv.refresh();    }
>  >     dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null,
>  > "updateReports");
>  > </script>
>  > Here is the html
>  > <html>
>  > <body>
>  > <form>
>  > <table>
>  > <input type="hidden" name="hidden1" value="hidden1">
>  > ..</table></form></body></html>HTHM------- Original Message -----
>  > From: "Varun Ratra" <vr...@symcor.com>
>  > To: <us...@struts.apache.org>
>  > Sent: Friday, February 22, 2008 4:05 PM
>  > Subject: How to call javascript from Struts tag
>  >
>  >
>  >>
>  >> Hello everyone,
>  >>
>  >> I have been researching on the web on how to call javascript from Struts
>  >> tag.
>  >> I am using struts 2 to develop JSP. Following is the piece of code in
>  >> JSP,
>  >> which calls javascript
>  >> <td class="nowrap">
>  >> <script type="text/javascript">
>  >>      document.write(shortenTextLength('${defaultReturnReason}',
>  >> '${displayLength}'))
>  >> </script>
>  >> </td>
>  >> The script returns a shortened value of defaultReturnReason based
>  >> displayLength
>  >> I want to use struts tag to call javascript shortenTextLength(). In other
>  >> words, I want to embed javascript inside struts tag.
>  >> Please suggest how I can achieve this.
>  >> --
>  >> View this message in context:
>  > http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p1564
>  > 1406.html
>  >> Sent from the Struts - User mailing list archive at Nabble.com.
>  >>
>  >>
>  >> ---------------------------------------------------------------------
>  >> 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
>  >
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p15740609.html
>  Sent from the Struts - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>  For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: How to call javascript from Struts tag

Posted by Dave Newton <ne...@yahoo.com>.
Your requirement, as stated, is more complicated than is worth doing.

IMO you'd be better served doing this conversion on the server side.

Dave

--- Varun Ratra <vr...@symcor.com> wrote:
> Thanks for the valuable information. The problem is my company is not using
> ajax at the moment. Is there any other way to call the javascipt funtion in
> struts tag. I have a java script function placed in web project. This
> function returns a value
> 
> function shortenTextLength(text, textlength)
> {
> 	var textValue = text;
> 	if (textValue.length > textlength){
> 		var shortenedText = textValue.substring(0,textlength) + "...";
> 	}else{
> 		var shortenedText = text;
> 	}
> 	return (shortenedText);
> }
> 
> I want to call function shortenTextLength(text, textlength) in JSP using
> struts tag.
>
> > From: "Varun Ratra" <vr...@symcor.com>
> >> I have been researching on the web on how to call javascript from Struts
> >> tag.
> >> I am using struts 2 to develop JSP. Following is the piece of code in
> >> JSP,
> >> which calls javascript
> >> <td class="nowrap">
> >> <script type="text/javascript">
> >>      document.write(shortenTextLength('${defaultReturnReason}',
> >> '${displayLength}'))
> >> </script>
> >> </td>
> >> The script returns a shortened value of defaultReturnReason based
> >> displayLength
> >> I want to use struts tag to call javascript shortenTextLength(). In
> other
> >> words, I want to embed javascript inside struts tag.
> >> Please suggest how I can achieve this.
> >> --
> >> View this message in context:
> >
>
http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p1564
> > 1406.html
> >> Sent from the Struts - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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
> > 
> > 
> > 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p15740609.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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: How to call javascript from Struts tag

Posted by Varun Ratra <vr...@symcor.com>.
Hi,

Thanks for the valuable information. The problem is my company is not using
ajax at the moment. Is there any other way to call the javascipt funtion in
struts tag. I have a java script function placed in web project. This
function returns a value

function shortenTextLength(text, textlength)
{
	var textValue = text;
	if (textValue.length > textlength){
		var shortenedText = textValue.substring(0,textlength) + "...";
	}else{
		var shortenedText = text;
	}
	return (shortenedText);
}

I want to call function shortenTextLength(text, textlength) in JSP using
struts tag.
regards,
Varun


mgainty wrote:
> 
> lets say you have some tag which has its base function called
> updateReports()
> 
> assuming the div tag has theme="ajax"  referencing
> http://struts.apache.org/2.0.11/docs/ajax-div-template.html
> <saf:head theme="ajax" />
> function doit(){  document.login_form.hidden_id.value="01420";}</script>
> <script type="text/javascript">
>     function updateReports(id)     {       doit(); //this modifies the
> zipcode (id) for the weather       id = 
> document.login_form.hidden1.value;
> var reportDiv= window['reportDivId'];       reportDiv.href =
> '/../reportListRemote.action?selectedId='+id;
>        reportDiv.refresh();    }
>     dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null,
> "updateReports");
> </script>
> Here is the html
> <html>
> <body>
> <form>
> <table>
> <input type="hidden" name="hidden1" value="hidden1">
> ..</table></form></body></html>HTHM------- Original Message -----
> From: "Varun Ratra" <vr...@symcor.com>
> To: <us...@struts.apache.org>
> Sent: Friday, February 22, 2008 4:05 PM
> Subject: How to call javascript from Struts tag
> 
> 
>>
>> Hello everyone,
>>
>> I have been researching on the web on how to call javascript from Struts
>> tag.
>> I am using struts 2 to develop JSP. Following is the piece of code in
>> JSP,
>> which calls javascript
>> <td class="nowrap">
>> <script type="text/javascript">
>>      document.write(shortenTextLength('${defaultReturnReason}',
>> '${displayLength}'))
>> </script>
>> </td>
>> The script returns a shortened value of defaultReturnReason based
>> displayLength
>> I want to use struts tag to call javascript shortenTextLength(). In other
>> words, I want to embed javascript inside struts tag.
>> Please suggest how I can achieve this.
>> --
>> View this message in context:
> http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p1564
> 1406.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p15740609.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: How to call javascript from Struts tag

Posted by Martin Gainty <mg...@hotmail.com>.
lets say you have some tag which has its base function called
updateReports()

assuming the div tag has theme="ajax"  referencing
http://struts.apache.org/2.0.11/docs/ajax-div-template.html
<saf:head theme="ajax" />
function doit(){  document.login_form.hidden_id.value="01420";}</script>
<script type="text/javascript">
    function updateReports(id)     {       doit(); //this modifies the
zipcode (id) for the weather       id =  document.login_form.hidden1.value;
var reportDiv= window['reportDivId'];       reportDiv.href =
'/../reportListRemote.action?selectedId='+id;
       reportDiv.refresh();    }
    dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null,
"updateReports");
</script>
Here is the html
<html>
<body>
<form>
<table>
<input type="hidden" name="hidden1" value="hidden1">
..</table></form></body></html>HTHM------- Original Message -----
From: "Varun Ratra" <vr...@symcor.com>
To: <us...@struts.apache.org>
Sent: Friday, February 22, 2008 4:05 PM
Subject: How to call javascript from Struts tag


>
> Hello everyone,
>
> I have been researching on the web on how to call javascript from Struts
> tag.
> I am using struts 2 to develop JSP. Following is the piece of code in JSP,
> which calls javascript
> <td class="nowrap">
> <script type="text/javascript">
>      document.write(shortenTextLength('${defaultReturnReason}',
> '${displayLength}'))
> </script>
> </td>
> The script returns a shortened value of defaultReturnReason based
> displayLength
> I want to use struts tag to call javascript shortenTextLength(). In other
> words, I want to embed javascript inside struts tag.
> Please suggest how I can achieve this.
> --
> View this message in context:
http://www.nabble.com/How-to-call-javascript-from-Struts-tag-tp15641406p1564
1406.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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