• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

JSF Validation - How to identify the component which calls the validate method in the nethod itself  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Take a look a the code

<t:inputText value="#{bean.val1}">
<f:validator validatorId="validate"/>
</t:inputText>

<t:inputText value="#{bean.val2}">
<f:validator validatorId="validate"/>
</t:inputText>


public void validate(FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException {

if (cond1)
validate1(arg0, arg1, arg2);

if (cond2
validate2(arg0, arg1, arg2);

}

private void validate1(FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException {

// validation code here for val1

}

private void validate2(FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException {

// validation code here for val2

}


Now I need to know the condition cond1 and cond2 whether it can be given for different inputTexts. So i do not need to have different classes for different text boxes. How do I identify which text box is being called in the validate method since I have the same Id for both. Can this requirement be done like this or is there any other way ? Please help
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Augustine,
I personally haven't tried this with plain JSF. You might want to give it a try:
1. Provide ids to your inputText tags (assuming this is not a constraint for you)
2. In your validator check the component.getId() value against the id's of tags in step 1.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!