Is there any way I can validate a jsf input text that is readonly but the value is changed upon some other events triggered?
4 Answers
Answering from comment: "Woudn't it be easier to validate it in the jsf page backing bean?" You can do application-level validation on a button click or some similar event. You can do something like this in your backing bean and link it to the event.
public String login(){
FacesContext context = FacesContext.getCurrentInstance();
if(**<<some validation for value in field 'firstName' in form 'userForm'>>**){
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("Some Valication check");
message.setSummary("Some Valication check!!");
context.addMessage("userForm:firstName", message);//adds validation message for field firstName in form userForm
return "ERROR";
}
return "SUCCESS";
}
Hope this helped.
I have solved this problem with a workaround. I have added an inputHidden field that has the required attribute true that will not appear on the interface, but will be validated:
<h:inputHidden value="#{bean.value}" required="true"
requiredMessage="Data must be entered" />
The value of bean.value is changed by other event, and at some reRender on the inputHidden, the validation takes place.
You will most likely have to manually call the validation logic directly from your event. Here is a model of the JSF lifecycle from IBM.

You will notice that Process Validations phase occurs before the Invoke Application phase where events are typically handled. This occurs well after so validation will not occur automatically.