• Post Reply Bookmark Topic Watch Topic
  • New Topic

InputText field validation based on DropDown value selected

 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have DropDown with values CustomerId and PhoneNumber and an Input Field to enter value to search
Based on the value i select in the Dropdown, i will enter the value in Input Field

Now i want to do validation for the Input Field ( But based on the DropDown value, i will be entering the values in Input Field, so based on it i have to do Validation )

Can anybody give me suggestions on how to implement this functionality.




 
Tim Holloway
Bartender
Posts: 18414
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSF, the validation framework really only applied to single controls and are involved in mostly syntactic and range checking.

What you want is a context-sensitive (semantic) validation based on some other control's value. This is really very messy to do with a validator, since validators are both stateless and parameter-free, so there's no good place to work with context. Usually, it's easier to do the cross-check validation in the action method, set a JSF message in the action processor and return to the same view until the cross-checking is valid.
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand. But I tried to do something and let me explain it below

Based on the value selected in the dropdown, i have set the variable in JSF backing bean to true ( Using ValueChangeListener attribute for dropdown component )

And while coming to validation for the InputText Field, i am using regular expressions in my JSF backing bean. And i know which value was selected in the dropdown based on the flag i set in the JSF backing bean. So based on that condition, that is which value selected in the dropdown, i am using respective regular expression ( validation using validator and ValueChangeListener attributes of InputText component )

I am still working on it. Let's see how it turns up.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!