`

jee6 学习笔记 4 - CRUD 1: Primefaces datatable, sorting and paging

阅读更多
实现简单的搜索功能:搜索学生姓名,同时利用primefaces datatable来显示结果。

screenshot: (Note, i've changed the theme from "sam" to "afterwork")



Backing bean StudentSearch:
package com.jxee.action.student;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.log4j.Logger;
import com.jxee.ejb.student.StudentDAO;
import com.jxee.model.student.Student;

@ManagedBean(name="ss")
@SessionScoped
public class StudentSearch {

  private static final Logger log = Logger.getLogger(StudentSearch.class);
  
  private List<Student> searchResultList;
  @EJB private StudentDAO dao;

  private String nameFilter;
  private int maxRows = 50;
  

  public String findByName() {
    searchResultList = dao.find(this.nameFilter, maxRows);
    return "studentSearch";
  }

  public String getNameFilter() {
    return nameFilter;
  }

  public void setNameFilter(String afilter) {
    this.nameFilter = afilter;
  }

  public int getMaxRows() {
    return maxRows;
  }

  public void setMaxRows(int maxRows) {
    this.maxRows = maxRows;
  }

  public List<Student> getSearchResultList() {
    return searchResultList;
  }

  public void setSearchResultList(List<Student> searchResultList) {
    this.searchResultList = searchResultList;
  }
  
  public int getSize() {
    return this.searchResultList != null ? this.searchResultList.size() : 0;
  }
}


StudentSearch.xhtml
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
    
<h:head>
	<title>student search</title>
</h:head>

<h:body>
    
    <h:form id="form">
	    <p:panel header="Student Search Form">
	        <h:panelGrid columns="3">
	            <h:outputLabel value="Name"/>
	            <h:inputText value="#{ss.nameFilter}"></h:inputText>
	            <h:commandButton type="submit" value="Search" action="#{ss.findByName}"/>
	        </h:panelGrid>
	    </p:panel>
	    
	    <br/>
	
		<p:panel style="border:0px">
			students found: #{ss.size}
		</p:panel>
	
		<!-- search result list -->
	   	<p:dataTable id="stuDataTable" 
	   		var="st" 
	   		value="#{ss.searchResultList}" 
	   		paginator="true" rows="3">  
	   	
		    <p:column headerText="name" sortBy="#{st.name}">  
		        <h:outputText value="#{st.name}" />  
		    </p:column> 
		    
		    <p:column headerText="mobile" sortBy="#{st.mobile}">  
		        <h:outputText value="#{st.mobile}" />  
		    </p:column>  
		    
		    <p:column headerText="age" sortBy="#{st.age}">  
		        <h:outputText value="#{st.age}" />  
		    </p:column>
		    
		    <p:column headerText="created date" sortBy="#{st.created_date}">  
		        <h:outputText value="#{st.created_date}">
		        	<f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
		        </h:outputText>  
		    </p:column>
		    
		</p:dataTable> 
		
    </h:form>
    
</h:body>
</html>


小姐一下:

1, it's quite simple to use the primefaces tag <p:datatable> to render search result list.

2, sorting can be achieved by <p:column> attribute "sortBy" and it takes EL expression. however, backing bean needs to be session scoped in order to hold the result set for sorting.

3, paging can be easily achieved by attribute paginator="true" rows="3".

Next will take a look at row selection and view details.
  • 大小: 26.6 KB
分享到:
评论

相关推荐

    eclipse-jee-mars-1-win32-x86_64.7z

    eclipse-jee-mars-1-win32-x86_64.7z eclipse-jee-mars-1-win32-x86_64.zip 我打的 7z 压缩包 关于有 Alt + / 不起作用解决办法: window -&gt; General -&gt; Keys -&gt; Content Assist -&gt; Binding: 改为 Alt + / When:...

    eclipse-jee-2023-09-R-win32-x86-64.zip

    "eclipse-jee-2023-09-R-win32-x86_64.zip" 是Eclipse针对2023年9月发布的一个更新版,专为Windows 64位操作系统设计。 在Windows系统上安装和使用Eclipse-JEE,你需要了解以下关键知识点: 1. **安装步骤**: - ...

    开发工具 eclipse-jee-mars-2-win32

    开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32...

    eclipse-jee-neon-1a-win_64

    eclipse-jee-neon-1a-win_64

    eclipse-jee-2023-09-R-linux-gtk-x86-64.tar.gz

    1. **下载**:访问Eclipse官方网站,找到"eclipse-jee-2023-09-R-linux-gtk-x86_64.tar.gz"的下载链接,将其保存到Linux系统的本地目录。 2. **解压**:Linux提供了命令行工具来解压tar.gz文件。打开终端,使用以下...

    eclipse-jee-2018-09-win32-x86_64.zip

    "eclipse-jee-2018-09-win32-x86_64.zip" 是Eclipse针对Windows 32位和64位系统的2018年9月版本的下载包。此版本被称为Eclipse SimRel(Simultaneous Release),意味着它是在Eclipse年度统一发布计划中的一部分,...

    eclipse-jee-mars-R-win32-x86_64位官方绿色版.zip

    Eclipse-jee-mars-R-win32-x86_64位官方绿色版.zip是一个针对Windows平台的64位版本的Eclipse集成开发环境(IDE)的压缩包,特别为Java企业级(J2EE)应用程序开发设计。该版本发布于2015年6月30日,是当时Eclipse ...

    eclipse-jee-2021-12-R-win32-x86_64.zip

    Eclipse IDE for Enterprise Java and Web Developers (eclipse-jee-2021-12-R-win32-x86_64.zip)适用于Windwos x86_64

    eclipse-jee-2022-06-R-win32-x86_64.zip

    在解压eclipse-jee-2022-06-R-win32-x86_64.zip后,我们会得到一个名为“eclipse”的文件夹,这个文件夹包含了整个IDE的所有组件和配置。启动Eclipse IDE,用户会看到熟悉的界面,包括工作区(Workspace)、透视图...

    jee6 学习笔记 6.3 - @Asynchronous

    在Java企业版(Java EE)6中,`@Asynchronous`注解是一个非常重要的特性,它使得开发者可以方便地在应用程序中实现异步处理。这个注解是Java EE并发编程的一部分,主要应用于EJB(Enterprise JavaBeans)环境,用于...

    eclipse-jee-2021-12-R-win32-x86_64

    eclipse-jee-2021-12-R-win32-x86_64 eclipse-jee-2021-12-R-win32-x86_64 eclipse-jee-2021-12-R-win32-x86_64

    eclipse-jee-2019-09-R-win32-x86_64

    文件名称: eclipse-jee-2019-09-R-win32-x86_64.zip 文件大小: 352 MB (369,940,487 字节) MD5: fc821116680da0bca7bd7a1d9e0b48b7 SHA1: 14be627915d2e11b618434d48ddf9e3ec3849392 SHA256: 3808c394d16153ceb429...

    eclipse-jee-2023-12-R-win32-x86-64.zip

    eclipse-jee-2023-12-R-win32-x86_64.zip 适用于Windows系统

    eclipse-jee-2022-12-R-win32-x86-64

    eclipse-jee-2022-12-R-win32-x86_64,rar压缩包格式,解压即用。 安装教程:https://danbaku.blog.csdn.net/article/details/128600309

    eclipse-jee-neon-1a-win32.part1.rar 最新版

    eclipse-jee-neon-1a-win32.part1.rar 官网最新版 共6个分卷,全部下载完才可以解压。

    eclipse-jee-2020-09-R-win32-x86_64.zip

    标题中的“eclipse-jee-2020-09-R-win32-x86_64.zip”指的是Eclipse IDE for Java EE Developers的2020年9月版本,适用于Windows 32位和64位系统的安装包。Eclipse是一款著名的开源集成开发环境(IDE),广泛用于...

    eclipse-jee-mars-1-win32-x86_64.rar

    《Eclipse JEE Mars 1 for Windows 64位:构建Java EE网页代码的强大工具》 Eclipse JEE Mars 1-win32-x86_64.rar 是一个专为Windows 64位操作系统设计的Java EE开发环境压缩包。Eclipse是一款广泛使用的开源集成...

    eclipse-jee-2020-12-R-win32-x86_64

    《Eclipse IDE for Java开发者:深入解析eclipse-jee-2020-12-R-win32-x86_64》 Eclipse IDE,全称集成开发环境(Integrated Development Environment),是全球广泛使用的开源Java开发工具。该版本"eclipse-jee-...

    jee6 学习笔记 1 - 开发环境的配置

    NULL 博文链接:https://jxee.iteye.com/blog/1575432

Global site tag (gtag.js) - Google Analytics