Displaytag is a huge disappointment

Source: Internet
Author: User
Tags comparable

First of all, let's write down the learning contents of the past few days.

Then, based on the defects of displaytag and the solution, we will propose our own infinite disappointment.

OK. The column is started,

Displaytag learning notes Summary (1)

6. subset of the List
<Display: Table name = "mylist" offset = "M" length = "N"/>
Offset is the sequence number of the first data in mylist.
Length is the number of records displayed.

7. automatically set the link
The content of this column can be used as a link, and the URL of the connection is consistent with the content.
Of course, a URL must be in a valid format; otherwise, no connection is established after the URL is written.

(
This function is generally used.
Because the connection content is usually different from the displayed content.
)
Of course, you can specify all links in a column as the same connection in <display: column href = "">.
Or <display: column> <a href = ""> sdfs </a> </display: column>.

!!! So what if the connected URL is not column content and the links in each row are different?
It is like the advertisement list has a merchant name, and the Merchant name is a connection to the merchant's specific information page.
The connection URL must be different. What should I do?
 
I don't know yet. Let's look down.

8. Use the decoration class to convert data.
 

<Display: Table name = "test" decorator = "org. displaytag. sample. wrapper">
Used to convert data content. It is generally used to format information.
This class must inherit tabledecorator.
By the way, we will introduce a formatting time package org. Apache. commons. Lang. Time. fastdateformat;
Java. Text. decimalformat;
 
The idea is to overwrite the getxxx method of the specific type in the list.
This. getcurrentrowobject () to get the data of the current row.
This. getlistindex () obtains the serial number of the current row.
Then it is converted to the specific type stored in the list, and the data of a column is obtained.
Returns formatted data.

!!!! In addition, I have seen some getxxx methods added to the decoration class, which are not defined in listobject.
I still don't know what the benefits of doing so?
 
<Display: column property = "date" decorator = "org. displaytag. sample. longdatewrapper"/>
In this way, only one column of data is formatted and columndecorator must be inherited.
Implementation: String decorate (Object columnvalue) method. This method also accepts an object parameter,
This parameter is a specific property value of the object. It is directly converted to the corresponding type, formatted, and a string is returned.

9. Create a dynamic link.
You can create a dynamic link in either of the two ways.
The first method is directly used on the page.
<Display: column href = "baseurl" paramid = "paramid"/>
Http: // baseurl/paramid = columnvalue
<Display: column href = "baseurl" paramid = "paramid" paramname = "name" paramscope = "Scope"/>
Http: // baseurl/paramid = Name value in the scope
<Display: column href = "baseurl" paramid = "paramid" paramproperty = "propertyname"/>
Http: // baseurl/paramid = attribute value whose name is propertyname

This method is very effective for processing simple links, but if the Link parameter value is obtained by querying the database and other complex methods, this method
No. In this case, the second method must be used.

The second method is to obtain the connection in the decoration class.
The decoration class defines some getxxx methods, so you can use <display: column propety = "XXX"...> to use the decoration class de
Getxxx method. Well, in this way, get the row object in the getxxx method of the decoration class, so that all attributes of the object can be obtained,
It is easy to check the database or complete the judgment logic of the responsible person. Don't forget to assemble it and write it as
<A href = "..."> This string is returned.
Well, you can get the assembled "A" in one sentence on the page. <Display: column propety = "XXX"...>

The second method is better, because it can be more flexible. Write as much as you want. The first method is simple implementation.
 
10. Flip the page.
1. How to obtain the serial number of each row?
<Display: Table id = "XXX"...>
Use <% = pagecontext. getattribute ("xxx_rownum") %>.
However, <C: Out value = "$ {row_rownum}"/> is not easy to use. I don't know what the difference is.

Page turning is simple. In <display: Table pagesize = "M">, you can specify the number of pages.
The index for changing pages, top and bottom pages, and so on are automatically displayed.
It is really convenient. But the problem is that a lot of things are uploaded at a time, and the performance is poor. Wait for a while to see how to improve.

11. Automatic Sorting
<Display: Table name = "sessionscope. stest" defaultsort = "1" defaultorder = "descending">
<Display: column property = "ID" Title = "ID" sortable = "true" headerclass = "sortable"/>
You can set which columns are sorted by default, in ascending or descending order. In this example, the first column is set in descending order by default.
Each object in a column must implement the comparable interface to be set to sortable = "true ".
If comparable is not implemented, you must write a decoration class.
Note that,
It only sorts the current page. Instead of all. Pay special attention when turning pages.
To sort all data, you must re-write the action to send a new list to the webpage.

12. How to group
Group by column.
This function is really good.
<Display: column property = "city" Title = "city" group = "1"/>
<Display: column property = "project" Title = "project" group = "2"/>
In this way, not only results can be grouped, but duplicate data can also be omitted, such as the city column and the project column have
Rows A, B, A, and B are not displayed in the second row.

You can only group the current page.

Note: The first column must be 1 and the second column must be 2; otherwise, an nullpoint error occurs.

13. Statistics
Good stuff. You can collect statistics on groups or all rows.
It mainly relies on the tabledecorator class finishrow () to return the statistical result, which is displayed on the page.

The tabledecorator class method getdecoratedobject () obtains the entire result set. It is generally converted to list, because in most cases the result
Is stored in the list.
Public final string finishrow () {} executes this method when a row ends. Therefore, it is used to determine whether to calculate city statistics,
Or all statistics.
It is equivalent to event processing. The returned string is also displayed on the page. In this example, <tr> <TD>... </TD> <tr> is returned.
In this way, the table is nested into three rows. It is sufficient to display statistics.

 

14. Export data
Very simple. Set export = "true" in talbe. You must set export. xml = true in the configuration file to export the XML file.
PDF, Excel, HTML, and CSV files.
The syntax <display: column media = "CSV excel" indicates whether a column is displayed in a certain format "..
If this parameter is not set, it is displayed in all formats.

Note:
The contained file cannot use this function. If you need to use this function, you can use a filter. I will study it later.

15. Configure displaytag.
Copy tabletag. properties from the classpath path of the application and name it displaytag. properties.
By default, the configuration in displaytag. properties is used. It is very easy to think about Chinese. Put displaytag_zh.properties in
In the classpath path.

Title is like Chinese: the default format is jstl resource file usage. So you have to learn about jstl first.
I understand how jstl. FMT uses resource files. Well, jstl must first specify a resource file with FMT: bunlle before
Using this resource file in his body is quite troublesome.

What about displaytag? It is not so troublesome. If it is used together with Struts, the resource file for struts is of course the most reasonable.
You must define
Parameter, # locale. provider = org. displaytag. Localization. i18njstladapter
Locale. provider = org. displaytag. Localization. i18nstrutsadapter
In this case, you can use the struts configuration file. I watched it for one afternoon. Ah, I am suffering from poor information.

The problem is: Use struts in combination. In the jstl environment only, how does displaytag use jstl resource files?
You must specify the resource file using <FMT: bundl> as in the jstl environment, and then put the displaytag tag to its body.
Then you can use the jstl resource file !!!! (Fortunately, I first read the jstl method for using resource files)

16. There are more than two tables on one page.
You only need to configure different IDs for each table.

17. There are also tables in the table.
It is very simple. As long as
<Dispaly: column>
(Add <display: Table...> here...
</Display: Table>)
</Display: column>
 


18. End of the header table
Very simple: <dispaly: caption> <display: footer> just use it like <display: column>.
Note: The <display: footer> content must be <tr>... </tr>

19. The values in the table are truncated and blank.
<Display: column property = "nullvalue" nulls = "false"/>
<Display: column property = "longdescription" maxlength = "10" style = "whitespace: nowrap;"/>
Very simple.

OK. It's almost time to go .!!!!!

========================================================== =====
Key:
20. How to paging.
 
Because the displaytag paging mechanism needs to upload all records to it at a time, it is not suitable for many recorded items. If you still need to use
Displaytag has to give up some of its functions. The rational way is to just let displaytag get a list page. In this way, displaytag is not needed.
Or write customertag, or use jsppager tag.

Many people question this method, because it reduces the displaytag light by at least half, because it cannot be used because of its many functions,
For example, the sorting function can be used to globally sort all lists. If only one page of data is transmitted at a time, global sorting is no different from page sorting.
The global sorting function of displaytag is declared useless.

<Display: Table name = "mylist" offset = "M" length = "N"/> this function is basically useless.

So what else can we do with it? Displaytag has its advantages even if it is useless. For example
1. Table Nesting is supported.
2. Supports CSS so that you can write a small amount of code to make the program more concise. You have to define a set of CSS and use it globally.
3. In addition, it supports truncation of long strings so that you do not need to use your own methods on the page.
4. Implement complicated logic to generate dynamic links. This is also a benefit.
5. You can easily use struts resource files. So that it can be well internationalized.
6. filter NULL values.

Disadvantages:
1. grouping cannot be used, and statistics cannot be used. It is meaningless to count only the current page.
2. the sorting also changes to the sorting of the current page. It doesn't mean much.
3. Export is also exported to the current page.

Alas, in general, displaytag is actually used. It's like a feather-dropping peacock. The gorgeous stuff is lost. Unfortunately, it took me a week,
There are also 16 hours to study it in absolute time.

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.