I have a simple JSF input form into edit page and Validator which checks the value for duplication:
<td>Name</td>
<td>
<h:outputText value="#{ud.name}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText id="dcname" value="#{ud.name}" rendered="#{DCProfileTabGeneralController.editable}"
validator="#{ValidatorDatacenterController.validateDatacenterName}" autocomplete="off">
<f:ajax event="blur" render="dcnamevalidator" />
</h:inputText>
<h:message id="dcnamevalidator" for="dcname" />
</td>
public void validateDatacenterName(FacesContext context, UIComponent component, Object value){
....
}
I'm interested is there any possible way to send a second value which will be used into the validation process?
<f:attribute>
comes to mind. Add one to the inputtext and retrieve it in the validator.
<h:inputText id="dcname".....
<f:attribute name="param" value="myparam" />
</h:inputText>
And:
String param = (String) component.getAttributes().get("param");
Can get the value from EL. Good luck
You can add a postValidate event to validate multiple fields , like
<f:event listener="#{bean.validationMethod}" type="postValidate" />
this should fire before model updates and you can get the new value for different component with
FacesContext fc = FacesContext.getCurrentInstance();
UIComponent components = event.getComponent();
UIInput param1 = (UIInput) components.findComponent("param1");
UIInput param2 = (UIInput) components.findComponent("param2");
If the validation fails , call the FacesContext renderResponse method to skip model update.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With