Professional Documents
Culture Documents
TUTORIALS
#INTERVIEW QUESTIONS
JAVA
WEB DESIGN
Download Now
JSF, PrimeFaces
pdfcrowd.com
The major aim of this tutorial is to cover the main menu components that get used with Primefaces
implementation. Typically, a huge amount of applications spread over internet use a different form of menus.
This tutorial will cover the following types of menu:
Menu: Is a navigation component with submenus and menu items.
MenuBar: Is a horizontal navigation component.
MenuButton: Is used to display different commands in a popup menu.
TieredMenu: Is used to display nested submenus with overlays.
SlideMenu: Is used to display nested submenus with sliding animation.
Lets get started explaining all of these menu types to see all of those featured functionalities that Primefaces
provide for this kind of components.
menu
Component Class
org.primefaces.component.menu.Menu
pdfcrowd.com
Component Type
org.primefaces.component.Menu
Component Family
org.primefaces.component
Renderer Type
org.primefaces.component.MenuRenderer
Renderer Class
org.primefaces.component.menu.MenuRenderer
Menu Attributes
Name
Default
Type
Description
id
null
String
rendered
true
Boolean
Boolean value to specify the rendering of the component, when set to false
component will not be rendered.
binding
null
Object
widgetVar
null
String
pdfcrowd.com
model
null
MenuModel
trigger
null
String
my
null
String
at
null
String
overlay
false
Boolean
style
null
String
styleClass
null
String
triggerEvent
click
String
pdfcrowd.com
index.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form>
<p:menu>
<p:submenu label="File">
<p:menuitem value="Open"></p:menuitem>
<p:menuitem value="Edit"></p:menuitem>
<p:separator/>
<p:menuitem value="Exit"></p:menuitem>
</p:submenu>
<p:submenu label="Help">
<p:menuitem value="About Primefaces"></p:menuitem>
<p:menuitem value="Contact Us"></p:menuitem>
<p:separator/>
<p:menuitem value="Help"></p:menuitem>
</p:submenu>
</p:menu>
</h:form>
</html>
pdfcrowd.com
pdfcrowd.com
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form>
<p:menu overlay="true" trigger="triggerButton" my="left top" at="right top"
<p:submenu label="File">
<p:menuitem value="Open"></p:menuitem>
<p:menuitem value="Edit"></p:menuitem>
<p:separator/>
<p:menuitem value="Exit"></p:menuitem>
</p:submenu>
<p:submenu label="Help">
<p:menuitem value="About Primefaces"></p:menuitem>
<p:menuitem value="Contact Us"></p:menuitem>
<p:separator/>
<p:menuitem value="Help"></p:menuitem>
</p:submenu>
</p:menu>
<p:commandButton id="triggerButton" value="Trigger Menu"></p:commandButton
</h:form>
pdfcrowd.com
25
26
</h:form>
</html>
Once Trigger Menu action has activated, your defined menu has been displayed.
pdfcrowd.com
containing menuitems that correspond to required actions that menu aim to provide. Those menuitems are
actually actions likewise p:commandButton, so its also applicable for you to ajaxify them.
index2.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form>
<p:growl id="message"></p:growl>
<p:menu overlay="true" trigger="triggerButton" my="left top" at="right top"
<p:submenu label="File">
<p:menuitem value="Open" action="#{menuManagedBean.openAction}" update
<p:menuitem value="Edit"></p:menuitem>
<p:separator/>
<p:menuitem value="Exit"></p:menuitem>
</p:submenu>
<p:submenu label="Help">
<p:menuitem value="About Primefaces"></p:menuitem>
<p:menuitem value="Contact Us"></p:menuitem>
<p:separator/>
<p:menuitem value="Help"></p:menuitem>
</p:submenu>
</p:menu>
<p:commandButton id="triggerButton" value="Trigger Menu"></p:commandButton
</h:form>
</html>
pdfcrowd.com
MenuManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class MenuManagedBean {
public String openAction(){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Open a
return "";
}
}
pdfcrowd.com
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
pdfcrowd.com
7
8
9
10
11
12
13
14
15
MenuManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
import
import
import
import
import
org.primefaces.model.menu.DefaultMenuItem;
org.primefaces.model.menu.DefaultMenuModel;
org.primefaces.model.menu.DefaultSeparator;
org.primefaces.model.menu.DefaultSubMenu;
org.primefaces.model.menu.MenuModel;
@ManagedBean
@SessionScoped
public class MenuManagedBean {
private MenuModel menu = new DefaultMenuModel();
public MenuManagedBean(){
// Create submenu
DefaultSubMenu file = new DefaultSubMenu("File");
// Create submenu
DefaultSubMenu help = new DefaultSubMenu("Help");
// Create menuitem
pdfcrowd.com
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Create menuitem
DefaultMenuItem open = new DefaultMenuItem("Open");
// Create menuitem
DefaultMenuItem edit = new DefaultMenuItem("Edit");
// Create menuitem
DefaultMenuItem exit = new DefaultMenuItem("Exit");
// Create menuitem
DefaultMenuItem about = new DefaultMenuItem("About Primefaces");
// Create menuitem
DefaultMenuItem contact = new DefaultMenuItem("Contact Us");
// Create menuitem
DefaultMenuItem helpMenuItem = new DefaultMenuItem("Help");
// Determine menuitem action
open.setCommand("#{menuManagedBean.openAction}");
// Associate menuitem with submenu
file.addElement(open);
file.addElement(edit);
file.addElement(new DefaultSeparator());
file.addElement(exit);
help.addElement(about);
help.addElement(contact);
help.addElement(new DefaultSeparator());
help.addElement(helpMenuItem);
pdfcrowd.com
59
60
61
62
63
64
65
66
67
68
69
}
public void setMenu(MenuModel menu) {
this.menu = menu;
}
pdfcrowd.com
Tag
Menubar
Component Class
org.primefaces.component.menubar.Menubar
Component Type
org.primefaces.component.Menubar
Component Family
org.primefaces.component
Renderer Type
org.primefaces.component.MenubarRenderer
Renderer Class
org.primefaces.component.menubar.MenubarRenderer
Menubar Attributes
Name
Default
Type
Description
id
null
String
pdfcrowd.com
rendered
true
Boolean
Boolean value to specify the rendering of the component, when set to false
component will not be rendered.
binding
null
Object
widgetVar
null
String
model
null
MenuModel
style
null
String
styleClass
null
String
autoDisplay
false
Boolean
pdfcrowd.com
pdfcrowd.com
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:menubar>
<p:submenu label="File">
<p:submenu label="Open">
<p:menuitem value="Open Excel File"></p:menuitem>
<p:menuitem value="Open Word File"></p:menuitem>
<p:menuitem value="Open Power Point File"></p:menuitem>
pdfcrowd.com
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
pdfcrowd.com
Menubar has also supported rooted menuitem, that is by providing a direct p:menuitem child component
within p:menubar.
index6.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:menubar>
<p:menuitem value="Open"></p:menuitem>
</p:menubar>
</h:form>
</html>
pdfcrowd.com
Likewise p:commandButton component, p:menuitem has also supported ajaxifying actions. Youve already
experienced this in p:menu section. You can use p:menuitem for doing actions Ajax and Non-Ajax and
navigation as well.
Following sample shows you the different usage of p:menuitem.
index7.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:menubar>
<p:submenu label="File">
<p:submenu label="Open">
<p:menuitem value="Ajax Action" action="#{menubarManagedBean.ajaxAc
<p:menuitem value="Non Ajax Action" action="#{menubarManagedBean.no
<p:menuitem value="Go To JournalDev" url="http://www.journaldev.com
</p:submenu>
<p:menuitem value="Edit"></p:menuitem>
<p:separator/>
<p:menuitem value="Exit"></p:menuitem>
</p:submenu>
<p:submenu label="Help">
<p:menuitem value="About JournalDev"></p:menuitem>
<p:menuitem value="Contact Us"></p:menuitem>
<p:separator/>
<p:menuitem value="Help"></p:menuitem>
pdfcrowd.com
26
27
28
29
30
<p:menuitem value="Help"></p:menuitem>
</p:submenu>
</p:menubar>
</h:form>
</html>
MenubarManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class MenubarManagedBean {
public String ajaxAction(){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Ajax U
return "";
}
pdfcrowd.com
pdfcrowd.com
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:menubar model="#{menubarManagedBean.menubar}">
pdfcrowd.com
11
12
13
14
<p:menubar model="#{menubarManagedBean.menubar}">
</p:menubar>
</h:form>
</html>
MenubarManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
import
import
import
import
import
org.primefaces.model.menu.DefaultMenuItem;
org.primefaces.model.menu.DefaultMenuModel;
org.primefaces.model.menu.DefaultSeparator;
org.primefaces.model.menu.DefaultSubMenu;
org.primefaces.model.menu.MenuModel;
@ManagedBean
@SessionScoped
public class MenubarManagedBean {
private MenuModel menubar = new DefaultMenuModel();
public MenubarManagedBean(){
// Create submenus required
DefaultSubMenu file = new DefaultSubMenu("File");
DefaultSubMenu open = new DefaultSubMenu("Open");
DefaultSubMenu help = new DefaultSubMenu("Help");
pdfcrowd.com
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
open in browser PRO version
pdfcrowd.com
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
this.menubar.addElement(file);
this.menubar.addElement(help);
}
public MenuModel getMenubar() {
return menubar;
}
public void setMenubar(MenuModel menubar) {
this.menubar = menubar;
}
pdfcrowd.com
Tag
menuButton
Component Class
org.primefaces.component.menubutton.MenuButton
Component Type
org.primefaces.component.MenuButton
Component Family
org.primefaces.component
Renderer Type
org.primefaces.component.MenuButtonRenderer
Renderer Class
org.primefaces.component.menubutton.MenuButtonRenderer
MenuButton Attributes
Name
Default
Type
Are you a developer? Try out the HTML to PDF API
Description
pdfcrowd.com
id
null
String
rendered
true
Boolean
Boolean value to specify the rendering of the component, when set to false
component will not be rendered.
binding
null
Object
value
null
String
style
null
String
styleClass
null
String
widgetVar
null
String
model
null
MenuModel
disabled
false
Boolean
iconPos
left
String
appendTo
null
String
pdfcrowd.com
index9.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:menuButton value="MenuButton">
<p:menuitem value="Ajax Action" action="#{menuButtonManagedBean.ajaxAction}
<p:menuitem value="Non Ajax Action" action="#{menuButtonManagedBean.nonAjax
<p:menuitem value="Go To JournalDev" url="http://www.journaldev.com"></
</p:menuButton>
</h:form>
</html>
pdfcrowd.com
MenuButtonManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
import
import
import
import
import
org.primefaces.model.menu.DefaultMenuItem;
org.primefaces.model.menu.DefaultMenuModel;
org.primefaces.model.menu.DefaultSeparator;
org.primefaces.model.menu.DefaultSubMenu;
org.primefaces.model.menu.MenuModel;
@ManagedBean(name="menuButtonManagedBean")
@SessionScoped
public class MenuButtonManagedBean {
private MenuModel menuButton = new DefaultMenuModel();
public MenuButtonManagedBean(){
}
public MenuModel getMenuButton() {
return menuButton;
}
public void setMenuButton(MenuModel menuButton) {
this.menuButton = menuButton;
}
pdfcrowd.com
32
33
34
35
36
37
38
39
pdfcrowd.com
MenuButton can be created programmatically as well. The same example of MenuButton that is provided in
the previous section has actually implemented below using programmatic methodology.
index10.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:menuButton value="MenuButton" model="#{menuButtonManagedBean.menuButton}"
</p:menuButton>
</h:form>
</html>
MenuButtonManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.MenuModel;
@ManagedBean(name="menuButtonManagedBean")
pdfcrowd.com
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@ManagedBean(name="menuButtonManagedBean")
@SessionScoped
public class MenuButtonManagedBean {
private MenuModel menuButton = new DefaultMenuModel();
public MenuButtonManagedBean(){
// Create menuitems required
DefaultMenuItem ajaxAction = new DefaultMenuItem("Ajax Action");
ajaxAction.setUpdate("message");
ajaxAction.setCommand("#{menubarManagedBean.ajaxAction}");
DefaultMenuItem nonAjaxAction = new DefaultMenuItem("Non Ajax Action");
nonAjaxAction.setAjax(false);
nonAjaxAction.setCommand("#{menubarManagedBean.nonAjaxAction}");
DefaultMenuItem urlAction = new DefaultMenuItem("Go To JournalDev");
urlAction.setUrl("http://www.journaldev.com");
this.menuButton.addElement(ajaxAction);
this.menuButton.addElement(nonAjaxAction);
this.menuButton.addElement(urlAction);
}
public MenuModel getMenuButton() {
return menuButton;
}
public void setMenuButton(MenuModel menuButton) {
this.menuButton = menuButton;
}
pdfcrowd.com
47
48
49
50
51
52
53
return "";
Tag
TieredMenu
Component Class
org.primefaces.component.tieredmenu.TieredMenu
Component Type
org.primefaces.component.TieredMenu
Component Family
org.primefaces.component
Renderer Type
org.primefaces.component.TieredMenuRenderer
Renderer Class
org.primefaces.component.tieredmenu.TieredMenuRenderer
TieredMenu Attributes
open in browser PRO version
pdfcrowd.com
Name
Default
Type
Description
id
null
String
rendered
true
Boolean
Boolean value to specify the rendering of the component, when set to false
component will not be rendered.
binding
null
Object
widgetVar
null
String
model
null
MenuModel
style
null
String
styleClass
null
String
autoDisplay
true
Boolean
trigger
null
String
Id of the component whose triggerEvent will show the dynamic positioned menu.
my
null
String
pdfcrowd.com
at
null
String
overlay
false
Boolean
triggerEvent
click
String
Event name of trigger that will show the dynamic positioned menu.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
pdfcrowd.com
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<p:growl id="message"></p:growl>
<p:tieredMenu>
<p:submenu label="Ajax Menuitem">
<p:menuitem value="Ajax Action" action="#{tieredMenuManagedBean.ajaxAct
</p:submenu>
<p:submenu label="Non Ajax Menuitem">
<p:menuitem value="Non Ajax Action" action="#{tieredMenuManagedBean.non
</p:submenu>
<p:separator/>
<p:submenu label="Navigations">
<p:submenu label="Primefaces links">
<p:menuitem value="Prime" url="http://www.prime.com.tr"></p:menuite
<p:menuitem value="Primefaces" url="http://www.primefaces.org"
</p:submenu>
<p:submenu label="Prime Blogs">
<p:menuitem value="JournalDev" url="http://www.journaldev.com"
</p:submenu>
</p:submenu>
</p:tieredMenu>
</h:form>
</html>
TieredMenuManagedBean.java
1
2
3
4
5
6
7
8
9
10
11
12
package com.journaldev.prime.faces.beans;
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class TieredMenuManagedBean {
public String ajaxAction(){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Ajax U
pdfcrowd.com
12
13
14
15
16
17
18
19
TieredMenu AutoDisplay
By default, submenus are displayed when mouse is over root menuitems, set autoDisplay to false require a
click on root menuitems to enable autoDisplay mode.
The same example will be used to set autoDisplay to false against p:tieredMenu component.
pdfcrowd.com
TieredMenu Overlay
Likewise Menu component, TieredMenu can also be overlaid using the same way that is used for overlaying
the Menu component (See Menu Overlay).
index11.xhtml
1
2
3
4
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
pdfcrowd.com
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:tieredMenu autoDisplay="false" trigger="triggerBtn" overlay="true" my="left
<p:submenu label="Ajax Menuitem">
<p:menuitem value="Ajax Action" action="#{tieredMenuManagedBean.ajaxAct
</p:submenu>
<p:submenu label="Non Ajax Menuitem">
<p:menuitem value="Non Ajax Action" action="#{tieredMenuManagedBean.non
</p:submenu>
<p:separator/>
<p:submenu label="Navigations">
<p:submenu label="Primefaces links">
<p:menuitem value="Prime" url="http://www.prime.com.tr"></p:menuite
<p:menuitem value="Primefaces" url="http://www.primefaces.org"
</p:submenu>
<p:submenu label="Prime Blogs">
<p:menuitem value="JournalDev" url="http://www.journaldev.com"
</p:submenu>
</p:submenu>
</p:tieredMenu>
<p:commandButton value="Show Menu" id="triggerBtn"></p:commandButton>
</h:form>
</html>
pdfcrowd.com
Method
Params
Return Type
Description
show()
void
hide()
void
align()
void
index11.xhtml
1
2
3
4
5
6
7
8
9
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
<script>
function showMenu(){
pdfcrowd.com
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function showMenu(){
PF('tieredMenu').show();
}
function hideMenu(){
PF('tieredMenu').hide();
}
</script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:tieredMenu autoDisplay="false" trigger="triggerBtn" overlay="true" my="left
<p:submenu label="Ajax Menuitem">
<p:menuitem value="Ajax Action" action="#{tieredMenuManagedBean.ajaxAct
</p:submenu>
<p:submenu label="Non Ajax Menuitem">
<p:menuitem value="Non Ajax Action" action="#{tieredMenuManagedBean.non
</p:submenu>
<p:separator/>
<p:submenu label="Navigations">
<p:submenu label="Primefaces links">
<p:menuitem value="Prime" url="http://www.prime.com.tr"></p:menuite
<p:menuitem value="Primefaces" url="http://www.primefaces.org"
</p:submenu>
<p:submenu label="Prime Blogs">
<p:menuitem value="JournalDev" url="http://www.journaldev.com"
</p:submenu>
</p:submenu>
</p:tieredMenu>
<p:commandButton value="Show Menu - Normal Trigger" id="triggerBtn"></p:command
<p:commandButton value="Show Menu - JavaScript function" onclick="showMenu()"
<p:commandButton value="Hide Menu - JavaScript function" onclick="hideMenu()"
</h:form>
</html>
pdfcrowd.com
Tag
slideMenu
Component Class
org.primefaces.component.slidemenu.SlideMenu
Component Type
org.primefaces.component.SlideMenu
Component Family
org.primefaces.component
Renderer Type
org.primefaces.component.SlideMenuRenderer
Renderer Class
org.primefaces.component.slidemenu.SlideMenuRenderer
pdfcrowd.com
Default
Type
Description
id
null
String
rendered
true
Boolean
Boolean value to specify the rendering of the component, when set to false
component will not be rendered.
binding
null
Object
widgetVar
null
String
model
null
MenuModel
style
null
String
styleClass
null
String
backLabel
Back
String
trigger
null
String
Id of the component whose triggerEvent will show the dynamic positioned menu.
pdfcrowd.com
my
null
String
at
null
String
overlay
false
Boolean
triggerEvent
click
String
Event name of trigger that will show the dynamic positioned menu.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
<script>
function showMenu(){
pdfcrowd.com
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
1
2
function showMenu(){
PF('tieredMenu').show();
}
function hideMenu(){
PF('tieredMenu').hide();
}
</script>
</h:head>
<h:form style="width:400px;">
<p:growl id="message"></p:growl>
<p:slideMenu autoDisplay="false" trigger="triggerBtn" overlay="true" my="left t
<p:submenu label="Ajax Menuitem">
<p:menuitem value="Ajax Action" action="#{slideMenuManagedBean.ajaxActi
</p:submenu>
<p:submenu label="Non Ajax Menuitem">
<p:menuitem value="Non Ajax Action" action="#{slideMenuManagedBean.nonA
</p:submenu>
<p:separator/>
<p:submenu label="Navigations">
<p:submenu label="Primefaces links">
<p:menuitem value="Prime" url="http://www.prime.com.tr"></p:menuite
<p:menuitem value="Primefaces" url="http://www.primefaces.org"
</p:submenu>
<p:submenu label="Prime Blogs">
<p:menuitem value="JournalDev" url="http://www.journaldev.com"
</p:submenu>
</p:submenu>
</p:slideMenu>
<p:commandButton value="Show Menu - Normal Trigger" id="triggerBtn"></p:command
<p:commandButton value="Show Menu - JavaScript function" onclick="showMenu()"
<p:commandButton value="Hide Menu - JavaScript function" onclick="hideMenu()"
</h:form>
</html>
package com.journaldev.prime.faces.beans;
pdfcrowd.com
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import
import
import
import
javax.faces.application.FacesMessage;
javax.faces.bean.ManagedBean;
javax.faces.bean.SessionScoped;
javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class SlideMenuManagedBean {
public String ajaxAction(){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Ajax U
return "";
}
pdfcrowd.com
pdfcrowd.com
Summary
Primefaces provides you a vast amount of Primefaces UI Menu components, that are set the developer in
front of interesting collection that the user may select from. This tutorial intended to clarify part of these
menu types. Contribute us by commenting below and find the source code for this tutorial.
Related Posts:
Primefaces Panel,
Primefaces Toolbar,
Primefaces Tab,
PanelGrid &
ToolbarGroup &
PrimeFaces Tutorial
PanelMenu Example
Tooltip
TagCloud
with Example
Tutorial
Components
components
Projects
primefaces
Primefaces components
primefaces menu
primefaces menubar
pdfcrowd.com
pdfcrowd.com
Baboutini says:
November 12, 2014 at 12:37 am
Hi,
Went i take your source code for programmatic menubar.
Mozilla dont display the submenu propertly.
How to solve it ?
Reply
Baboutini says:
November 13, 2014 at 3:32 am
Hi
I solved my problem display submenus with Mozilla by setting the width of my webpage
to 100% (style =100%)
Reply
pdfcrowd.com
Bijetri says:
October 11, 2014 at 2:43 am
The pop up menus or trigger menus or sliding menus are not working. It could be because
the jquery.js file is messing. Please provide it. It will be really help ful
Reply
Bijetri says:
October 11, 2014 at 2:34 am
Please include the jquery.js in the download or provide a link for it to download. Thanks.
Reply
Pankaj says:
October 11, 2014 at 2:57 am
pdfcrowd.com
Reply
Leave a Reply
Your email address will not be published. Required fields are marked *
Name
Website
Comment
pdfcrowd.com
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b>
<blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Post Comment
Be My Friend
JournalDev
Like
pdfcrowd.com
Pankaj Kumar
Follow
4,342 followers
JournalDev
Follow
+1
+ 8,933
Recent Posts
AngularJS Custom Directives Tutorial
Part 1
JSF Form Components Example
Tutorial
Oracle Webcenter Portal Framework
Hierarchy
JSF UI Component Tag Attributes
View Results
open in browser PRO version
Example Tutorial
pdfcrowd.com
Adve rtise He re
Categories
AngularJS
Database
MongoDB
Tutorial Example
Hibernate
Interview Questions
pdfcrowd.com
Java
Design Patterns
Java EE
jQuery
jQuery Plugins
JSF
Maven
PHP
Portal and Portlets
PrimeFaces
Random
Resources
HTML
Scripts
Softwares
pdfcrowd.com
Spring
Struts 2
Web Design
Wordpress
Pages
About
Advertise
Java Interview Questions
Privacy Policy
Tutorials
Write For Us
Popular Tags
hibernate
hibernate example
Tutorials
Interview Questions
Multi-Threading Interview
pdfcrowd.com
hibernate tutorial
java Arrays
java file
java String
java Thread
jQuery
java xml
mongodb
primefaces
Interview Questions
Tutorial
Questions
primefaces tutorial
spring tutorial
struts 2 tutorial
struts 2
Be My Friend
Facebook
Google+
Twitter
Powered by WordPress
Karma.
pdfcrowd.com