I'm trying to validate some values in my form, but this validation constraints I want to come from some annotations(javax.validation.constraints.*) on a class. I tried everything I can, spend a few hours searching google/stackoverflow - but I get the same thing, it may be that I'm missing something really simple, but still I can't see it
I use Primefaces 5.3, and webspehere8.5(java1.7)
Below is my Bean where I'm going to receive the values.
Please note,I tried a few ways to get this working as I was not sure which one would wokr:
- Use a holder for my values (see below SearchForm class)
Directly in the the bean
@ManagedBean @SessionScoped public class MagicBean implements Serializable { private static final long serialVersionUID = -8724952745982557284L; SearchForm formValues = new SearchForm(); public void submitSearchForm() { System.out.println("is Ok"); } .... @NotNull @Pattern(regexp = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$", message = "This is not a valid email") private String email; ... }
Here is the search form class
public class SearchForm {
...
@NotNull
@Size(min = 3, message = "Name should at least be 3 characters long")
private String name;
...
}
And here is how my page looks like
<p:growl id="msgs" showDetail="true" />
<p:messages id="msgs2"/>
<h:form id="searchParamsForm">
<p:fieldset widgetVar="searchParamsFormToggle" legend="Search params" toggleable="true" toggleSpeed="500">
<h:panelGrid columns="3" cellpadding="5">
<h:outputText>Name</h:outputText>
<p:inputText id="name" required="true" >#{magicBean.formValues.name} <!-- notice here I use some other class -->
</p:inputText>
<p:message id="errorName" for="name" style="color:red"/>
<h:outputText>Email</h:outputText>
<p:inputText id="email">#{magicBean.email}</p:inputText> <!-- direct from the magic bean -->
<p:message id="errorMail" for="email" style="color:red"/>
<p:commandButton value="Save" ajax="false" icon="ui-icon-check" validateClient="true"/>
<p:commandButton value="Search" update="msgs msgs2 errorMail searchParamsForm" ajax="false" icon="ui-icon-check" validateClient="true" action="#{magicBean.submitSearchForm}" process="searchParamsForm" >
</h:panelGrid>
</p:fieldset>
</h:form>
And of course here are some params I found I have to set
<context-param>
<param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.TRANSFORM_METADATA</param-name>
<param-value>true</param-value>
</context-param>