How to Create JSF table components (including source code)

Source: Internet
Author: User

On Tuesday, I was in a hurry to demonstrate the Table control of RichFaces, But Liu said that RichFaces is too complicated and not suitable for us, and there are still a lot of bugs (I cannot verify these :). So he took out a table written using a bunch of JSP + Servelet + beans and told me that I suspect that JSF can make this thing, I believe that JSF can be used on the Development Platform (Note: I am a part-time architect of this Eclipse Development Platform) when you use pure JSF to make the same table component. I was wondering, since you are using JSP/Servlet, and JSF is based on Servlet technology, how can it not be implemented? Three days! I have always believed that technology lies in the use of technology, not the technology itself.

Download the JSF table component

First look at the figure:

 

Let's look at the corresponding JSF tag.

 
 
  1. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. < Html Xmlns=Http://www.w3.org/1999/xhtml" 
  3. Xmlns: h=Http://java.sun.com/jsf/html" 
  4. Xmlns: f=Http://java.sun.com/jsf/core" 
  5. Xmlns: ui=Http://java.sun.com/jsf/facelets" 
  6. Xmlns: cby="Http:/www.lifesting.com/jsf"> 
  7.  
  8. < Ui: composition Template="/Tpl.xhtml"> 
  9.  
  10. < Ui: define Name="PageTitle">Table display</Ui: define> 
  11. < Ui: define Name="PageHeader">Country</Ui: define> 
  12. < Ui: define Name="Body"> 
  13.  
  14. < H: form> 
  15. < H: panelGrid Columns="1"> 
  16. < H: message For="Mytable" /> 
  17. </H: panelGrid> 
  18. < Cby: rns Text="Page settings" TableFor="Mytable" /> 
  19. < Cby: filter Text="Filter policy" TableFor="Mytable" /> 
  20. < Cby: delete TableFor="Mytable" /> 
  21. < Cby: table Id="Mytable" Var="Rec" Checkable="True" IdField="Code" 
  22. Bean="Country"> 
  23. < Cby: column Field="Name" Sortable="True" Filterable="True" 
  24. Width="200" Value="Name"> 
  25. < H: outputText Value="# {Rec. wrapped. name }"></H: outputText> 
  26. </Cby: column> 
  27. < Cby: column Field="Region" Sortable="True" Filterable="False" 
  28. Width="100" Value="Region"> 
  29. < H: outputText Value="# {Rec. wrapped. region }"></H: outputText> 
  30. </Cby: column> 
  31. < Cby: column Field="SurfaceArea" Sortable="False" Filterable="True" 
  32. Width="150" Value="Surface area"> 
  33. < H: outputText Value="# {Rec. wrapped. surfaceArea }"></H: outputText> 
  34. </Cby: column> 
  35. < Cby: column Field="Population" Sortable="True" Filterable="True" 
  36. Width="100" Value="Population"> 
  37. < H: outputText Value="# {Rec. wrapped. population }"></H: outputText> 
  38. </Cby: column> 
  39. < Cby: ds /> 
  40. </Cby: table> 
  41. </H: form> 
  42. </Ui: define> 
  43. </Ui: composition> 
  44.  
  45. </Html> 

Because the development platform is ultimately centered on BO, this table component sets bean and then obtains data through Hibernate.

In addition to using JSF + Facelet, this JSF table component does not have any other page technology. The code is concise, non-abstract, and there are comments in it. For Beginners, refer to it.

Main functions of the JSF table component:
1. Set the column filterable attribute (true/false) to filter data. (currently, this attribute is implemented as a left Match. For example, if the input is Sa, it starts with Sa)
2 paging navigation
3. Set the column sortable attribute (true/false) to perform positive/reverse sorting on a column.
4. Change the page record size. The default value is 20 records/page.
5. Set the checkable attribute of the table to true. The table will use one more column for selection.
6. checked records can be deleted in batches.

This component only takes into account functions, and does not consider appearance. If you think you can use it, modify its html attribute settings.

Installation:

1. the attachment is a Maven project that must be installed with maven.
2. Install the MySQL database, start MySQL, and run
Create database world
3. Find the world. SQL under the project, and assume the path is/a/B/c/world. SQL. Use the MySQL source command.
Use world
Source/a/B/c/world. SQL
4. Modify the MySQL database username/password in hibernate. cfg. xml under the project.
5. run mvn jetty: run to start
6. Enter http: // localhost: 8080/jsftry/in the browser to see the effect.

About debugging:
1. Download an Eclipse JEE version
2. Execute mvn eclipse: clean eclipse: eclipse-DdownloadSources = true-Dwtpversion = 1.5 in the project directory.
3. import this project in eclipse workspace

Although I haven't used Java for a long time at work, I still feel that Java is very productive. JSF, Hibernate, Maven, and Eclipse are comparable to each other.

  1. JSP line feed solution
  2. Comparison between JSP development framework and Servlet-based Tapestry
  3. JSP blocks the JSF light like a dark cloud
  4. JSF technology details
  5. Learning the basic concepts of JSP: Nine implicit objects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.