richfaces4 布局 panelMenu保持选中状态

阅读更多
布局文件
/richfaces-demo/webapp/masterLayout.xhtml




	
	
	


	

布局CSS
/richfaces-demo/webapp/resources/css/layout.css
@CHARSET "UTF-8";
#heading {
	width: 100%;
	height: 30px;
	background-color: blue;
}
#menu {
	float: left;
	width: 240px;
	height: 400px;
	background-color: orange;
}
#content {
	width: 100%;
	height: 400px;
	background-color: gray;
}

全局CSS
/richfaces-demo/webapp/resources/css/style.css
@CHARSET "UTF-8";
*{ margin:0; padding:0;}
body {
	font-size: 12px;
}

菜单页面
/richfaces-demo/webapp/menu.xhtml






	
		
		

第一个页面
/richfaces-demo/webapp/index.xhtml




	
	
	


	
		第一个页面
	



第二个页面
/richfaces-demo/webapp/main.xhtml




	
	
	


	
		第二个页面
	



两个Bean
/richfaces-demo/src/test/MenuBean.java
package test;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;

@ManagedBean
@RequestScoped
public class MenuBean implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@ManagedProperty(value = "#{menuState}")
	private MenuState menuState;

	public MenuState getMenuState() {
		return menuState;
	}

	public void setMenuState(MenuState menuState) {
		this.menuState = menuState;
	}

	public MenuBean() {
	}

	public void select(ActionEvent event) {
		menuState.setSelectedMenuItem(event.getComponent().getId());
	}
}

/richfaces-demo/src/test/MenuState.java
package test;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class MenuState implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private Map menu;
	private String selectedMenuItem;
	
	public String getSelectedMenuItem() {
		return selectedMenuItem;
	}

	public Map getMenu() {
		return menu;
	}

	public void setMenu(Map menu) {
		this.menu = menu;
	}

	public void setSelectedMenuItem(String selectedMenuItem) {
		this.selectedMenuItem = selectedMenuItem;
	}

	public MenuState() {
	}

	@PostConstruct
	public void init() {
		menu = new HashMap();
		menu.put("group1", false);
		menu.put("group2", false);
	}
}

你可能感兴趣的:(richfaces)