aspose file tools*
The moose likes JSF and the fly likes JSF Validation - How to identify the component which calls the validate method in the nethod itself Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Validation - How to identify the component which calls the validate method in the nethod itself" Watch "JSF Validation - How to identify the component which calls the validate method in the nethod itself" New topic
Author

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

Augustine Chelliah
Greenhorn

Joined: Mar 12, 2009
Posts: 28
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


Thanks & Regards,
Augustine
Vj Borkar
Greenhorn

Joined: Jan 10, 2007
Posts: 7
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.


Regards,
VJ
SCJP 1.4, SCJP 6.0, SCWCD 1.4
 
wood burning stoves
 
subject: JSF Validation - How to identify the component which calls the validate method in the nethod itself