Dynamic MenuBar not so dynamic

UI Components for JSF
Post Reply
_lucas_
Posts: 10
Joined: 09 Jul 2011, 22:42

03 Aug 2011, 02:29

Hi everybody, I have the following problem:

I have a form, and in it I'm using a MenuBar that I programmatically built, I wanted a Menu that is have some items while the user is not logged, then when he do log, if he is a enterprise user, some items appear,and if he is a normal user, then other items appear, I know for sure this code works, but the problem is: it work only one time, before the user have logged in, and after it doesn't update with the new items. I'm using the MenuBar inside a ui:repeat, i don't know if it has something to do with this.
below is my bean and the MenuBar itself:
Bean:

Code: Select all

public class MenuBean {
	private MenuModel menu;
	public MenuBean(){
		menu = new DefaultMenuModel();
		
		FacesContext fc = FacesContext.getCurrentInstance();
		ExternalContext exc = fc.getExternalContext();
		Person person = (Person) exc.getSessionMap().get("user");
		Submenu subMenu = new Submenu();
		MenuItem item= new MenuItem();
		Submenu oport = new Submenu();
		
		if(person!=null){
			if(person.getTp_person()=='J'){
				EnterpriseDAO dao = new EnterpriseDAO();
				EnterpriseEntity enterprise = dao.find(person.getId());
				subMenu.setLabel("Enterprise");
				item.setValue("Update data");
				item.setUrl("#");
				item.setIcon("ui-icon ui-icon-wrench");
				subMenu.setIcon("ui-icon ui-icon-home");
				subMenu.getChildren().add(item);
				item= new MenuItem();
				item.setValue("Change Password");
				item.setIcon("ui-icon ui-icon-key");
				item.setUrl("#");
				subMenu.getChildren().add(item);
				subMenu.setIcon("ui-icon ui-icon-home");
				menu.addSubmenu(subMenu);

			
				item = new MenuItem();
				item.setValue("Incluir");
				if(empresa.getTp_enterprise()=='R')
					item.setUrl("cadOportPriv.xhtml");
				else
					item.setUrl("cadOportunityPub.xhtml");
				item.setIcon("ui-icon ui-icon-plus");
				oport.getChildren().add(item);
				item= new MenuItem();
				item.setIcon("ui-icon ui-icon-minus");
				item.setValue("Update/Delete");
				item.setUrl("#");
				oport.getChildren().add(item);
				item= new MenuItem();
				item.setIcon("ui-icon ui-icon-minus");
				item.setValue("My Oportunities");
				item.setUrl("#");
				oport.getChildren().add(item);
				
				
			
				
				
			}else {
				subMenu.setLabel("My  account");
				item.setValue("Update  data");
				item.setUrl("#");
				item.setIcon("ui-icon ui-icon-home");
				subMenu.getChildren().add(item);
				item= new MenuItem();
				item.setValue("Change password");
				item.setIcon("ui-icon ui-icon-key");
				item.setUrl("#");
				subMenu.getChildren().add(item);
				subMenu.setIcon("ui-icon ui-icon-home");
				menu.addSubmenu(subMenu);
				item= new MenuItem();
				item.setIcon("ui-icon ui-icon-minus");
				item.setValue("My Oportunities");
				item.setUrl("#");
				oport.getChildren().add(item);
				
			}
		}else {
			item = new MenuItem();
			item.setValue("Login");
			item.setOnclick("loginDialog.show();");
			
			menu.addMenuItem(item);
			item= new MenuItem();
			item.setValue("Register!");
			item.setUrl("cadUser.xhtml");
			menu.addMenuItem(item);
		}
		item= new MenuItem();
		item.setValue("Search Oportunities");
		item.setUrl("#");
		item.setIcon("ui-icon ui-icon-search");
		
		oport.setLabel("Oportunities");
		oport.setIcon("ui-icon ui-icon-star");
		oport.getChildren().add(item);
		menu.addSubmenu(oport);
	}

	public void setMenu(MenuModel menu) {
		this.menu = menu;
	}
	public MenuModel getMenu() {
		return menu;
	}


Code: Select all

<ui:include src="MenuEnterprise.xhtml"></ui:include>
MenuEnterprise.xhtml:

Code: Select all

<!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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head>
	<link type="text/css" rel="StyleSheet" href="css/default.css" />
	<link type="text/css" rel="StyleSheet" href="css/Menu.css" />
</h:head>

<h:body>
	<ui:debug hotkey="K" />

	<p:growl id="messages" showDetail="false" showSummary="false" />
	<h:form id="formMenuBar">

		<p:menubar model="#{bar.menu}"  autoSubmenuDisplay="true" style="float:top;" effect="drop"/>
			

	</h:form>
	<p:dialog widgetVar="loginDialog" resizable="false"
		id="logindialog" header="Log in">
		<h:form id="formLogin" prependId="false">
		<p:growl />
		
			<p>
				<p:inputText id="user" required="true" value="#{login.user}" />
				<p:message for="user"></p:message>
			</p>
			<p>

				<p:password id="password" feedback="false" value="#{login.password}"
					required="true" />
				<p:message for="password"></p:message>
			</p>
			<p>
				<h:commandButton value="Log in"
					actionListener="#{login.validateUser}" update="formLogin,formMenuBar"></h:commandButton>
			</p>
		
	</h:form>
		</p:dialog>

</h:body>
</html>
I though the ui:include may had something to do with this, but even if I copy the code from MenuEnterprise.xhtml inside any page to test,it yet does not update, so I don't really know, what should I do?
I tried also to bind the Menubar with a backing bean, but the result is the same, except without css, Im using primefaces v3.0.M2.

anavarro
Posts: 20
Joined: 14 Aug 2012, 01:06

06 Sep 2012, 18:04

did you ever solve this?
JSF 2.1
Primefaces 2.2.1
Netbeans 7.1.2
Apache Tomcat 7.0.22.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 24 guests