aspose file tools*
The moose likes Struts and the fly likes javascript with bean:write tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "javascript with bean:write tag" Watch "javascript with bean:write tag" New topic
Author

javascript with bean:write tag

Tracy Ward
Greenhorn

Joined: Sep 07, 2005
Posts: 4
I'm trying to format the text from a bean:write tag with a simple javascript function and I cannot figure out how to pass the value of the bean tag to the funtion.

This is the function:

function shorten (str, iLen){
if (len(str) > iLen){
shorten = Trim(left(str, iLen) + "...");
}
else{
shorten = Trim(str);
}
}

and I'd like to execute this within a jsp :
<td>
<%shorten(<bean:write name="rpt" property="issueDescription" filter="false"/>, 50)%>
</td>

does nayone have any suggestions to get the desired result?
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
<%%> is used for scriptlets not for javascript.
You should use your javascript funcion within HTML.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
remove the scriptlet tags <% %> surrounding the javascript call and use

[ September 07, 2005: Message edited by: alan do ]

-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Tracy Ward
Greenhorn

Joined: Sep 07, 2005
Posts: 4
Thanks for the quick response - I've implimented the change and I no longer get an error but I'm getting nothing returned to the page (Though I've added alerts and all of the values are passed correctly to the function) so I'm hoping there's a trick to getting the response to write....

<script language="javascript">
function shorten(string, length){

var short;

alert(string);

if (string.length > length){

alert('if' + string.length);

short = string.substring(0, length) + "...";
}

else{

alert('else' + string.length);
short = string;
}

return short;

}
</script>

<td width="30%">
<script language="javascript">
shorten('<bean:write name="rpt" property="issueDescription" filter="false"/>', 50);
</script>
</td>
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
ah...the trick to getting the right answer is to ask the right question.

you're not getting anything back because your script only processes the value and returns the value for javascript to use. you need to have a document.writeln(short); instead of return short;
Tracy Ward
Greenhorn

Joined: Sep 07, 2005
Posts: 4
Alan, you're awesome, thanks so much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript with bean:write tag