Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom Validator  RSS feed

 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i submit the page i need to do Validation for more than 1 field

i have written custom validation class

My question is can i do validation for multiple fields in the same Custom Validation class

i Tried and it's not working

in My Custom Validation class when i try to find the component for which i need to do validation using the following code

Boolean flag1 = Boolean.valueOf((String) component.getAttributes().get("Field1"));
Boolean flag2 = Boolean.valueOf((String) component.getAttributes().get("Field2"));

It suppose to written true for both of the fields. But it's returning TRUE only for the first field

Is it possible in the first case???

Any ideas?


 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can (I have) write validators that reference multiple controls. In my case I did one that did the comparison of 2 password controls to verify that the user typed the same password twice.

I don't think you can attach validators to general components such as panelGrids, however. I think that they only work when applied to actual Input controls. So you have to pick the "master" input control and then search your way up, down, and around the component tree to find the other component(s). Which - annoyingly - you can't specify as parameters, so you generally have to do something kludgy like require a specific relative location or use the primary control's ID as a basis for the IDs of the secondary controls.

This only carries so far, however. Eventually you just have to do really complex cross-field validation as the prologue statemtents in your action processor and have the action reject with appropriate error messages.
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have specified Customer Validator to input control itself and NOT for panelGrid

Below are my custom validator code in JSF

<f:validator validatorId="customValidator"/>
<f:attribute name="Field1" value="true"/>

And similarly for other field too with attribute name as "Field2"
------------------------------------------------------------------------------------------

Actually it is working fine. Let me explain what's happening

I entered empty spaces and thought it should throw validation error using my custom validation code
But before it calls custom validation i think somehow the empty spaces are getting trimmed ( i don't know how ). This field type is "Integer"

In that case, since it's empty field, custom validator is never invoked


I have posted the same question as another Topic

http://www.coderanch.com/t/535537/JSF/java/empty-space-validation
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!