This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I need to validate the data entered in each row(all columns inputTexts) in a datatable. I am using myfaces t:columns since the numbers of columns are dynamic. I need some ideas how to do validation for the data entered by the user in each row together. I bound the datatable to a backing bean property, I have a validator method in my backing bean and I am calling this method using a dummy hidden field's validator attribute. Inside the method, I am accessing the datatable via its property in the backing bean. But when I am stepping through the rows from the method, I find that they do not contain the latest data entered.
I understand that the data is not yet posted to the model at this point, I am still in validation phase. But then how will I be able to get hold of data of each inputtext while in validation phase? First of all is this the right way to do the validation?
Thanks for any help.
Joined: Sep 27, 2004
As a workaround, I am now validating in the action method in the backing bean - AFTER - the values are posted to model and then re throwing the same page if there are any invalid rows. Since I now cannot add an error message to the faces Context(I am now Invoke Application phase), I used an extra text column at the end of each row and populating it with messages in the event of any validation errors.
Although this solves the problem for now, I am really interested to know solution that does validation even before the values are posted to model.
After much mystification and pulling out of hair, I finally made a small webapp to test various combinations -- none of which work properly.
Suppose I have a 3-by-3 table of input fields backed by a DataModel, plus an additional input field that is NOT part of the DataModel, plus a hidden field that contains the hook to the validator.
When that validator runs, it loops through the rows and columns of the DataModel, accessing the UIInput fields and doing its thing. After that, it accesses the UIInput field for the stand-alone input field.
When it does this, I've found that it does NOT have the new values of the fields that were in the 3-by-3 table, but it DOES have the new value that was entered in the standalone input field.
However, AFTER the validator has run, the UIInput fields in the DataModel object are updated, so if I click the Submit button again, then it sees those values.
This has been EXTREMELY confusing and frustrating! I'm using Java 1.5, MyFaces 1.3, and Tomahawk 1.3. Has anyone found a way to make validation with DataModel work properly?
In order to keep things friendly, I'd like to ask you to update your display name to match the JavaRanch naming policy.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Joined: Sep 27, 2004
Bert Bates, I read the naming policy again today and it says one could use initials for the first name if one wanted. Is something changed now? I have had this display name for almost 2 years?! Before I change it to my real name, can you clarify?
Joined: Oct 14, 2002
Hey A. -
You have my apology! I haven't actually read the darned thingfor a long time and I didn't realize that a first initial was okay! Proceed