⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexbean.java

📁 HR系统模拟企业对内部职员的管理
💻 JAVA
字号:
/*$Id: IndexBean.java,v 1.1 2008/07/15 03:38:23 liqi Exp $ *-------------------------------------- * Apusic (Kingdee Middleware) *--------------------------------------- * Copyright By Apusic ,All right Reserved * author   date   comment * chenhongxin  2008-4-14  Created*/package org.operamasks.example.ejb.hr.litebean.module;import java.util.Collections;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Set;import javax.faces.application.Application;import javax.faces.context.ExternalContext;import javax.faces.context.FacesContext;import javax.faces.event.ActionEvent;import org.operamasks.example.ejb.hr.constants.ILocalStringsKey;import org.operamasks.example.ejb.hr.constants.IUserConstants;import org.operamasks.example.ejb.hr.entity.Module;import org.operamasks.example.ejb.hr.entity.ModuleItem;import org.operamasks.example.ejb.hr.entity.Role;import org.operamasks.example.ejb.hr.entity.User;import org.operamasks.example.ejb.hr.service.ServiceBean;import org.operamasks.example.ejb.hr.util.TagPanelUtil;import org.operamasks.example.ejb.hr.util.Util;import org.operamasks.faces.annotation.Action;import org.operamasks.faces.annotation.ActionListener;import org.operamasks.faces.annotation.BeforeRender;import org.operamasks.faces.annotation.Bind;import org.operamasks.faces.annotation.ManagedBean;import org.operamasks.faces.annotation.ManagedBeanScope;import org.operamasks.faces.annotation.ManagedProperty;import org.operamasks.faces.component.ajax.AjaxUpdater;import org.operamasks.faces.component.widget.UIButton;import org.operamasks.faces.component.widget.UISeparator;import org.operamasks.faces.component.widget.UIToolBar;import org.operamasks.faces.component.widget.menu.UICommandMenuItem;import org.operamasks.faces.component.widget.menu.UIMenu;/** * 主页面的托管Bean * @author chenhongxin */@ManagedBean(name = "module.indexBean", scope = ManagedBeanScope.SESSION)public class IndexBean extends BaseBean {	private static final String HELP_PAGE_URL = "help.faces";	private static final String HELP_ICON_URL = "../resources/images/help.png";	private static final String REFRESH_ICOM_URL = "../resources/images/refresh.png";		/**	 * 注入服务提供Bean,该Bean提供各种的业务操作对象	 */	@ManagedProperty("#{serviceBean}")	private ServiceBean service;	/**	 * 绑定页面上的ToolBar组件	 */	@Bind(id = "toolBar", attribute = "binding")	private UIToolBar toolBar;	/**	 * 绑定菜单项的Updater	 */	@Bind(id = "menuUpdater", attribute = "binding")	private AjaxUpdater menuUpdater;		/**	 * 绑定页面的js脚本回调	 */	@Bind(id="scripter", attribute="script")	private String scripter;	@BeforeRender	protected void beforeRender(boolean isPostBack) {		initBaseResource();		if (!isPostBack) {			ExternalContext eContext = FacesContext.getCurrentInstance().getExternalContext();			Map<String, Object> session = eContext.getSessionMap();			User user = (User)session.get(IUserConstants.USER_BEAN);			Set<String> validateItems = getValidateModuleItemIdSet(user.getRole());						FacesContext context = FacesContext.getCurrentInstance();			Application application = context.getApplication();			List<Module> modules = service.getModuleService().listModule();			if (modules != null) {				for (Module module : modules) {					//创建菜单					UIMenu menu = (UIMenu)application.createComponent(UIMenu.COMPONENT_TYPE);					menu.setLabel(module.getName());					menu.setImage(module.getIcon());					List<ModuleItem> items = module.getModuleItems();					if (items != null) {						for (ModuleItem item : items) {							//创建菜单下拉项							UICommandMenuItem uiItem = (UICommandMenuItem)application.createComponent(UICommandMenuItem.COMPONENT_TYPE);							uiItem.setLabel(item.getName());							uiItem.setImage(Util.getBasePath() + item.getIcon());							uiItem.setValue(item.getUrl());							//添加事件监听							uiItem.addActionListener(Util.createMethodExpressionActionListener(context, "#{module.indexBean.redirect}"));							if(validateItems.contains(item.getId())) {//只有当前用户角色可见的模块项才添加到菜单								menu.getChildren().add(uiItem);							}						}					}					toolBar.getChildren().add(menu);					UISeparator separator = (UISeparator)application.createComponent(UISeparator.COMPONENT_TYPE);					toolBar.getChildren().add(separator);				}								//创建帮助按钮				UIButton helpBtn = (UIButton)application.createComponent(UIButton.COMPONENT_TYPE);				helpBtn.setId("help");				helpBtn.setLabel(getMessages().get(ILocalStringsKey.MENU_HELP_LABEL));				helpBtn.setImage(HELP_ICON_URL);				helpBtn.setValue(HELP_PAGE_URL);				toolBar.getChildren().add(helpBtn);								//创建刷新按钮				UIButton refreshBtn = (UIButton)application.createComponent(UIButton.COMPONENT_TYPE);				refreshBtn.setId("refresh");				refreshBtn.setLabel(getMessages().get(ILocalStringsKey.MENU_REFRESH_LABEL));				refreshBtn.setImage(REFRESH_ICOM_URL);				toolBar.getChildren().add(refreshBtn);								//使用AjaxUpdater动态刷型区域组件				menuUpdater.reload();			}		}	}		/**	 * 获取角色对应的合法访问模块的id集合	 * @param role 进行判断的角色对象	 * @return 角色对应的合法访问模块的id集合	 */	private Set<String> getValidateModuleItemIdSet(Role role) {		List<ModuleItem> validateItems = role.getModuleItems();		if(validateItems == null) return Collections.emptySet();		Set<String> set = new HashSet<String>();		for(ModuleItem item : validateItems) {			set.add(item.getId());		}		return set;	}		/**	 * 绑定帮助按钮点击事件	 */	@Action(id="help")	public void help() {		scripter = formatScript(getMessages().get(ILocalStringsKey.MENU_HELP_LABEL), 								HELP_PAGE_URL, 								HELP_ICON_URL);	}		/**	 * 绑定刷新当前标签页的按钮点击事件	 */	@Action(id="refresh")	public void refresh() {		scripter = "refreshTag();";	}	/**	 * 事件监听函数,用于执行菜单按钮点击后的页面切换的脚本回调	 * @param e ActionEvent	 */	@ActionListener	public void redirect(ActionEvent e) {		if (e.getComponent() instanceof UICommandMenuItem) {			UICommandMenuItem item = (UICommandMenuItem) e.getComponent();			Object obj = item.getValue();			String url = (obj instanceof String ? (String)obj : obj.toString());			scripter = formatScript(item.getLabel(), url, item.getImage());		}	}		/**	 * 格式化调用添加标签页的js回调脚本	 * @param title 标签页的名称	 * @param url 标签页内容页面的url	 * @param icon 标签页的小图标地址	 * @return 格式化好的js回调脚本字符串	 */	private String formatScript(String title, String url, String icon) {		return String.format("addTab('%s','%s','%s');", title, url, TagPanelUtil.getTabPanelIconCls(icon));	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -