This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JSF and the fly likes Validating primeface data table data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Validating primeface data table data" Watch "Validating primeface data table data" New topic
Author

Validating primeface data table data

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2995
    
    9

Hello ranchers,

I am using Primeface data table <p:datatable> to create/update data. I noticed that when I do validation, it validates the inputs on that page view only.

For example: <p:datatable rows="5" ...>
I have 7 rows in the data table. The first 5 are displayed. How can I also validate the last 2 rows on the next page?

Currently I'm trying to get this list of data from my session-scoped managed bean and loop through it. But then I found the values are sometimes null.

Therefore, is there a way to use the JSF validate(FaceContext fc, UIComponent ui, Object obj) method to validate ALL rows (including those on other page links of the data table)?

Note that ui.findComponent("table_id") with give me the 5 rows of inputs only from the request map.

Thanks.

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17046
    
  26

I suspect you're doing something horrible involving rooting around in internal JSF data structures and yanking on data based on what you're referencing.

JSF validation is done for input control values when a form is submitted. If the item in question isn't an input control or isn't in the form that's being submitted (remember, a page can contain more than one form), then the input value will not be validated.

So if you have a table with 7 rows but your are only displaying 5 of them on the page, those 5 rows are the only ones whose data will pass through the validators. And, as I mentioned earlier, only data being input from the client. Outbound data never passes through the validators.


An IDE is no substitute for an Intelligent Developer.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2995
    
    9

Thanks Tim.

I understand that I only get say the 5 rows of inputs. I asked this because some inputs cannot be duplicated. So if I enter "abc" on page 1 then on page 2 there is another record with "abc". Under this circumstance, I suppose to inform the user there is duplication and fail the validation.

But now because the validation only process the current page's inputs, the validation returns true and save/update the database ending up duplicate records. :(
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17046
    
  26

Checking for duplicates isn't really what validation is for. Validation is primarily about superficial objective tests like valid syntax and range.

Normally, when you want to avoid the possibility of duplications, you'd be testing that in the action method itself.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2995
    
    9

Tim Holloway wrote:Checking for duplicates isn't really what validation is for. Validation is primarily about superficial objective tests like valid syntax and range.

Normally, when you want to avoid the possibility of duplications, you'd be testing that in the action method itself.


So you are saying, I can let validation pass and do the duplicate checking in my managed bean before I actually save/update to database?

I guess I can try that.
 
Have you checked out Aspose?
 
subject: Validating primeface data table data
 
It's not a secret anymore!