BootsFaces-OSP: DataTable onSelect works but generates javascript "network error"
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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 19 (5 by maintainers)
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
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?
@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.
That being said, I think there’s still a bug:
pdfmake.min.jsis still loaded from the CDN.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: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 inC.javayou getpublic 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 😃