Friday, September 17, 2010

JSF to pass parameters via URL



Had taken a fancy to JSF, because the Chinese and a number of benefits:

1, to obtain or display form data, you can use the same EL, JSF EL can only get can not be pre-set;

2, MyFaces realize there are many is the "flip" the components, such as drop-down menus, tree controls, date selection control, etc. is extremely easy to use.

Therefore, in a small project using the JSF development, with a discovered fact, this brings a lot of things are more trouble than before, the place, so they took a very common database operations - query, modify, insert, delete to illustrate the use of JSF to realize what trouble:

1) for inquiries. For the small amount of data, with a dataTable on everything buttoned up. However, relatively large amounts of data pages in trouble, because the paging dataTable is to take out all the data and then a page display, and a large amount of data usually need to see the next page to check which page. Web pages have a common stored procedure, as long as the number of parameters (page, sort, page size, etc.) to pass it, you can get a page of data. If the URL to pass parameters directly through the server under the parameter to call the stored procedure is a convenient things. But the JSF is not to pass parameters through the URL, and the page address in the process is more complicated, not intuitive as before. It was changed a bit dataModel way to achieve, to make it a time to take one of the data, the effect is achieved, but to jump to a page, but can only point link, can not enter the URL to get a (that is not to a page in the Add to Favorites).

Two days to do some tests, the JSF in or to pass parameters through the URL, in the Backing Bean in the getValue ValueBinding obtained by URL parameters, then according to parameters obtained from the database corresponding content, generate an object bean, and then displayed on the page. But this way, it seems almost Jiugen servlet.

If can be configured to set the form submission method or post method is get enough. However, all can now post, in addition to the consequences of such a collection can not be refreshed (if prompted to re-submit data), the will to disable the browser's back.

2) modification. In the datatable displayed in the data, you can add each line of a commanButton, in its action method called dataModel the getRowData () method to get the row data, the data stored in a request scope bean inside, and then turn to Another page can be edited through a form to display the contents of the bean, where you can modify, submitted. As the way forward is to use a turn, so the page url or data displayed of the page, as long as a refresh, the data show that on the back page and not the one that has; If you do not want to modify, click the browser back button, although the data displayed back to that page, but above commandButton has failed, for example, click the Modify button, nothing happens, have to refresh it a point to be effective again.

To solve this problem, I use a URL to pass parameters. ID specified by the URL to show what you want to modify the object, modify the page backing bean in the constructor to read the URL parameters to obtain the ID, then query the database by other elements of the object, and then displayed on the page . This can be refreshed, you can back.

3) Add. Can be added with the amendments to display the same page, but corresponding to different commandButton action method, such as "Edit" button corresponding to the update, "Add" button corresponds to create, in the two method were used in the database update statements and insert statements can be. The new time is not ID's, when it has been modified with ID.

4) Delete. Display data in the dataTable, each line can add a commandButton, in its action method, the reading of the line data, the ID after the execution of the DELETE SQL statement can be, relatively simple.

No matter what it does, can not do without three things: pages, configuration files, Backing Bean. What page is the presentation layer, is responsible for what page to link with the Backing Bean. Configuration file specifies the page to use Backing Bean's name, class, range of use, as well as navigation rules (Navigation Rules). Backing Bean is part of the program's logic. Even if the realization of the simplest functions, such as display a variable value, these three things are essential.

When the page changes, although not restart the server, but in the new session in order to see the results, the simplest way is to turn off the browser, open a new, view the results. Modify the configuration files and backing bean must restart the server. So JSF is very cumbersome to debug.







Recommended links:



Pause Slideshow tips



MMOG / LE assessment of the road Troika



Vob format



Effects Authorware Word Album (2)



Recommend NEWS Servers



Training of new employees approach HR



Lists System Maintenance



VEGAS DVD The Road (2) DVD menu MAKING



Wizard Encryption Tools



Let Gmail Tell Friends Where You Live



How to quickly assess the adoption of CMMI



Convert .flv to .wmv



Mr. Ma, please do not anger me



F4v to mp4



Wmv to mpeg converter free



No comments:

Post a Comment