| Author |
Empty text Field Validation in JSF data Table
|
Vaibhav Purani
Greenhorn
Joined: Mar 26, 2008
Posts: 6
|
|
Hi i am new to Java n JSF i need to have the validation for JSF datatable so that it shows a POPup or a message when any blank field is submitted following is my JSF datatable please help me with this Thanks in ADvance
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
add required="true" for the required field. add a message tag after the field:
|
 |
Vaibhav Purani
Greenhorn
Joined: Mar 26, 2008
Posts: 6
|
|
Thanks a Ton BOB that really helped now what if i want a PopUp to be generated in the same scenario. thank you again in Advance
|
 |
Darryl Nortje
Ranch Hand
Joined: Jun 11, 2002
Posts: 140
|
|
Have you tried Javascript? if (document.fieldName == "") { alert("Please fill field x in..."); return false; } something like that...
|
 |
Vaibhav Purani
Greenhorn
Joined: Mar 26, 2008
Posts: 6
|
|
Hi Darryl yes i have tried a java script also but the thing is when i add rows to the datatable each row generates its own id to hence doesnt work instead works when i hardcode "i" where i= the row integer
|
 |
Darryl Nortje
Ranch Hand
Joined: Jun 11, 2002
Posts: 140
|
|
|
You got me there. I'm not so sure I understand exactly what you want to do though. you have a dataTable. It has lots of rows. A user can change values across all the rows in the dataTable, and when he/she submits the form, the entire dataTable needs to be validated. And you want this done with popUps...? Is that correct?
|
 |
Vaibhav Purani
Greenhorn
Joined: Mar 26, 2008
Posts: 6
|
|
hi Darryl yes you got my requirements to the point. the popup should appear only if any of the field is empty in that datatable thanks a lot
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
You may want to trigger the javascript popup 'onblur' for each field (popup when they leave the field if it is blank). Might be kind of annoying though. If you do it on form submit (onclick), then you will get 1 popup if there are ANY empty fields...I would guess.
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
|
Another more subtle thing you can do is use cascading style sheet to turn he field red if it is blank (onblur). That will altert them in a subtle way in real time that there is something wrong.
|
 |
Vaibhav Purani
Greenhorn
Joined: Mar 26, 2008
Posts: 6
|
|
hi BOB thanks i have done the needful but i dont want it to submit to the database any of the field is blank
|
 |
Bob Good
Ranch Hand
Joined: Jan 09, 2008
Posts: 86
|
|
|
Yes, keep the edit, just give them subtle hints too as they are typing and tabbing.
|
 |
Vaibhav Purani
Greenhorn
Joined: Mar 26, 2008
Posts: 6
|
|
hi BoB thanks for the reply but then if i have to use a popup then what can i do because the java script demands a dyanamic rowindex value which i am unable to provide.. thanks a lot in advance
|
 |
A. Dusi
Ranch Hand
Joined: Sep 27, 2004
Posts: 114
|
|
You can still pass the rowIndex into the javascript arguments like this: Have this in your datatable: And have this in your javascript call:
|
 |
 |
|
|
subject: Empty text Field Validation in JSF data Table
|
|
|