Monday, August 20, 2012
Passing parameters in a data table Using JSF
Some knowledge of J2EE or JSF is assumed for this article.
As some of you have been frustrated with the technology known as Java Server Faces or JSF. There are different flavors out there that are built on the shoulders of the JSF. For example, Oracle ADF (Application Development Framework). Oracle ADF Faces Components is a collection of over 100 JSF components that create a richer user interface for Java EE applications. Oracle ADF Faces also includes many features of the framework for JSF developers today.
Which is great, and in many ways makes life easier to develop in a JSF environment.
Some items that you will find available in these "add on" packages have a real benefit. For example, from the date of this article, I was very surprised that a File Upload is a feature not yet implemented in JSF than using natural JSF tags. There are ways to do this in JSF JSF approaches but are not native. The process is a "no brainer" in almost every other context now available, including asp.net.
Another simple task (I thought) was having a data table to present the results of a query in an editable format. Perhaps to update a user record, or a shopping cart. After working in other technologies, has been very effective to return a result set of an object data table and let the object take care of some mundane behaviors and characteristics of the table.
When I started exploring JSF often and every time I was increasingly frustrated in trying to duplicate some of the most basic processes like managing records through data tables.
There are a lot of resources out there still on the JSF, although it is growing, and I found that too often the resources that I find on the internet or does not apply to simple tasks or information was just completely wrong. An example of this is what was stated in an article I read that you can not use the control buttons inside a JSF data table. The recommendation was to use JSF hyperlinks, but when trying to perform an action from a table of data due to a bug that prevented the actions in the framework of the buttons order to fire if the button was residing within a table of data.
At first I thought "you've got to be kidding me!" Then I remembered that I find a fair amount of information "false" regarding the development JSF so I decided to do more research and found that the information must be less than accurate.
I simply had to find a way to populate a data table through a result set and get a command button to activate an 'action and move all the data in the data table to the backing bean to update the record. Control buttons and hidden fields exist on multiple id numbers, and so on. Pretty simple stuff and we've all done it before with relative ease.
It was discovered that the solution was in fact a simple. "Binding". You have heard and read about it. But this approach was something a bit 'different from what I could find.
Many blogs and articles I read dealt with the values passed as parameters and follow the steps to define the parameters in the file faces.config etc., then the recovery of the parameters in a backing bean. The processing of past data requested another set of procedures used for mapping each of the parameters of field, and then passed treatment can begin.
That seemed like a whole hell lot to me just to retrieve the form data. Then it occurred to me that I should be able to "bind" a text field component in a page to a backing bean. Once it is bound, then all I have to do is extract the data. And that's all there is to it. My query returned results and pre-populated a table of data, including text fields pre-populated with the query values in text fields.
Each of these text fields has been associated with a type "HtmlInputText" in my backing bean. He was not a String, as other approaches to define. Doing that needed to map the parameters and populate the String variable using methods once the form is submitted.
What I found is that if I bind my text field to a property of type text field that has solved my problem of passing values from a data table, and I had to define the parameter fields anywhere in any file xml. Now that I realized that I needed to figure out how to get the value of that property that I tied my form field, also because getValue ()?
I personally had not seen any examples online or in books to retrieve the value of a form factor binding to the type of form it was and just use the getValue () to extract the value of the object. Used as this getParameterFromForm (). GetValue ().
Let me clarify that I'm not saying try this approach is not documented anywhere, I find it hard to believe that I had some stroke of genius that no one had before in the world of Java, especially because they come from. NET and ColdFusion.
After that I never had any problem passing the form data to my backing bean.
I was able to dynamically populate the data tables with any number of records including any number of command buttons in the data table and did not have to remember to take care to define the parameters in other application areas.
So put simply, you can bind form fields to properties of the same type in the backing bean, and then extract the value of this object using getValue (), if you prefer using multiple mapping string parameters and approaches similar to the 'data processing module. I found it was easier and less time-consuming process has costs associated with it as well .......
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment