Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Empty text Field Validation in JSF data Table

 
Vaibhav Purani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add required="true" for the required field.

add a message tag after the field:

 
Vaibhav Purani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried Javascript?

if (document.fieldName == "") {
alert("Please fill field x in...");
return false;
}


something like that...
 
Vaibhav Purani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, keep the edit, just give them subtle hints too as they are typing and tabbing.
 
Vaibhav Purani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can still pass the rowIndex into the javascript arguments like this:
Have this in your datatable:



And
have this in your javascript call:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic