In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how JSF to pass parameters through URL, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
I took a fancy to JSF because I took a fancy to several benefits:
1. Use the same EL to obtain or display form data. The EL before JSF can only be get but not set.
2. There are many "cool" components in MyFaces implementation, such as drop-down menus, tree controls, date selection controls, etc., which are extremely easy to use.
So we use JSF to develop in a small project, and we find that this thing also brings a lot of more trouble than before. Take the very common database operations-query, modify, insert, delete-to illustrate the trouble of using JSF to implement:
1) query. For a small amount of data, everything can be done with a dataTable. However, paging with a large amount of data is more troublesome, because the paging of dataTable takes out all the data and then displays it page by page, while in large amounts of data, you usually take any page you want to see. There is a general paging stored procedure on the Internet, which can obtain the data of a page as long as a series of parameters (page number, sorting basis, page size, etc.) are passed to it. If you pass parameters directly through URL, it is convenient for the server to call stored procedures based on the parameters. However, JSF does not pass parameters through URL, and the whole process of page processing is more complex, not as intuitive as before. Someone has changed the implementation of dataModel so that it takes only one page of data at a time, and the effect is achieved, but to jump to a page, you can only click on a link, not by typing URL (that is, you can't add a page to your favorites).
Some experiments have been done in the past two days. In JSF, you can still pass parameters through URL. In Backing Bean, you can get URL parameters through ValueBinding's getValue, and then get the corresponding content from the database according to the parameters to generate the bean of an object, and then display it on the page. But in this way, it seems to be about the same as servlet.
It would be nice if you could configure whether the form submission is get or post. However, at present, it can only be post, which will invalidate the browser's fallback function in addition to not being able to collect and refresh (will prompt whether to resubmit the data).
2) modify. After displaying the data in datatable, you can add a commanButton to each row, call the getRowData () method of dataModel in its action method to get the data of the row, save the data in a request range of bean, and then go to another page to display the contents of the bean through an editable form, where you can modify and submit. Because the forward method is used to turn, the page displayed by url is still the page displayed by the data. As soon as it is refreshed, it will go back to the page where the data is displayed instead of modifying it. If you don't want to change it, click the browser's back button. Although you have returned to the page where the data is displayed, the commandButton above has become invalid. For example, if you click the modify button, there is no response. You must refresh that page and click it again to be effective.
To solve this problem, I use URL to pass parameters. Specify which object to modify by specifying ID in URL. In the constructor of the backing bean of the modified page, read the URL parameter to get the ID, and then query the database to get the other contents of the object, and then display it on the page. This way it can be refreshed and backed up.
3) add. Additions and modifications can be displayed on the same page, but commandButton corresponds to different action method. For example, the "modify" button corresponds to update, and the "add" button corresponds to create. You can use the database update statement and insert statement in the two method respectively. There is no ID when you add it, but you already have ID when you modify it.
4) Delete. In the dataTable that displays the data, each row can add a commandButton, in its action method, read that line of data, get the ID and execute the DELETE statement of SQL, which is relatively simple.
No matter what you do, you can't do without three things: the page, the configuration file, and Backing Bean. The page is something in the presentation layer, which is responsible for linking the things on the page to Backing Bean. The profile specifies the name, class, scope of use, and navigation rules (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, all three things are essential.
When you modify a page, you don't have to restart the server, but you have to see the effect in the new session. The easiest way is to close the browser, open a new one, and view the results. If you modify the configuration file and backing bean, you must restart the server. So debugging JSF is troublesome.
These are all the contents of the article "how JSF passes parameters through URL". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.