Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrimeFaces, BootsFaces and JQuery: resource ordering #640

Closed
kaioppermann opened this issue Feb 24, 2017 · 7 comments
Closed

PrimeFaces, BootsFaces and JQuery: resource ordering #640

kaioppermann opened this issue Feb 24, 2017 · 7 comments

Comments

@kaioppermann
Copy link

Hey there,
I have a "HelloWorld" page which uses a PrimeFaces component and some BootsFaces tags for layout.
On the first load the page is ok, no error in console etc.
When I hit a simple h:commandLink in the JS console appears:
Uncaught ReferenceError: jQuery is not defined at tbmDisposition-aendernPF.jsf:3 VM219 jquery-plugins.js.jsf?ln=primefaces&v=6.0:5 Uncaught ReferenceError: jQuery is not defined at VM219 jquery-plugins.js.jsf?ln=primefaces&v=6.0:5 at VM219 jquery-plugins.js.jsf?ln=primefaces&v=6.0:5
The reason is that jquery-plugins is loaded before jquery.
My question is:
Which class is finally responsible for the ordering and is there a chance to influence or reimplement this?

Some version informations:
PrimeFacs: 6.0
JSF: 1.2_15-jbossorg-2 (= JSF 2.1
Server: jboss-as-7.1.2.Final
BootsFaces: 1.0.2
Mojarra 2.1.19

See also: http://stackoverflow.com/questions/42390734/primefaces-and-jquery-resource-ordering

@kaioppermann
Copy link
Author

P.S.: When I drop BootsFaces I don't have this problem.

@kaioppermann
Copy link
Author

kaioppermann commented Feb 24, 2017

In the ResourceFileComparator the JS files will be renamed like

		if (name.contains("jquery-ui"))
			name = "2.js"; // make it the second JS file
		else if (name.contains("jquery"))
			name = "1.js"; // make it the first JS file

But in my case the name for jquery-ui is: "jquery/jquery-plugins.js"
=> Both "jquery/jquery.js" and "jquery/jquery-plugins.js" will be renamed to "1.js"

@kaioppermann
Copy link
Author

kaioppermann commented Feb 24, 2017

Now this code works for me:

	private String renameJSFile(String name) {
		name = name.toLowerCase();
		if (name.contains("jquery.js"))
			name = "1.js"; // make it the first JS file
		else if (name.contains("jquery"))
			name = "2.js"; // make it the second JS file
		else if (name.contains("ui/core.js"))
			name = "3.js"; // make it the third JS file
		else if (name.contains("ui/widget.js"))
			name = "4.js"; // make it the second last JS file
		else if (name.contains("bsf.js"))
			name = "zzz.js"; // make it the last JS file
		else
			name = "keep.js"; // don't move it
		return name;
	}

@kaioppermann
Copy link
Author

Closed by mistake, sorry.

@stephanrauh
Copy link
Collaborator

I've taken a slightly different approach that should be a bit more flexible. If you jquery-plugins.js depends on jquery-ui, please rename it to jquery-ui-plugins.

Hope that works for you!

		if (libname.contains("jquery-ui"))
			name = "2" + libname; // make it the second JS file, while still distinguishing between jquery-ui.js and jquery-ui-plugins.js
		else if (libname.contains("jquery")) {
			name = "1" + libname; // make it the first JS file, while still distinguishing between jquery.js and jquery-plugins.js
		}
		else if (name.contains("ui/core.js"))
			name = "3.js"; // make it the third JS file
		else if (name.contains("ui/widget.js"))
			name = "4.js"; // make it the second last JS file
		else if (name.contains("bsf.js"))
			name = "zzz.js"; // make it the last JS file
		else
			name = "keep.js"; // don't move it

@stephanrauh stephanrauh added this to the v1.1.0 milestone Apr 15, 2017
@stephanrauh stephanrauh moved this from In Progress to DONE in BootsFaces v1.1.0 Apr 15, 2017
@mamar93
Copy link

mamar93 commented Mar 31, 2019

Hello I need Help please, i have the same problem but i don't understand the solution.
where to put this code :
private String renameJSFile(String name) { name = name.toLowerCase(); if (name.contains("jquery.js")) name = "1.js"; // make it the first JS file else if (name.contains("jquery")) name = "2.js"; // make it the second JS file else if (name.contains("ui/core.js")) name = "3.js"; // make it the third JS file else if (name.contains("ui/widget.js")) name = "4.js"; // make it the second last JS file else if (name.contains("bsf.js")) name = "zzz.js"; // make it the last JS file else name = "keep.js"; // don't move it return name; }

@stephanrauh
Copy link
Collaborator

@mamar93 You don't have to do anything, that's our job! :) The code snippet stems from an internal BootsFaces class (AddResourcesListener).

I gather you ran into a problem, so I'd like to invite you to debug this class. Admittedly, it's the most complicated class of BootsFaces, but I believe it's possible to understand what's happening there. At least I hope so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

4 participants