JSF抽屉式菜单的实现

主要是使用<layout:accordionLayout/>控件实现效果,话不多说,直接上代码:

 

<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
	xmlns:ui="http://java.sun.com/jsf/facelets" renderKitId="AJAX">
	<w:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<w:stylesheet src="resources/css/style.css"></w:stylesheet>
	</w:head>
	<w:page title="Insert title here">
		<layout:borderLayout fitToBody="true">
			<layout:panel region="north" autoHeight="true" border="false">
				<ui:include src="header.xhtml"></ui:include>
			</layout:panel>
			<layout:panel region="west" width="200"  title="菜单" split="true" border="false" collapsible="true">
				<layout:accordionLayout id="layout" animate="true" fit="true" border="false"></layout:accordionLayout>
			</layout:panel>
			 <layout:panel region="center" title="center" fit="true">                
			 <w:iframe style="width: 100%; height: 100%" id="frame" src="workspace.xhtml" name="content" frameborder="no" />           
			  </layout:panel>
			  <layout:panel region="south" autoHeight="true" border="false">               
			   <ui:include src="footer.xhtml" />            
			   </layout:panel>
		</layout:borderLayout>
	</w:page>
</f:view>

 

 

package com.ahsl.index;

import java.util.List;

import javax.faces.application.Application;
import javax.faces.component.html.HtmlGraphicImage;
import javax.faces.component.html.HtmlOutputLink;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.layout.impl.UIAccordionLayout;
import org.operamasks.faces.component.layout.impl.UIPanel;

import com.ahsl.index.enities.Function;
import com.ahsl.index.enities.Functiontype;
import com.ahsl.index.service.IFunctionService;
import com.ahsl.index.service.IFunctiontypeService;
@ManagedBean(name = "AccordionLayoutBean", scope = ManagedBeanScope.REQUEST)
public class AccordionLayoutBean {
	
	  @Inject(value="functionSpringService")
	  private IFunctionService fs;
	  
	  @Inject(value="functiontypeSpringService")
	  private IFunctiontypeService fts;
	
	  @Bind
	  private UIAccordionLayout layout;
	  
	  @BeforeRender
	  public void beforeRender(boolean isPostback) {
	    
	    FacesContext context = FacesContext.getCurrentInstance();
	    Application app = context.getApplication();
	    List<Functiontype> ftlist=fts.findAll();
	    for (Functiontype ft:ftlist) {
	        UIPanel panel = (UIPanel) app
	            .createComponent(UIPanel.COMPONENT_TYPE);
	        panel.setTitle(ft.getName());
	        List<Function> flist=fs.findByTypeID(ft.getUid());
	        for (Function fun:flist) {
	            HtmlOutputLink hOL = (HtmlOutputLink) app
	                .createComponent(HtmlOutputLink.COMPONENT_TYPE);
	            hOL.setValue(fun.getFunCode());
	            hOL.setTarget("content");
	            hOL.setStyle("color: #0078C2;text-decoration: none;margin: 6px 3px;font-size: 14px;font-weight: bold;");
	            
	            // 显示图标
//	            if (hnode.getImage() != null) {
//	              HtmlGraphicImage image = (HtmlGraphicImage) app
//	                  .createComponent(HtmlGraphicImage.COMPONENT_TYPE);
//	              image.setUrl(hnode.getImage());
//	              image.setStyle("margin: 0px 10px;");
//	              hOL.getChildren().add(image);
//	            }

	            
	            // 显示文字
	            HtmlOutputText text = (HtmlOutputText) app
	                .createComponent(HtmlOutputText.COMPONENT_TYPE);
	            String txt = fun.getName() + "<br/>";
	            text.setValue(txt);
	            text.setEscape(false);
	            hOL.getChildren().add(text);
	            panel.getChildren().add(hOL);        
	        }
	        layout.getChildren().add(panel);
	    }
	  }


}

 

其中funciton和functiontype是多对一得关系。。。。。这我就不多说了想必大家也都能理解。。效果见附件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
 JSF2.xdatatable分页控件与左侧菜单最简单应用   JSF2.x,功能强大,使用方便。全世界使用JSF的人越来越多。而且也有很多很好的控件给发出来了,如:richfaces、primefaces、myfaces等,就日前来讲primefaces功能很强大,控件很多,但有一点不好就是不支持IE6,特别是下拉列表,p:dialog等,其它的分页p:datatable实际使用起来总有不如意的地方。richfaces还支持可视化开发,可惜就是控件开发进度相比其它的慢了很多。下面帖我的控件的使用方法:   下载地址:http://download.csdn.net/detail/ptianfeng/4802713 一、分页具体使用方法如下(不多说,直接给你些颜色看看): 1. xhtml文件:    <html xmlns:ems="http://www.ems.com.cn" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:dataTable id="tableId" value="#{userlogMBean.defaultDataModel}" var="var" rows="10"> <h:column> <f:facet name="header"> <h:outputText value="" /> </f:facet> <h:outputText value="#{var.sqlid}" /> </h:column> </h:dataTable> <ems:page id="pageId" for="tableId" maxPage="5" /> 2. 相应的Managedbean: [java] view plaincopy /** * EMS 11185 限时未达邮费奉还 * @author 螃蟹 */ @SuppressWarnings(value = "serial") @ManagedBean(name = "userlogMBean") @ViewScoped() public class UserlogMBean extends PageListBaseBean implements Serializable { public PagedListDataModel getDefaultDataModel() { if (defaultDataModel == null) { defaultDataModel = new PagedListDataModel(pageSize) { public DataPage fetchPage(int startRow, int pageSize) { ArrayList<UserlogVo> dataList = new ArrayList<UserlogVo>(); List<Userlog> list = dao.getObjectList(jpql, pageSize, startRow); if (list != null) { for (Userlog u : list) { UserlogVo vo = new UserlogVo(); vo.setSqlid(u.getSqlid()); vo.setCode(u.getCode()); vo.setDate(u.getDate()); vo.setStation(u.getStation()); vo.setUserid(u.getUserid()); vo.setText(u.getText()); dataList.add(vo); } } int size = dao.getCountOption(jpql); DataPage dataPage = new DataPage(size, startRow, dataList); return dataPage; } }; } return defaultDataModel; } } 提示:关于PageListBaseBean更多的信息,可以参阅我在百度的blog(百度改版后,让我很QF,所以转到CSDN来了): http://hi.baidu.com/kittopang/item/19af4e37c6ede2fae6bb7a11   至此,分页已经实现。下面是使用截图:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值