What does JSF bring?

Source: Internet
Author: User
At the beginning, I took a fancy to JSF because of the following benefits:
1. Use the same El to obtain or display form data. The El before JSF can only get but cannot set;
2. The MyFaces Implementation contains many "dazzling" components, such as the drop-down menu, tree control, and date Selection control, which are extremely convenient to use.
As a result, JSF development is used in a small project, and it is found that this thing also brings a lot of trouble than before, take the common database operations-query, modify, insert, and delete to illustrate the existing troubles of using JSF:
1. query. For small data volumes, you can do everything with a single able. However, pagination of large data volumes is troublesome, because the pagination of datatable is to retrieve all the data and display it on another page, in large data volumes, you can choose which page to view. There is a general paging storage process on the Internet. You only need to pass a series of parameters (page number, sorting basis, size of each page, etc.) to it to obtain data on a certain page. If the parameters are directly transmitted through the URL, It is very convenient for the server to call the stored procedure based on the parameters. However, JSF does not pass parameters through URLs, and the process of processing the entire page is complicated and not as intuitive as it was previously. Someone changed the implementation method of datamodel so that it can retrieve only one page of data at a time. The effect is achieved, but to jump to a page, you can only click the link, you cannot enter a URL (that is, you cannot add a page to your favorites folder ). Some experiments have been conducted over the past two days. In JSF, parameters can still be passed through URL. In backing bean, URL parameters can be obtained through valuebinding's getvalue, then, get the corresponding content from the database based on the parameters, generate the bean of an object, and then display it on the page. However, it seems like servlet.
You can configure the get or post mode for form submission. However, currently, only post is allowed. In addition to being unable to add to favorites, refresh is not allowed (the system prompts whether to resubmit the data), and the browser's back-up function is invalid.

2. modify. After displaying the data in the datatable, you can add a commanbutton to each row and call the getrowdata () method of datamodel in its action method to obtain the data of the row, save the data in the bean of a request range, and then switch to another page to display the bean content through an editable form, where the bean content can be modified and submitted. Because the forward method is used for redirection, the page displayed by the URL is the page displayed by the data. As long as the page is refreshed, the page displayed by the data is returned instead of the page modified; if you do not want to modify it, click the back button of the browser. Although you return to the page where the data is displayed, the commandbutton above is invalid. For example, if you click the modify button, there is no response, the page must be refreshed and then clicked.To solve this problem, I used the URL-based parameter passing method. Specify the ID in the URL to specify the object to be modified. In the backing bean constructor on the modification page, read the URL parameter to obtain the ID, then, you can query the database to obtain other content of the object and then display it on the page. In this way, you can refresh and move back.

3. added. The addition and modification can be displayed on the same page, but the commandbutton corresponds to different action methods. For example, the "modify" button corresponds to update, and the "add" button corresponds to create, use the update statement and insert statement of the database in the two methods respectively. No ID is added, and the ID is already available when you modify it.

4. Delete. In the able that displays data, you can add a commandbutton to each row. In its action method, read the row of data and obtain the ID. Then, execute the SQL Delete Statement, which is relatively simple.

no matter what you do, you can't do without three things: Page, configuration file, and backing bean. The page is the thing at the presentation layer. It is responsible for connecting the things on the page with the backing bean. The configuration file specifies the name, class, scope of use, and navigation rules of the backing Bean used on the page ). Backing bean is the logical part of the Program . Even if you implement the simplest functions, such as displaying the value of a variable, these three items are essential.
when modifying the page, you do not need to restart the server, but you must check the effect in the new session. The simplest way is to turn off the browser and open a new one, view the result. After modifying the configuration file and backing bean, you must restart the server. Therefore, debugging JSF is very troublesome.

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.