-
1. Re: where should i include my javascript file?
tufla Aug 2, 2007 12:55 PM (in response to saigon_man)Hello,
You can put your js file, for example, into a directory called "js" in your root application, then you should edit your jboss-potlet.xml file (located in WEB-INF directory, or you should create it) to include it in the header content as is showed below:<portlet> <portlet-name>YourPortlet</portlet-name> <header-content> <script type="text/javascript" src="/js/your_js_file.js"></script> </header-content> </portlet>
That's all. -
2. Re: where should i include my javascript file?
saigon_man Aug 2, 2007 2:45 PM (in response to saigon_man)Thanks for the hint, I followed the instruction but somehow, the browser could not find the javascript.
Here what I've done
in my jboss-portlet.xml<portlet> <portlet-name>HelloWorldJSPPortlet</portlet-name> <transaction> <trans-attribute>Required</trans-attribute> </transaction> <header-content> <script type="text/javascript" src="/js/myscript.js"/> </header-content> </portlet>
i created a folder called js at the same level as WEB-INF and put myscript.js in there. When I click on the button in that jsp portlet to invoke the function in javascript, the browser complaints that it can not find that file. So, my war structure is:
mywar.war
---- js
---- myscript.js
---- WEB-INF
---- jboss-portlet.xml
---- some more xml files
here is the code in my jsp file<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <portlet:defineObjects/> <div id="msg">I am default</div> <br/> <button onclick="testing();">Change me</button>
in myscript.jsfunction testing(){ document.getElementById("msg").innerHTML = "I am changed"; }
Am I missing something here?
Thanks
TL -
3. Re: where should i include my javascript file?
tufla Aug 2, 2007 3:36 PM (in response to saigon_man)Well, I've done that procedure few time ago and that works for me...
Can you see the inclusion of your js file in the source code generated when you access your page ?? -
4. Re: where should i include my javascript file?
saigon_man Aug 2, 2007 3:40 PM (in response to saigon_man)yes, it printed out the text "i ma default" along with the button. But when I view the source, I can not see the line for my javascript included in the header. I think I am missing some steps here. Any idea how to solve it?
Thanks,
TL -
5. Re: where should i include my javascript file?
tufla Aug 2, 2007 4:00 PM (in response to saigon_man)I think that should be a stupid problem...
Are you restarted the server after change on jboss-potlet.xml ?? because at least, after include the header-content in this file, should appear the line into source code...could be wrong the path, but the line should appear...
The only difference with my setup is that I don't have the "" tag in my definition. -
6. Re: where should i include my javascript file?
tufla Aug 2, 2007 4:01 PM (in response to saigon_man)<transaction>
tag * -
7. Re: where should i include my javascript file?
saigon_man Aug 2, 2007 4:12 PM (in response to saigon_man)I already removed the tag but it does not make any different. Are you using the same version 2.6 as well? I read something off from sourceforge for JBoss bug
[JBPORTAL-1246] Error while creating javascript includes using jboss-portlet.xml
I dont' know if this is true or not, but even if I include a css file as said in JBoss portal document, there is no such line show up in the main portal. By the way, the url for my portal is
http://localhost:8080/portal
Any ideas?
thanks,
TL -
8. Re: where should i include my javascript file?
saigon_man Aug 2, 2007 6:08 PM (in response to saigon_man)I found the problems
1. there should be no line
<?xml version="1.0" standalone="yes"?> as specified in jboss reference document
2. I mistyped the jboss-portlet.xml name. Kinda silly action made by me )-- -
9. Re: where should i include my javascript file?
tufla Aug 3, 2007 10:41 AM (in response to saigon_man)I'm using Jboss Portal 2.6 and this is my jboss-portlet.xml file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE portlet-app PUBLIC "-//JBoss Portal//DTD JBoss Portlet 2.6//EN" "http://www.jboss.org/portal/dtd/jboss-portlet_2_6.dtd"> <portlet-app> <portlet> <portlet-name>MyPortlet</portlet-name> <header-content> <script type="text/javascript" src="/js/myfile.js"></script> </header-content> </portlet> </portlet-app>
-
10. Re: where should i include my javascript file?
dickinson Feb 25, 2008 7:34 AM (in response to saigon_man)Hello, this method works well but with one problem. I have 2 Portlets, both use a different JavaScript file. When I instanciate the Portlets, only the first is to able to works with JavaScript. The second Portlet can not view the JavaScript functions. If I change the order in the Portal view, now the second is the first and this works well, and the first is the second and this do not works well.
What is the problem?. -
11. Re: where should i include my javascript file?
natoine Nov 3, 2008 3:42 AM (in response to saigon_man)well i'm tryning to insert javascript and i have this error :
<html><head><title>JBossWeb/2.0.1.GA - Rapport d'erreur</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>Etat HTTP 404 - /WEB-INF/jsp/tiny_mce/tiny_mce.js</h1><HR size="1" noshade="noshade"><p><b>type</b> Rapport d'état</p><p><b>message</b> <u>/WEB-INF/jsp/tiny_mce/tiny_mce.js</u></p><p><b>description</b> <u>La ressource demandée (/WEB-INF/jsp/tiny_mce/tiny_mce.js) n'est pas disponible.</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.1.GA</h3></body></html>
And I have added these lines into my jboss-portlet.xml :<header-content> <script type="text/javascript" src="/WEB-INF/jsp/tiny_mce/tiny_mce.js"></script> </header-content>