js| Sort | data | show
The display and concealment of processing components in JSF, the sorting of data, etc. are very easy and straightforward, and are often analyzed and explained by textbooks as examples. The following example comes from a book called "Mastering JavaServer Faces Chinese" (slightly modified) that explains the use of the UI components in JSF by displaying (or hiding) the components and sorting the data.
First look at its interface a total of three (1) index.jsp,
(2) modifyinvoice.jsp, this modified invoice interface has a display (hidden) button, click to Show (or hide) part of the component.
(3) viewinvoices.jsp, display a list of all invoices. And can be sorted by invoice serial number and amount.
Mainly look at this page, when you click on the invoice invoice number, how to correctly return to the modifyinvoice.jsp page (in our own practice must encounter problems ah, the usual approach is the hyperlink with parameters). Of course, first of all, define the navigation rules in the Faces-config.xml file:
/viewinvoices.jsp
modifyinvoice
/modifyinvoice.jsp
From the source can know that this page through a tag to display all invoices.
...
Value= "#{invoice.invoicenumber}" action= "#{viewinvoicespage.modifyinvoice}" >
.....
On top of that, JSF calls the Viewinvoicespage.modifyinvoice method when we click on the serial number of the invoice.
Public String Modifyinvoice () { Facescontext facescontext = Facescontext.getcurrentinstance (); Uiviewroot root = Facescontext.getviewroot (); UIData table = (UIData) root.findcomponent ("Invoiceform"). Findcomponent ("table"); Invoicebean invoice = (Invoicebean) table.getrowdata ();
Facescontext.getapplication (). createvaluebinding ("#{modifyinvoicepage}"); Modifyinvoicepage detailpage = (modifyinvoicepage) binding.getvalue (facescontext); Detailpage.setinvoice (invoice); return "Modifyinvoice"; }
So it seems that when used When you mark the data, smart JSF uses GetRowData () to know that you clicked on the line (that is, the invoice number, which is actually a JSF to automatically add a row index to the HTML link), and then passes this line of data to the Modifyinvoice.jsp page.