Foren

Redefine a javaScript file

thumbnail
hamza jemai, geändert vor 11 Jahren.

Redefine a javaScript file

Junior Member Beiträge: 40 Beitrittsdatum: 04.12.12 Neueste Beiträge
I want to redefine a javascript file in my liferay project, i'm using a jar thats contains this file but i want to add same modification to this file so how can i do it ? Thanks
Riggy D, geändert vor 11 Jahren.

RE: Redefine a javaScript file

New Member Beiträge: 2 Beitrittsdatum: 02.04.13 Neueste Beiträge
At least to my knowledge you have to extract the contents of the jar file, do you modifications, and jar the file again.

Also check out http://stackoverflow.com/questions/1224817/modifying-a-file-inside-a-jar for different suggestions and comments. emoticon
thumbnail
hamza jemai, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Junior Member Beiträge: 40 Beitrittsdatum: 04.12.12 Neueste Beiträge
I will explain, in my example i'am using the Mindmap from Primefaces, and i want to change the position of node, i successfully get the javascript file for displaying
component and i keep him in my /js folder and of course in liferay-portlet.xml "<header-portal-javascript>/js/mindmapJS.js</header-portal-javascript>" but when i run my portlet i have this in the consol :
WARN [http-localhost-127.0.0.1-8080-6][404_jsp:101] /js/mindmapJS.js
Thanks
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
I might be able to provide some help, but when you get a chance, I need to confirm something first. Can you please confirm that mindmapJS.js is contained inside of primefaces.jar and that it is automatically added to the <head>...</head> section of the portal page automatically when you use the p:mindMap component in your XHTML view?
thumbnail
hamza jemai, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Junior Member Beiträge: 40 Beitrittsdatum: 04.12.12 Neueste Beiträge
Thanks Neil,
- in the jar i have mindmap.js i just rename it.
- i have declared the file in my XHTML :
<h:head>
<script type="text/javascript" src="/js/mindmapJS.js"></script>
</h:head>
thumbnail
Juan Gonzalez, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Hamza,

How did you rename the js? Did you copied the js outside the jar file?

BTW, for resources guess you have to declare it this way:

<h:outputScript ... />

instead of using <script>
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Hamza,

Juan is right -- it is a good idea to use h:outputScript if possible.

One concern I have, is that your current approach of <h:head><script ... /></h:head> doesn't address the problem of having two copies of mindMap.js being downloaded: 1) from the primefaces.jar file and 2) your customized one.

When you get a chance, can you verify my concern? If there are two on the page, then I can recommend a way to use a JSF2 ResourceHandler to fix that.

Neil
thumbnail
hamza jemai, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Junior Member Beiträge: 40 Beitrittsdatum: 04.12.12 Neueste Beiträge
Hi Juan , hi Neil
I tried your approch and i keep this in my xhtml file : <h:outputScript library="js" name="mindmap.js" target="head" />
and i have this error :
ERROR [MissingResourceImpl:112] Resource handler=[com.liferay.faces.bridge.application.ResourceHandlerOuterImpl@59a7f372] was unable to create a resource for resourceName=[mindmap.js] libraryName=[js] contentType=[null]
ERROR [BaseURLEncodedStringImpl:57] URL path must start with a '/' or include '://'
java.lang.IllegalArgumentException: URL path must start with a '/' or include '://'


Thanks a lot
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Hamza,

When you get a chance, please revert back to your <h:head><script ...></script></h:head> solution and let me know if you see the mindMap.js file appearing twice in the <head>...</head> section of the portal page.

Thanks,

Neil
thumbnail
Juan Gonzalez, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Can you post what's your resources tree inside your project?

By convention, you should have a js folder inside a "resources" folder.
thumbnail
hamza jemai, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Junior Member Beiträge: 40 Beitrittsdatum: 04.12.12 Neueste Beiträge
HI Neil, sorry but it's not appear
Hi Juan, i attache a picture to explain the tree project
thumbnail
Juan Gonzalez, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Can you try moving mimdmap.js to webapp/resources/js ?

Remember that your file is mindmap.js NOT mindmapJS.js when adding <h:outputScript ../>
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Hamza,

I just looked at the source code for org.primefaces.component.mindmap.MindMap and saw this:

@ResourceDependency(library="primefaces", name="mindmap/mindmap.js")


So if you have the <p:mindMap ... /> component tag in your XHTML view, then the mindmap.js resource should automatically be included in the <head>...</head> section of the portal page.

Neil
thumbnail
Juan Gonzalez, geändert vor 11 Jahren.

RE: Redefine a javaScript file

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Neil Griffin:
Hi Hamza,

I just looked at the source code for org.primefaces.component.mindmap.MindMap and saw this:

@ResourceDependency(library="primefaces", name="mindmap/mindmap.js")


So if you have the <p:mindMap ... /> component tag in your XHTML view, then the mindmap.js resource should automatically be included in the <head>...</head> section of the portal page.

Neil


Seems that's the best option.

Good catch! :-)