Hello guys i have been trying to change the menubar to primefaces 3.5 to primefaces 4.0 actually .I got an error when generate the primefaces menubar in pf4.0.Please help guys.........
package xbashhr.general;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import org.primefaces.component.menuitem.UIMenuItem;
import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuColumn;
import org.primefaces.model.menu.MenuElement;
import org.primefaces.model.menu.MenuModel;
@ManagedBean(name = "topmenu1")
@RequestScoped
public class TopMenuBean1 {
private MenuModel model;
private String current_module = "No module chosen ...";
private ArrayList<UserMenus> um_list;
@SuppressWarnings("unchecked")
public TopMenuBean1() {
this.um_list = new ArrayList<UserMenus>();
this.um_list.addAll((ArrayList<UserMenus>) utils.execute_VE("#{loginBean.ua.user_menus}", ArrayList.class));
this.current_module = (String) utils.execute_VE("#{loginBean.ua.current_module}", String.class);
this.model = new DefaultMenuModel();
}
@PostConstruct
public void construct_top_menu() {
String menu_item_id_prefix;
String base_path = utils.get_base_path();
System.out.println("About to construct top menu and Base path is ---> " + base_path);
Collections.sort(this.um_list, new Comparator<UserMenus>() {
@Override
public int compare(UserMenus u1, UserMenus u2) {
return (u1.getMenu_id() * 100 + u1.getParent_menu_id()) - (u2.getMenu_id() * 100 + u2.getParent_menu_id());
}
});
UserMenus user_menu_item;
DefaultSubMenu submenu = null;
DefaultMenuItem dmf = null;
DefaultMenuItem dmf1 = null;
DefaultSubMenu dsm = null;
for (int i = 0 ; i < this.um_list.size() ; i++) {
System.out.println("hey");
user_menu_item = this.um_list.get(i);
menu_item_id_prefix = "Top_" + Integer.toString(user_menu_item.getMenu_id()) + "_";
System.out.println(hasChildren(user_menu_item) + "-----------------");
if (hasChildren(user_menu_item)) {
submenu = new DefaultSubMenu();
submenu.setLabel(user_menu_item.getMenu_display_name());
submenu.setId(menu_item_id_prefix + user_menu_item.getMenu_display_name().replace(' ', '_'));
DefaultSubMenu parent = this.parentItem(user_menu_item);
if (parent == null) {
this.model.addElement(submenu);
} else {
parent.getElements().add(submenu);
submenu.addElement(parent);
}
} else {
DefaultMenuItem item = new DefaultMenuItem();
item.setId(menu_item_id_prefix + user_menu_item.getMenu_display_name().replace(' ', '_'));
item.setValue(user_menu_item.getMenu_display_name());
item.setTitle(user_menu_item.getMenu_display_name());
item.setUrl(base_path + "/" + user_menu_item.getUrl() + "?mn=" + user_menu_item.getMenu_id());
DefaultSubMenu parent = this.parentItem(user_menu_item);
if (parent == null) {
this.model.addElement(item);
} else {
parent.getElements().add(item);
}
}
}
}
private Boolean hasChildren(UserMenus um) {
int i;
for (i = 0 ; i < this.um_list.size() && !(um_list.get(i).getParent_menu_id() == um.getMenu_id()) ; i++)
;
return (i < this.um_list.size());
}
public MenuModel getModel() {
return model;
}
public void setModel(MenuModel model) {
this.model = model;
}
public String getCurrent_module() {
return current_module;
}
public void setCurrent_module(String current_module) {
this.current_module = current_module;
}
public ArrayList<UserMenus> getUm_list() {
return um_list;
}
public void setUm_list(ArrayList<UserMenus> um_list) {
this.um_list = um_list;
}
public DefaultSubMenu parentItem(UserMenus user_menu_item) {
DefaultSubMenu uic = null;
ArrayList<DefaultSubMenu> all_components = new ArrayList<DefaultSubMenu>();
String search_string = null;
int i;
for (i = 0 ; i < this.um_list.size() && !(this.um_list.get(i).getMenu_id() == user_menu_item.getParent_menu_id()) ; i++)
;
if (i < this.um_list.size()) {
String menu_item_id_prefix = "Top_" + Integer.toString(um_list.get(i).getMenu_id()) + "_";
search_string = menu_item_id_prefix + um_list.get(i).getMenu_display_name().replace(" ", "_");
all_components.addAll((Collection<? extends DefaultSubMenu>) this.model.getElements());
for (int j = 0 ; j < all_components.size() ; j++) {
if (!search_string.equals(all_components.get(i).getId())) {
all_components.addAll((Collection<? extends DefaultSubMenu>) all_components.get(i).getElements());
} else {
System.out.println("hey 2");
System.out.println("false else in allcomponents");
}
System.out.println(i + " hey");
}
if (i < all_components.size()) {
uic = all_components.get(i);
} else {
System.out.println("hey ");
}
}
return uic;
}
}
failure to create primefaces menubar level
-
- Posts: 100
- Joined: 29 Jan 2014, 03:41
Regards
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Hi, Please read the forum posting rules about code tags...
And it might help a lot if you posted WHAT error you got. And did you search the forum (and read the migration documentation about the models used in the menus?)
And it might help a lot if you posted WHAT error you got. And did you search the forum (and read the migration documentation about the models used in the menus?)
-
- Posts: 100
- Joined: 29 Jan 2014, 03:41
kukeltje wrote:Hi, Please read the forum posting rules about code tags...
And it might help a lot if you posted WHAT error you got. And did you search the forum (and read the migration documentation about the models used in the menus?)
ok thanks where i can get the migration documentation about the models used in the menus?
Regards
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
-
- Posts: 100
- Joined: 29 Jan 2014, 03:41
kukeltje wrote:well, you can find it at least via here
And reading the blog now and then might also help
(and yes, it might have been easier to find via the basic site)
thank you kukeltje for the migration form .can u help me with the menumodel well i'm a newbie.please help me to create a menumodel
Regards
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
There have been posts about the differences between the 3.5 and 4.0 model in this forum, so you might be able to find things there. Since I personally do not use the models I have to digg into it myself as well, for which I do not have the time (nor do I want to 'create' the time, lots of other things to do, sorry).
Others might be able to help you out.
And do not forget my other question... Posting WHAT goes WRONG helps others a lot... Believe me, they will not try to find your error without that info... And please edit your initial post, using code tags AND correct indentation (use preview to check)
Others might be able to help you out.
And do not forget my other question... Posting WHAT goes WRONG helps others a lot... Believe me, they will not try to find your error without that info... And please edit your initial post, using code tags AND correct indentation (use preview to check)
-
- Posts: 100
- Joined: 29 Jan 2014, 03:41
kukeltje wrote:There have been posts about the differences between the 3.5 and 4.0 model in this forum, so you might be able to find things there. Since I personally do not use the models I have to digg into it myself as well, for which I do not have the time (nor do I want to 'create' the time, lots of other things to do, sorry).
Others might be able to help you out.
And do not forget my other question... Posting WHAT goes WRONG helps others a lot... Believe me, they will not try to find your error without that info... And please edit your initial post, using code tags AND correct indentation (use preview to check)
thanks kukeltje for giving me some idea
Regards
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
-
- Posts: 100
- Joined: 29 Jan 2014, 03:41
senthilkumar.89 wrote:kukeltje wrote:There have been posts about the differences between the 3.5 and 4.0 model in this forum, so you might be able to find things there. Since I personally do not use the models I have to digg into it myself as well, for which I do not have the time (nor do I want to 'create' the time, lots of other things to do, sorry).
Others might be able to help you out.
And do not forget my other question... Posting WHAT goes WRONG helps others a lot... Believe me, they will not try to find your error without that info... And please edit your initial post, using code tags AND correct indentation (use preview to check)
Hello guys i have been doing like this for menubar for getting from database and it is working for two levels after that it is not displaying for third level i have been getting error . here is the code..... Please Help me Guys
------------------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import org.primefaces.component.menuitem.UIMenuItem;
import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuColumn;
import org.primefaces.model.menu.MenuElement;
import org.primefaces.model.menu.MenuModel;
@ManagedBean(name = "topmenu1")
@RequestScoped
public class TopMenuBean1 {
private MenuModel model;
private String current_module = "No module chosen ...";
private ArrayList<UserMenus> um_list;
@SuppressWarnings("unchecked")
public TopMenuBean1() {
this.um_list = new ArrayList<UserMenus>();
this.um_list.addAll((ArrayList<UserMenus>) utils.execute_VE("#{loginBean.ua.user_menus}", ArrayList.class));
this.current_module = (String) utils.execute_VE("#{loginBean.ua.current_module}", String.class);
this.model = new DefaultMenuModel();
}
@PostConstruct
public void construct_top_menu() {
String menu_item_id_prefix;
String base_path = utils.get_base_path();
System.out.println("About to construct top menu and Base path is ---> " + base_path);
Collections.sort(this.um_list, new Comparator<UserMenus>() {
@Override
public int compare(UserMenus u1, UserMenus u2) {
return (u1.getMenu_id() * 100 + u1.getParent_menu_id()) - (u2.getMenu_id() * 100 + u2.getParent_menu_id());
}
});
UserMenus user_menu_item;
DefaultSubMenu submenu = null;
DefaultMenuItem dmf = null;
DefaultMenuItem dmf1 = null;
DefaultSubMenu dsm = null;
for (int i = 0 ; i < this.um_list.size() ; i++) {
System.out.println("hey");
user_menu_item = this.um_list.get(i);
menu_item_id_prefix = "Top_" + Integer.toString(user_menu_item.getMenu_id()) + "_";
System.out.println(hasChildren(user_menu_item) + "-----------------");
if (hasChildren(user_menu_item)) {
submenu = new DefaultSubMenu();
submenu.setLabel(user_menu_item.getMenu_display_name());
submenu.setId(menu_item_id_prefix + user_menu_item.getMenu_display_name().replace(' ', '_'));
DefaultSubMenu parent = this.parentItem(user_menu_item);
if (parent == null) {
this.model.addElement(submenu);
} else {
parent.getElements().add(submenu);
submenu.addElement(parent);
}
} else {
DefaultMenuItem item = new DefaultMenuItem();
item.setId(menu_item_id_prefix + user_menu_item.getMenu_display_name().replace(' ', '_'));
item.setValue(user_menu_item.getMenu_display_name());
item.setTitle(user_menu_item.getMenu_display_name());
item.setUrl(base_path + "/" + user_menu_item.getUrl() + "?mn=" + user_menu_item.getMenu_id());
DefaultSubMenu parent = this.parentItem(user_menu_item);
if (parent == null) {
this.model.addElement(item);
} else {
parent.getElements().add(item);
}
}
}
}
private Boolean hasChildren(UserMenus um) {
int i;
for (i = 0 ; i < this.um_list.size() && !(um_list.get(i).getParent_menu_id() == um.getMenu_id()) ; i++)
;
return (i < this.um_list.size());
}
public MenuModel getModel() {
return model;
}
public void setModel(MenuModel model) {
this.model = model;
}
public String getCurrent_module() {
return current_module;
}
public void setCurrent_module(String current_module) {
this.current_module = current_module;
}
public ArrayList<UserMenus> getUm_list() {
return um_list;
}
public void setUm_list(ArrayList<UserMenus> um_list) {
this.um_list = um_list;
}
public DefaultSubMenu parentItem(UserMenus user_menu_item) {
DefaultSubMenu uic = null;
ArrayList<DefaultSubMenu> all_components = new ArrayList<DefaultSubMenu>();
String search_string = null;
int i;
for (i = 0 ; i < this.um_list.size() && !(this.um_list.get(i).getMenu_id() == user_menu_item.getParent_menu_id()) ; i++)
;
if (i < this.um_list.size()) {
String menu_item_id_prefix = "Top_" + Integer.toString(um_list.get(i).getMenu_id()) + "_";
search_string = menu_item_id_prefix + um_list.get(i).getMenu_display_name().replace(" ", "_");
all_components.addAll((Collection<? extends DefaultSubMenu>) this.model.getElements());
for (int j = 0 ; j < all_components.size() ; j++) { // this were i'm getting error for the file (i.e., defaultsubmenu can't be cast to defaultmenuitem..).If any one have any idea about this .please help me
if (!search_string.equals(all_components.get(i).getId())) {
all_components.addAll((Collection<? extends DefaultSubMenu>) all_components.get(i).getElements());
} else {
System.out.println("hey 2");
System.out.println("false else in allcomponents");
}
System.out.println(i + " hey");
}
System.out.println(all_components.get(i).getLabel() + "------------------------");
System.out.println(all_components.size() + "--------hey");
System.out.println(search_string.equals(all_components.get(i).getId()) + "------------hey there");
if (i < all_components.size()) {
uic = all_components.get(i);
} else {
System.out.println("hey ");
}
}
return uic;
}
}
------------------------------------------------------------------------------------------------------------------------------
Regards
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
-
- Posts: 100
- Joined: 29 Jan 2014, 03:41
org.primefaces.model.menu.DefaultMenuItem cannot be cast to org.primefaces.model.menu.DefaultSubMenu
at pharmacy.general.TopMenuBean.parentItem(TopMenuBean.java:107) [classes:]
hello guys i have been getting this error.Can some one please tell me about it
i have been using primefaces 4.0
at pharmacy.general.TopMenuBean.parentItem(TopMenuBean.java:107) [classes:]
hello guys i have been getting this error.Can some one please tell me about it
i have been using primefaces 4.0
Regards
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
Senthil Kumar
Jsf 2.1,2.2, Primefaces 3.5, Primefaces 4.0,
Primefaces Mobile 0.9.5
Primefaces 5.0.RC1,Primefaces 5.2,Primefaces Extentsions 3.2.0.
- andyba
- Expert Member
- Posts: 2473
- Joined: 31 Mar 2011, 16:27
- Location: Steinfeld, near Bremen/Osnabrück, DE
- Contact:
You have been asked, politely, to read the forum rules and use code tags to format the code you post. I am asking you, again politely, to do so.
Using code tags is not us being fussy, it makes your code much easier for us to read. Without this you will find people, like me, won't be prepared to make much effort to help you.
Using code tags is not us being fussy, it makes your code much easier for us to read. Without this you will find people, like me, won't be prepared to make much effort to help you.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now
-
- Information
-
Who is online
Users browsing this forum: No registered users and 54 guests