Integrating Bootstrap 3.3.7 navbar and Primefaces 6.1

UI Components for JSF
jmg
Posts: 15
Joined: 21 Nov 2017, 12:11

21 Nov 2017, 16:21

Hello all!
I have been working with JSF-Primefaces for a while but I also like the Bootstrap framework, specifically the bootstrap navigation bar. I'm trying to integrate both frameworks in order to use the typical nav-bar from bootstrap and use the Primefaces components in the rest of the page with the help of Grid CSS.
First thing I did was to search over the internet and I found many tutorials such as this one: http://blog.hatemalimam.com/jsf-and-twi ... tegration/
In order to implement it I altered my JSF main template like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
    </h:head>
    <h:body>
    	<link href="#{request.contextPath}/css/bootstrap.css" rel="stylesheet" type="text/css"/>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript" /> 
    	<script src="#{request.contextPath}/js/bootstrap.js" type="text/javascript" />
    		
        <ui:insert name="head">HEAD NOT FOUND</ui:insert>
        
        <ui:insert name="body">BODY NOT FOUND</ui:insert>
       
        <ui:insert name="foot">FOOT NOT FOUND</ui:insert>
    </h:body>
</html>

And added the following typical nav bar on the HEAD page:

Code: Select all

<div class="container">
	<nav class="navbar navbar-default navbar-fixed-top">
		<div class="container-fluid">
			<div class="nav-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-1">
					<span class="sr-only">Menu</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a href="#" class="navbar-brand"><i class="fa fa-book fa-lg"></i> The TEST</a>
			</div>
			
			<div class="collapse navbar-collapse" id="navbar-1">
				<ul class="nav navbar-nav navbar-right">
					<li class="active"><a href="">Start</a></li>
					<li><a href="">Content</a></li>
					<li><a href="">Content</a></li>
					<li><a href="">Contact</a></li>	
				</ul>
			</div>
		</div>
	</nav>
</div>	

Initially everything seemed to work fine: the bootstrap menubar rendered/worked and some primeface components also rendered... but after adding the following VERY SIMPLE selectOneMenu:

Code: Select all

<p:selectOneMenu id="console" value="#{indexBB.test}" >
	<f:selectItem itemLabel="Select One" itemValue="" />
	<f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
	<f:selectItem itemLabel="PS4" itemValue="PS4" />
	<f:selectItem itemLabel="Wii U" itemValue="Wii U" />
</p:selectOneMenu>

I was aware that something was wrong... The selectOneMenu arrow wasn't correctly positioned and the popup with the options didn't appear when clicking the arrow...

Image

As most of you already know Primefaces and Bootstrap use Jquery, so I supposed that the main problem was that Primefaces Jquery version and the Jquery version I included conflicted.
I tried the same above configuration but changing the Jquery version in order to match the Primefaces Jquery version. I tried with 1.11.3 (AFAIK the old version used by Primefaces), 2.2.4(the new one for Primeface 6.1.1 as stated here https://www.primefaces.org/primefaces-6-1-1-released/ ) and 3.2.1
None of them seems to work with a simple selectOneMenu...

I also tried adding the Bootstrap via CDN (<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"></link>) WITHOUT ADDING Jquery and the selectOneMenu WORKED, but the arrow still didn't draw correctly...

Image

Such test made me aware that I have 2 problems:
  • Jquery conflict
  • CSS problem drawing the selectOneMenu
Of course I could ignore the Jquery problem if I use primefaces in the same page as Bootstrap(in such case Bootstrap would use the Primefaces Jquery version) but I still have the wrong render problem with the selectOneMenu arrow.

Can someone tell me:
  • How correct/avoid the selectOneMenu arrow CSS problem?
PLEASE, BE AWARE THAT I know of the existence of Primefaces Grid CSS (https://www.primefaces.org/showcase/ui/panel/grid.xhtml), Bootstrap Theme (https://www.primefaces.org/twitter-bootstrap-theme/) and Primefaces MenuBar.
I'm interested in the aproach described in this thread, but any help to implement a menubar similar to the bootstrap one with Primefaces native components is welcome... (specifically the small button that appears in small resolutions).


Thanks a lot in advance!
I work with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1 and Tomcat 7.0.53.
I usually use Maven, Spring 3.2.3 and Hibernate 4.3 (MySQL 5.1.39)

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

21 Nov 2017, 21:26

PrimeFaces 6.1 = Jquery 1.12.4

PrimFaces 6.1.1+ = JQuery 2.2.4
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

jmg
Posts: 15
Joined: 21 Nov 2017, 12:11

21 Nov 2017, 23:37

I have changed the Jquery library declaration as follows:

<script src="https://ajax.googleapis.com/ajax/libs/j ... ery.min.js" type="text/javascript" />

And the selectOneMenu is still freezed...

If Melloware is right and Primefaces 6.1 uses Jquery 1.12.4, why does not work?

Thanks
I work with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1 and Tomcat 7.0.53.
I usually use Maven, Spring 3.2.3 and Hibernate 4.3 (MySQL 5.1.39)

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

22 Nov 2017, 14:26

Hmmm could be an issue with JQuery UI version as well?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

jmg
Posts: 15
Joined: 21 Nov 2017, 12:11

22 Nov 2017, 14:44

If you are right how could I make both frameworks work at the same time?
Maybe downgrading the Bootstrap version to a prior version in order to match both Jquery UI version?
Which is the Jquery UI version of Primefaces 6.1?
Thanks for your help!
I work with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1 and Tomcat 7.0.53.
I usually use Maven, Spring 3.2.3 and Hibernate 4.3 (MySQL 5.1.39)

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

22 Nov 2017, 14:45

I forgot what 6.1 has but I know 6.1.1 just upgrade to the latest JQueryUI which is 1.12.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

jmg
Posts: 15
Joined: 21 Nov 2017, 12:11

22 Nov 2017, 17:28

Ok, I have been trying some versions and none of the 3.X.X works (I just included the CDN of such versions and the popup worked but the component is wrongly rendered), BUT the Bootstrap 2.3.2 version seems to work fine (the selectOneMenu popup works and it is correctly rendered).
The only problem is that the Bootstrap navbar doesn't render nor works correctly with the 3.X.X sintax (I suppose that Bootstrap sintax changed from 2.X.X to 3.X.X).
I'm a bit confused with this topic because I'm not an expert with these libraries, may someone tell me how to avoid such library conflict?
Thanks!
I work with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1 and Tomcat 7.0.53.
I usually use Maven, Spring 3.2.3 and Hibernate 4.3 (MySQL 5.1.39)

jmg
Posts: 15
Joined: 21 Nov 2017, 12:11

22 Nov 2017, 19:25

I have downloaded and added to my project ONLY the Bootstrap 3.3.7 CSS file (<link href="#{request.contextPath}/css/bootstrap.css" rel="stylesheet" type="text/css"/>). The selectOneMenu works but the aspect is the same as in the above pictures so, as there isn't ANY extra Jquery UI library being loaded (except for the primefaces one), I think this is a CSS issue.
Can someone give me a hand with this? My CSS level is not the best to deal with such complex issue...
Thanks a lot in advance.
I work with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1 and Tomcat 7.0.53.
I usually use Maven, Spring 3.2.3 and Hibernate 4.3 (MySQL 5.1.39)

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

22 Nov 2017, 21:01

You might have to make your site publicly available so someone here can debug it by inspecting it in Chrome.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

jmg
Posts: 15
Joined: 21 Nov 2017, 12:11

22 Nov 2017, 21:46

I don't have any public hosting, I'm deploying it in a local Tomcat.
It is just a test project, so I don't have any problem sharing the code with whoever wants to help...
In any case, it is just a Primefaces project with a selectOneMenu and the Bootstrap library, it can be replicated in 1 minute.
Tell me how can I make it available to you.
Thanks
I work with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1 and Tomcat 7.0.53.
I usually use Maven, Spring 3.2.3 and Hibernate 4.3 (MySQL 5.1.39)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 31 guests