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

DataTable onSelect works but generates javascript "network error" #1164

Closed
jscrump59 opened this issue Feb 2, 2021 · 19 comments
Closed

DataTable onSelect works but generates javascript "network error" #1164

jscrump59 opened this issue Feb 2, 2021 · 19 comments

Comments

@jscrump59
Copy link

jscrump59 commented Feb 2, 2021

The datatable does execute onselect="ajax:mainfeed.onSelect(feed,typeOfSelection,indexes) and works properly, but it immediately displays a "network error" dialog three times.

I switched from Developer mode to Production which clears up the problem, but inspecting the table lists several errors concerning "Reason: missing token ‘xyz’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel". It's defined at https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowHeaderFromPreflight .

This is an example of one of the errors:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sl-1.3.1/datatables.min.js. (Reason: header ‘content-type’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

This is different type of error.

XML Parsing Error: not well-formed
Location: http://localhost:8080/chronicle/pages/javax.faces.resource/jq/ui/i18n/dt/datatable-en.json?ln=bsf
Line Number 1, Column 1: datatable-en.json:1:1

{
	"sEmptyTable":     "No data available in table",
	"sInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",
	"sInfoEmpty":      "Showing 0 to 0 of 0 entries",
	"sInfoFiltered":   "(filtered from _MAX_ total entries)",
	"sInfoPostFix":    "",
	"sInfoThousands":  ",",
	"sLengthMenu":     "Show _MENU_ entries",
	"sLoadingRecords": "Loading...",
	"sProcessing":     "Processing...",
	"sSearch":         "Search:",
	"sZeroRecords":    "No matching records found",
	"oPaginate": {
		"sFirst":    "First",
		"sLast":     "Last",
		"sNext":     "Next",
		"sPrevious": "Previous"
	},
	"oAria": {
		"sSortAscending":  ": activate to sort column ascending",
		"sSortDescending": ": activate to sort column descending"
	}
}

Can you see what I might be doing wrong?

Thanks

@macbl
Copy link

macbl commented Feb 8, 2021

I've got a similar problem on Tomee Webprofile & Micropofile (MyFaces) - Tomee PLUME with Mojarra however works. As fare as I unserstand it only occurs on AJAX request (datatable select). The AJAX request somehow includes the
Access-Control-Allow-Origin: https://localhost:8443 which prevets accessing the other datatables scripts.

I also played with the CORS filter settings, no luck with that. Any Idea how to make datatables select working?

(I can confirm that Datatables selection works in production mode:

 <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>

@jscrump59
Copy link
Author

jscrump59 commented Feb 8, 2021 via email

@macbl
Copy link

macbl commented Feb 9, 2021

Turing on production mode in web.xml basically seems to supress the javascript warnings, when looking into the browser console you can see, that the CORS errors are still there. I can confirm that no errors exist on TOMEE PLUME 8.0.6 which is using Mojarra as JSF implementation. So the problem might might have something to do with the MyFaces configuration?

@jscrump59
Copy link
Author

jscrump59 commented Feb 9, 2021 via email

@macbl
Copy link

macbl commented Feb 12, 2021

This is getting really paniful. I realize that selection is not properly working - not even in Production mode. Isn't there any way to fix the root cause of this problem? Any MyFaces experts here? My application makes heavy use of table selections, but most table selection AJAX calls are not working any more..

jsf.js?ln=javax.faces:1 Access to XMLHttpRequest at 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js' from origin 'https://localhost:8443' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
loadScriptEval @ jsf.js?ln=javax.faces:1
B @ jsf.js?ln=javax.faces:1
runScripts @ jsf.js?ln=javax.faces:1
_eval @ jsf.js?ln=javax.faces:1
insertAfter @ jsf.js?ln=javax.faces:1
_addResourceToHead @ jsf.js?ln=javax.faces:1
processUpdate @ jsf.js?ln=javax.faces:1
processChanges @ jsf.js?ln=javax.faces:1
processResponse @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
onsuccess @ jsf.js?ln=javax.faces:1
(anonym) @ jsf.js?ln=javax.faces:1
load (asynchron)
mixMaps @ jsf.js?ln=javax.faces:1
send @ jsf.js?ln=javax.faces:1
enqueue @ jsf.js?ln=javax.faces:1
xhrQueuedPost @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
BsF.ajax.callAjax @ bsf.js?ln=bsf:24
(anonym) @ adminAsset.xhtml:26
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
(anonym) @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
m @ datatables.min.js:699
(anonym) @ datatables.min.js:711
iterator @ datatables.min.js:140
(anonym) @ datatables.min.js:711
(anonym) @ datatables.min.js:144
(anonym) @ datatables.min.js:143
w @ datatables.min.js:704
(anonym) @ datatables.min.js:698
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
jsf.js?ln=javax.faces:1 GET https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js net::ERR_FAILED
loadScriptEval @ jsf.js?ln=javax.faces:1
B @ jsf.js?ln=javax.faces:1
runScripts @ jsf.js?ln=javax.faces:1
_eval @ jsf.js?ln=javax.faces:1
insertAfter @ jsf.js?ln=javax.faces:1
_addResourceToHead @ jsf.js?ln=javax.faces:1
processUpdate @ jsf.js?ln=javax.faces:1
processChanges @ jsf.js?ln=javax.faces:1
processResponse @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
onsuccess @ jsf.js?ln=javax.faces:1
(anonym) @ jsf.js?ln=javax.faces:1
load (asynchron)
mixMaps @ jsf.js?ln=javax.faces:1
send @ jsf.js?ln=javax.faces:1
enqueue @ jsf.js?ln=javax.faces:1
xhrQueuedPost @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
BsF.ajax.callAjax @ bsf.js?ln=bsf:24
(anonym) @ adminAsset.xhtml:26
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
(anonym) @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
m @ datatables.min.js:699
(anonym) @ datatables.min.js:711
iterator @ datatables.min.js:140
(anonym) @ datatables.min.js:711
(anonym) @ datatables.min.js:144
(anonym) @ datatables.min.js:143
w @ datatables.min.js:704
(anonym) @ datatables.min.js:698
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
jsf.js?ln=javax.faces:1 Access to XMLHttpRequest at 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js' from origin 'https://localhost:8443' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
loadScriptEval @ jsf.js?ln=javax.faces:1
B @ jsf.js?ln=javax.faces:1
runScripts @ jsf.js?ln=javax.faces:1
_eval @ jsf.js?ln=javax.faces:1
insertAfter @ jsf.js?ln=javax.faces:1
_addResourceToHead @ jsf.js?ln=javax.faces:1
processUpdate @ jsf.js?ln=javax.faces:1
processChanges @ jsf.js?ln=javax.faces:1
processResponse @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
onsuccess @ jsf.js?ln=javax.faces:1
(anonym) @ jsf.js?ln=javax.faces:1
load (asynchron)
mixMaps @ jsf.js?ln=javax.faces:1
send @ jsf.js?ln=javax.faces:1
enqueue @ jsf.js?ln=javax.faces:1
xhrQueuedPost @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
BsF.ajax.callAjax @ bsf.js?ln=bsf:24
(anonym) @ adminAsset.xhtml:26
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
(anonym) @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
m @ datatables.min.js:699
(anonym) @ datatables.min.js:711
iterator @ datatables.min.js:140
(anonym) @ datatables.min.js:711
(anonym) @ datatables.min.js:144
(anonym) @ datatables.min.js:143
w @ datatables.min.js:704
(anonym) @ datatables.min.js:698
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
jsf.js?ln=javax.faces:1 GET https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js net::ERR_FAILED
loadScriptEval @ jsf.js?ln=javax.faces:1
B @ jsf.js?ln=javax.faces:1
runScripts @ jsf.js?ln=javax.faces:1
_eval @ jsf.js?ln=javax.faces:1
insertAfter @ jsf.js?ln=javax.faces:1
_addResourceToHead @ jsf.js?ln=javax.faces:1
processUpdate @ jsf.js?ln=javax.faces:1
processChanges @ jsf.js?ln=javax.faces:1
processResponse @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
onsuccess @ jsf.js?ln=javax.faces:1
(anonym) @ jsf.js?ln=javax.faces:1
load (asynchron)
mixMaps @ jsf.js?ln=javax.faces:1
send @ jsf.js?ln=javax.faces:1
enqueue @ jsf.js?ln=javax.faces:1
xhrQueuedPost @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
BsF.ajax.callAjax @ bsf.js?ln=bsf:24
(anonym) @ adminAsset.xhtml:26
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
(anonym) @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
m @ datatables.min.js:699
(anonym) @ datatables.min.js:711
iterator @ datatables.min.js:140
(anonym) @ datatables.min.js:711
(anonym) @ datatables.min.js:144
(anonym) @ datatables.min.js:143
w @ datatables.min.js:704
(anonym) @ datatables.min.js:698
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
jsf.js?ln=javax.faces:1 Access to XMLHttpRequest at 'https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sl-1.3.1/datatables.min.js' from origin 'https://localhost:8443' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
loadScriptEval @ jsf.js?ln=javax.faces:1
B @ jsf.js?ln=javax.faces:1
runScripts @ jsf.js?ln=javax.faces:1
_eval @ jsf.js?ln=javax.faces:1
insertAfter @ jsf.js?ln=javax.faces:1
_addResourceToHead @ jsf.js?ln=javax.faces:1
processUpdate @ jsf.js?ln=javax.faces:1
processChanges @ jsf.js?ln=javax.faces:1
processResponse @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
response @ jsf.js?ln=javax.faces:1
onsuccess @ jsf.js?ln=javax.faces:1
(anonym) @ jsf.js?ln=javax.faces:1
load (asynchron)
mixMaps @ jsf.js?ln=javax.faces:1
send @ jsf.js?ln=javax.faces:1
enqueue @ jsf.js?ln=javax.faces:1
xhrQueuedPost @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
request @ jsf.js?ln=javax.faces:1
BsF.ajax.callAjax @ bsf.js?ln=bsf:24
(anonym) @ adminAsset.xhtml:26
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
(anonym) @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
each @ jquery.js?ln=bsf:2
trigger @ jquery.js?ln=bsf:2
m @ datatables.min.js:699
(anonym) @ datatables.min.js:711
iterator @ datatables.min.js:140
(anonym) @ datatables.min.js:711
(anonym) @ datatables.min.js:144
(anonym) @ datatables.min.js:143
w @ datatables.min.js:704
(anonym) @ datatables.min.js:698
dispatch @ jquery.js?ln=bsf:2
v.handle @ jquery.js?ln=bsf:2
jsf.js?ln=javax.faces:1 GET https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sl-1.3.1/datatables.min.js net::ERR_FAILED

@macbl
Copy link

macbl commented Feb 13, 2021

New tests with a almost blank project proove that there seems to be a major problem between Bootsfaces, datable an MyFaces. Actually any b:datatable insinde a page will kill all ajax calls even when performed outside the table. This is true, even when the table in not set to select mode. For whatever reason even ajax calls in commandLinks outside the table fire requests to https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js. and https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sl-1.3.1/datatables.min.js.
Is nobody else experiencing problems with this?

@macbl
Copy link

macbl commented Feb 14, 2021

I have given up - Datatables in Bootsfaces are currently incompatible with MyFaces. I had to return to TomEE PLUME to keep my application running.

@kvj2020
Copy link

kvj2020 commented Mar 2, 2021

I have had the same experience - CORS errors and javascript network error messages. I use a few BootsFaces datatables and lots of ajax. I could not resolve these issues while using MyFaces in Tomee 8.0.5 and BootsFaces 1.5.0. I solved the issue by removing the apache MyFaces implementation and adding the Oracle Mojarra 2.3 implementation. This is not a great solution but I am past the issue.

@jscrump59
Copy link
Author

jscrump59 commented Mar 2, 2021 via email

@exabrial
Copy link
Contributor

exabrial commented Mar 3, 2021

Would a possible patch would be to load these Javascript files as resources rather than from a CDN?

@exabrial
Copy link
Contributor

exabrial commented Mar 4, 2021

So I took a look at this. Let me explain my debug process and maybe this will help people solve their own issues too :)

First, I forked the project and checked everything out. I launched Safari Inspector and loaded the page and noted the name of the scripts that were causing problems. I then cd'd into the bootsfaces dir and executed a grep -ri "datatables.min.js" . and found this reference:

./src/main/java/net/bootsfaces/component/dataTable/DataTable.java:		AddResourcesListener.addDatatablesResourceIfNecessary("https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-html5-1.5.4/b-print-1.5.4/fc-3.2.5/fh-3.1.4/r-2.2.2/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.min.js", "js");

Pulling up that source file it calls AddResourcesListener.addDatatablesResourceIfNecessary, which then has a branch for the following: boolean loadDatatables = shouldLibraryBeLoaded(P_GET_DATATABLE_FROM_CDN, true);. So there's actually already a workaround built into the framework! Looking up that constant in C.java you get public static final String P_GET_DATATABLE_FROM_CDN = "net.bootsfaces.get_datatable_from_cdn";. I set that to false in my web.xml and my problem was solved :)

@exabrial
Copy link
Contributor

exabrial commented Mar 4, 2021

That being said, I think there's still a bug: pdfmake.min.js is still loaded from the CDN.

	public DataTable() {
		setRendererType(DEFAULT_RENDERER);
		Tooltip.addResourceFiles();
		AddResourcesListener.addThemedCSSResource("core.css");
		// DataTables with almost all extensions except Flash export and KeyTable - version of 10.11.2019
		AddResourcesListener.addDatatablesResourceIfNecessary("https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sl-1.3.1/datatables.min.css", "css");
		AddResourcesListener.addDatatablesResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js", "css");
		AddResourcesListener.addDatatablesResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js", "css");
		AddResourcesListener.addDatatablesResourceIfNecessary("https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sl-1.3.1/datatables.min.js", "js");
	}
The pdfmake javascript dependencies are listed as `css` not `js` like the others. Flipping it to JS still gives me an error, so I'm looking into this using the same technique.

@jscrump59
Copy link
Author

jscrump59 commented Mar 4, 2021 via email

@exabrial
Copy link
Contributor

exabrial commented Mar 4, 2021

So I did find one additional bug:

	private static boolean shouldLibraryBeLoaded(final String initParameter, final boolean defaultValue) {
		final String suppressLibrary = BsfUtils.getInitParam(initParameter);
		if (suppressLibrary == null) {
			return defaultValue;
		}
		return !isTrueOrYes(ELTools.evalAsString(suppressLibrary));
	}

this: !isTrueOrYes(ELTools.evalAsString(suppressLibrary)); should probably be isTrueOrYes(ELTools.evalAsString(suppressLibrary));

Note that if you set net.bootsfaces.get_datatable_from_cdn = false in the web.xml, it looks like you do have to provide your own copy. Datatables.net is MIT Licensed, so it possibly could be distributed with Bootsfaces.

@stephanrauh
Copy link
Collaborator

Phew! All that sounds like a nasty bug. By the look of it, it's a combination of a bug - you're right, @exabrial, the two JavaScript resources should not be loaded as CSS files - and the increasing security awareness of the browsers.

I suggest dropping CDN support entirely. I'm not sure why CORS is a problem all of a sudden, but it's not unexpected. I suppose no CDN can legally add the CORS headers, so let's simply solve the problem by bundling the files with the library. That makes a lot of things easier, anyways.

In the meantime you can bundle the files with your application, as @exabrial describes. There's even some documentation here: https://showcase.bootsfaces.net/layout/resourcemanagement.jsf (but I agree it's not a masterpiece of documentation, I was always unhappy with it).

@stephanrauh
Copy link
Collaborator

@exabrial More likely than not, this method is not buggy. It's just very confusing. Maybe this can be solved by renaming it. On the other hand, if you follow my suggestion and remove CDN support in favor of bundling Datatables.net with the library, you're going to remove the method, anyways.

@stephanrauh
Copy link
Collaborator

@exabrial When you prepare the pull request, can you prepare an individual pull request per ticket, please? I know this is cumbersome - it requires maintaining different branches. But it's a lot easier to understand what's going on if there's only the minimum set of modifications.

exabrial added a commit to exabrial/BootsFaces-OSP that referenced this issue Mar 5, 2021
…nerates javascript 'network error'. Remove CDN option for datatable script files
@exabrial
Copy link
Contributor

exabrial commented Mar 5, 2021

Yeah, so I can't get this to work with the CDN properly. I feel like that really isn't the job of the framework anyway. For instance cloudflare will automatically put your css/js on CDN with no work from the dev, so having that be part of the UI Lib is a bit of a stretch.

The PR I submitted serves the data-table support files up locally and removes the CDN option. This seems to work just fine. Can people on this thread test and give some feedback?

@stephanrauh
Copy link
Collaborator

I've merged your PR and uploaded it to Maven Central as snapshot 1.6.0. See issue #369 on how to get it.

Thanks a lot!
Stephan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants