I'm coding a JSF application which includes in the upper part of it a form with fields and in the lower part of it a datatable with a delete button on each item:
<h:panelGrid columns="2" styleClass="default">
<h:outputLabel for="name" value="Name: " />
<h:inputText id="name" value="#{user.name}" />
<h:outputLabel for="name" value="Surname: " />
<h:inputText id="surname" value="#{user.surname}" />
<h:outputLabel for="name" value="Email: " />
<h:inputText id="email" value="#{user.email}" />
<h:commandButton actionListener="#{manager.save}"
styleClass="buttons" value="Save" />
<h:messages errorStyle="color: red" infoStyle="color: green" />
<br/>
<ui:debug/>
</h:panelGrid>
<br/>
<h:dataTable value="#{userList}" var="item" styleClass="table"
headerClass="table-header"
rowClasses="table-odd-row,table-even-row">
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{item.name}" />
</h:column>
<h:column>
<f:facet name="header">Surname</f:facet>
<h:outputText value="#{item.surname}" />
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
<h:outputText value="#{item.email}" />
</h:column>
<h:column>
<f:facet name="header">Delete</f:facet>
<h:commandButton actionListener="#{manager.delete(item)}"
styleClass="buttons" value="Delete" />
</h:column>
</h:dataTable>
</h:form>
The application worked until I have applied constraints on the User Bean:
public class User {
@Size(min = 5, max = 20, message = "Please enter a valid name (5-20 characters)")
private String name;
@Size(min = 5, max = 20, message = "Please enter a valid surname (5-20 characters)")
private String surname;
@Size(min = 5, message = "Mail size is at least 5 characters")
@Pattern(regexp = "[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+", message = "Email format is invalid.")
private String email;
}
Now when I hit the Delete button on my page - with the text fields blank- the Constraint validator kicks in, preventing the actionListener to execute. Is there a way to work around this issue ? Thanks a lot !