This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Augustine Chelliah
Greenhorn
Posts: 28
  • 0
  • 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
 
Vj Borkar
Greenhorn
Posts: 7
  • 0
  • 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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic