I use this class for doing validation from input fields:
@ManagedBean
@RequestScoped
public class UserInputValidation {
public void validateCity(FacesContext context, UIComponent validate,
Object value) {
String inputFromField = (String) value;
if (inputFromField.equals("") || inputFromField.equals(" ")) {
FacesMessage msg = new FacesMessage("Odaberite grad");
throw new ValidatorException(msg);
}
}
//...
}
And this is the managed bean that holds the inputed values:
@ManagedBean
@RequestScoped
public class InputController {
//Attributes
private String city;
//Get set methods
Why when i create a selectOneComponent and i select the first component(blank input), the validation message is not shown?
<h:selectOneMenu id="city" value="#{inputController .city}">
<f:selectItems value="#{searchController.formatedCities()}" validator="#{userInputValidation.validateCity}"/>
</h:selectOneMenu>
<span style="color: red;"><b><h:message for="city"
showDetail="true" /></b></span>
The first of the fields in the selectOneMenu is a blank(The formatedCitiesMethod() returns a "" as first element), so why the validation message is not being shown if the form is submit button is clicked with the blank selected?