1

I have a problem with a JSF Web Java project using Bootsfaces: the default library loads three files from the internet while I disconnected form internet

  • datatables.min.css
  • font-awesome.min.css
  • datatables.min.js

When the project is offline, it gives problems when loading the page for not finding these files. I already downloaded and put the dependencies on the pages that requires them although it still give problems when is offline to reason of been looking that files. BootsFaces is a JAR so it is unlikely that you can look up the call of those files. Is there any chance to eliminate the load of files at run time? In addition, it is even better for me to load the local files due to in slow connectivity moments it can slow down the site loading. This is a code fragment of the parent template:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:b="http://bootsfaces.net/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:head>
<link rel="shortcut icon" type="image/x-icon" href="#{templateBean.request}/assets/admin/img/favicon.png"/>
        <link rel="stylesheet" href="#{templateBean.request}/assets/admin/css/datatable/datatables.min.css"/>
        <link rel="stylesheet" href="#{templateBean.request}/assets/admin/css/font-awesome/font-awesome.min.css"/>

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="#{templateBean.request}/assets/admin/css/bootstrap.min.css"/>

After a recommendation to download the files with problems and use them locally with , and to have downloaded the latest version of bootsfaces (1.4.1) it was possible to reduce the problems to only 1 error: datatables.js.

At the beginning of the parent template I added these lines:

<h:outputStylesheet library="css" name="datatables.min.css"/>
<h:outputStylesheet library="css" name="font-awesome.min.css"/>
<h:outputScript library="js" name="datatables.min.js"/>

screenchot for files structure screenshot for the error during load page

In the image you can see how it is loading the local file but still looking for the internet and the load of the page is 19s.

  • I just saw that you include the files with a simple HTML link. BootsFaces can't detect these links. Please use and instead. – Stephan Rauh Feb 06 '19 at 19:59

2 Answers2

1

Just bundle a copy of the files with your *.war file. If BootsFaces detects something like "datatables.css", "datatables.js", "font-awesome" or "*fontawesome" in the resources, it's happy with the local version and stops downloading these files from the internet.

Please update to BootsFaces 1.2.0+ (if you haven't do so already). Some of the earlier version had a bug, making them always download the datatables library.

There's much more information on the topic in our showcase: Dealing with resource files

Update: I just saw that you include the files with a simple HTML link. BootsFaces can't detect these links. Please use <h:outputStylesheet> and <h:outputScript> instead.

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
  • I did what you recommended to me to use and . I downloaded the files that Bootsfaces tries to download from the internet, so I managed to see font-awesome, but datatables.css and datatables.js I could not recognize them. I also tried to update the bootsfaces version (I was using version 1.2), updated to version 1.4 and there are no problems with datatables.css. But it still does not find datatables.js. When I tell you that you can not find it, you keep looking for it on the internet even though you find it local. – Gabriel Alberto Pérez Guerra Feb 06 '19 at 20:55
  • Time for plan b. Please debug the method `AddResourcesListener.addDatatablesResourceIfNecessary`. That's where BootsFaces detects whether it needs to download the DataTables.net files from the internet. You should be able to find the error quickly. – Stephan Rauh Feb 07 '19 at 19:36
  • If everything else fails, there's a switch you can activate in the `web.xml`. It's a context parameter called `net.bootsfaces.get_datatable_from_cdn`. Setting it to "true" stops BootsFaces from loading the file from the internet. The article I've pointed to above describes this in depth. – Stephan Rauh Feb 07 '19 at 19:40
  • Another problem might be the spelling. [This line](https://github.com/TheCoder4eu/BootsFaces-OSP/blob/e21c0d7022f99a64c4262fc8e0de02cb7e6103a6/src/main/java/net/bootsfaces/listeners/AddResourcesListener.java#L727) accidentially requires a capital "T" in the file name "dataTables.js". In most cases, this shouldn't make any difference, but it's a potential source of trouble. – Stephan Rauh Feb 07 '19 at 19:44
  • 1
    Thanks to [Stephan Rauh](https://stackoverflow.com/users/3466464/stephan-rauh) for the contribution. The solution you gave me worked perfectly. – Gabriel Alberto Pérez Guerra Feb 19 '19 at 16:32
0

Thanks to Stephan Rauh for the contribution. The solution you gave me worked perfectly. The solution is to modify the web.xml file and add these lines. You have to download and include the files that you try to download from the internet anyway.

<context-param>
        <param-name>net.bootsfaces.get_datatable_from_cdn</param-name>
        <param-value>true</param-value>
</context-param>