[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JSP Custom tag with javascript function add the head section

Posted on 2006-05-03
3
Medium Priority
?
945 Views
Last Modified: 2013-11-24
Using the custom java tag, is it possible to include a java script function at the HTML HEAD section, and add the function name to the BODY Onload method?

ie
<HTML>
<HEAD>
<script>
function init(){
alert("this is added script);
}
</script>
</HEAD>
<BODY onload="init()">
</BODY>
</HTML>
0
Comment
Question by:william007
3 Comments
 
LVL 19

Assisted Solution

by:Jim Cakalic
Jim Cakalic earned 800 total points
ID: 16598825
Not really, unless the tag was responsible for generating at least the </head> and <body> tags of the markup. It would probably look something like:

<HTML>
<HEAD>
<mytag:init/>
</BODY>
</HTML>

And then the init custom tag in the mytag library would be responsible for generating:

<script>
function init(){
alert("this is added script);
}
</script>
</HEAD>
<BODY onload="init()">

I don't think this is particularly useful though. Can you elaborate on the problem?
0
 
LVL 10

Accepted Solution

by:
radarsh earned 1200 total points
ID: 16599510
Hi william007,

Why would you want write a custom tag for such a simple task?
Can't you just have a scriptlet for the function name and use the same
to generate the onload event?

Something like this:

<html>
<head>
<script type="text/javascript">
    <%=funcStr%>
</script>
</head>
<body onload="<%=funcStr.trim().substring(8, funcStr.indexOf('(')).trim()%>">
</body>
</html>


Here, what I have done is, I have stored funcStr as something like:

String funcStr = "function init() {\n\talert('hi');\n\t}";

Now, I extract the function's name, init using funcStr.trim().substring(8, funcStr.indexOf('(')).trim()


________
radarsh
0
 
LVL 9

Author Comment

by:william007
ID: 16612052
Thanks, I just want to know whether there is a way to do it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question