I'm trying to validate a form before submitting, but is not working as expected.
Here my XHTML
<h:outputLabel for="name">Name: </h:outputLabel>
<p:inputText id="name" value="#{partyCreationBean.name}" />
<h:message for="name"/>
<h:outputLabel for="symbol">Symbol: </h:outputLabel>
Here my webBean:
@ManagedBean(name = "partyCreationBean")
@RequestScoped
public class PartyCreationBean {
@EJB
PartyManagerLocal ejb_partymanager;
@EJB
AuthenticationManagerLocal ejb_user;
private PartyDTO party = new PartyDTO();
public String getName() {
return party.getName();
}
public void setName(String name) {
party.setName(name);
}
Here my DTO:
import org.hibernate.validator.constraints.*;
public class PartyDTO implements IDataTransferObject {
private Integer id;
@NotEmpty()
private String name;
//Getters, setters and other stuff.
}
Now the point is that if I leave "Name" empty and I press the button to create my party, the page just remain all the sames, and i get Exceptions in the console stack traces (a lot like usual :D )
I tried to work with this XHTML (adding require="true"):
<h:outputLabel for="name">Name: </h:outputLabel>
<p:inputText id="name" required="true" value="#{partyCreationBean.name}" />
<h:message for="name"/>
<h:outputLabel for="symbol">Symbol: </h:outputLabel>
and it is working well but I want to put my "constraints" in the DTO level...
Thanks in advance :)