• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating primeface data table data

 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic