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.
- <! 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: h=Http://java.sun.com/jsf/html"
- Xmlns: f=Http://java.sun.com/jsf/core"
- Xmlns: ui=Http://java.sun.com/jsf/facelets"
- Xmlns: cby="Http:/www.lifesting.com/jsf">
-
- < Ui: composition Template="/Tpl.xhtml">
-
- < Ui: define Name="PageTitle">Table display</Ui: define>
- < Ui: define Name="PageHeader">Country</Ui: define>
- < Ui: define Name="Body">
-
- < H: form>
- < H: panelGrid Columns="1">
- < H: message For="Mytable" />
- </H: panelGrid>
- < Cby: rns Text="Page settings" TableFor="Mytable" />
- < Cby: filter Text="Filter policy" TableFor="Mytable" />
- < Cby: delete TableFor="Mytable" />
- < Cby: table Id="Mytable" Var="Rec" Checkable="True" IdField="Code"
- Bean="Country">
- < Cby: column Field="Name" Sortable="True" Filterable="True"
- Width="200" Value="Name">
- < H: outputText Value="# {Rec. wrapped. name }"></H: outputText>
- </Cby: column>
- < Cby: column Field="Region" Sortable="True" Filterable="False"
- Width="100" Value="Region">
- < H: outputText Value="# {Rec. wrapped. region }"></H: outputText>
- </Cby: column>
- < Cby: column Field="SurfaceArea" Sortable="False" Filterable="True"
- Width="150" Value="Surface area">
- < H: outputText Value="# {Rec. wrapped. surfaceArea }"></H: outputText>
- </Cby: column>
- < Cby: column Field="Population" Sortable="True" Filterable="True"
- Width="100" Value="Population">
- < H: outputText Value="# {Rec. wrapped. population }"></H: outputText>
- </Cby: column>
- < Cby: ds />
- </Cby: table>
- </H: form>
- </Ui: define>
- </Ui: composition>
-
- </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.
- JSP line feed solution
- Comparison between JSP development framework and Servlet-based Tapestry
- JSP blocks the JSF light like a dark cloud
- JSF technology details
- Learning the basic concepts of JSP: Nine implicit objects