Tuesday, March 18, 2008

Passing Parameters In A Data Table Using JSF

Some workings cognition of J2EE or JSF is assumed for this article.

Like some of you I've been frustrated with this engineering known as JSF or Java Waiter Faces. There are respective different spirits out there that are built on the shoulders of JSF. For case Oracle's ADF (Application Development Framework). Prophet ADF Faces Components is a set of over a 100 JSF constituents that allow you construct a richer user interface for your Java electrical engineering applications. Prophet ADF Faces also includes many of the model characteristics most needed by JSF developers today.

That is great, and in many ways it will do life easier to develop in a JSF environment. Some points you will happen available in these "add on" bundles have got a existent benefit. For instance, as of the day of the month of this article, I was very surprised that a File Upload is a characteristic still not implemented in JSF in regard to using natural jsf tags. There are ways to carry through this undertaking in JSF but they are not native JSF approaches. The procedure is a "no brainer" in just about every other model available today, including asp.net.

Another simple undertaking (I thought) was having a information tabular array nowadays the consequences of a question in an editable format. Possibly to update a user record or shopping cart. After working in other engineerings it was very efficient to go back a consequence set to a information tabular array physical physical object and allow that object take attention of some of the fiddling behaviours and features of the tabular array itself. When Iodine started exploring JSF I was frequently and at every bend becoming more than than than and more defeated in trying to reduplicate some of the most basic of procedures similar to managing records through information tables.

There are not a whole batch of resources out there yet on JSF although it is growing steadily, and I establish that all too often the resources that I was finding on the cyberspace either didn't use to the more simple undertakings or the information was just completely wrong. One illustration of that was that it was stated in one article I read that you cannot usage bid buttons inside of a JSF information table. The recommendation was to utilize JSF hyperlinks instead when trying to execute an action from a information tabular array owed to a bug in the model that prevented bid button actions to open fire if the button resided inside of a information table.

At first Iodine thought "you've got to be kidding me"! Then I remembered that I've been determination a just amount of "bogus" information in sees to JSF development so I decided to make additional research and discovered that information to be less than accurate as well.

I simply had to happen a manner to dwell a information tabular array through a consequence set and acquire a bid button to open fire an action and go through all of the information in the information tabular array to the championship edible bean to update the record. Multiple bid buttons would be as well as concealed Fields pertaining to Idaho Numbers and so forth. Pretty basic material and we've all done it before with relative ease.

It turned out that the solution was in fact a simple one. "Binding". You've heard about it and read about it. But this attack was something a small different as far as I could find.

Many of the blogs and articles that I read dealt with passing the values as parametric quantities and following the stairway to define the parametric quantities in faces.config data files etc., then retrieving the parametric quantities in a championship bean. Processing the passed information required another set of processes to use correspondence to each of the field parametric quantities passed and then processing could begin.

That seemed like a whole heck of a batch to me just to recover word form data. Then it occurred to me that I should be able to "bind" a textual matter field constituent on a page to a championship bean. Once it is jump then all Iodine have got to make is infusion the data. And that's all there is to it. My question returned consequences and pre-populated somes information tabular array including textual matter Fields with the values of the question pre-populated inch the textual matter fields.

Each 1 of those textual matter Fields was jump to a "HtmlInputText" type in my championship bean. It was not a String type like other attacks define. Doing that makes necessitate you to map parametric quantities and dwell that String variable through your set methods once the word form is submitted.

What I establish is that if I bind my textual matter field to a place of textual matter field type that it solved my job of passing values from a information table, and I didn't have got to define parametric quantity Fields anywhere in any xml file. Now that Iodine had that figured that out I needed to calculate out how to acquire the value of that place that I've jump my word word word form field to, well why not getValue()?

I personally hadn't seen any illustrations online or in books for retrieving the value from a form binding it to the type of form component it was and simply utilize the getValue() to draw out the value of the object. Used like this getParameterFromForm().getValue().

Let me clear up that I am NOT saying that trying this attack isn't documented anywhere, I happen it hard to believe that I've had some shot of mastermind that no 1 have had before in the human race of java, especially since I'm coming from .NET and ColdFusion.

After doing that I no longer had any jobs passing word form information to my championship bean. I was able to dynamically dwell information tabular arrays with any figure of records including any figure of bid buttons within that information tabular array and I didn't have got to concern myself with remembering to define parametric quantities in any other countries of the application.

So put option simply you can bind your word word form Fields to places of the same type in your championship bean, and then pull out the value of that physical object using getValue() if you prefer over utilizing parametric quantity twine correspondence and similar attacks for processing form data. I establish it to be easier and less clip consuming which have costs associated to it as well.

Labels: , ,

0 Comments:

Post a Comment

<< Home