Java JSF2动态表单和bean验证JSR303

Java JSF2动态表单和bean验证JSR303,java,jsf,jsf-2,bean-validation,dynamic-forms,Java,Jsf,Jsf 2,Bean Validation,Dynamic Forms,我从带注释的bean开始生成一个动态表单。使用Hibernate验证器对同一bean进行注释以进行验证。 表单已正确呈现,但当表单提交到验证步骤时,不会执行该步骤。如果我使用jsf标记编写相同的表单,验证将正常工作 有什么想法吗 表格页: 实体Bean示例: @Entity 公共类Istituto实现了可序列化的IBaseEntity{ 私有静态最终长serialVersionUID=1L @Id @SequenceGenerator(name="IstitutoGenerator", s

我从带注释的bean开始生成一个动态表单。使用Hibernate验证器对同一bean进行注释以进行验证。 表单已正确呈现,但当表单提交到验证步骤时,不会执行该步骤。如果我使用jsf标记编写相同的表单,验证将正常工作

有什么想法吗

表格页:

实体Bean示例:

@Entity
公共类Istituto实现了可序列化的IBaseEntity{ 私有静态最终长serialVersionUID=1L

@Id
@SequenceGenerator(name="IstitutoGenerator", sequenceName="ISTITUTO_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="IstitutoGenerator")
@Column(name="ID_ISTITUTO")
private int idIstituto;

@NotNull
private String nome;

@NotNull
private String indirizzo;

@NotNull
private String comune;

@NotNull
@Pattern(regexp="[0-9][0-9][0-9][0-9][0-9]", message="Il CAP deve essere composto da 5 numeri")
private String cap;

@OneToMany(mappedBy="istituto")
private Set<Classe> classes;

public Istituto() {
}

public int getIdIstituto() {
    return this.idIstituto;
}

public void setIdIstituto(int idIstituto) {
    this.idIstituto = idIstituto;
}

public String getCap() {
    return this.cap;
}

public void setCap(String cap) {
    this.cap = cap;
}

public String getComune() {
    return this.comune;
}

public void setComune(String comune) {
    this.comune = comune;
}

public String getIndirizzo() {
    return this.indirizzo;
}

public void setIndirizzo(String indirizzo) {
    this.indirizzo = indirizzo;
}

public String getNome() {
    return this.nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

public Set<Classe> getClasses() {
    return this.classes;
}

public void setClasses(Set<Classe> classes) {
    this.classes = classes;
}

@Override
public Integer getId() {
    return this.getIdIstituto();
}

@Override
public int hashCode() {
    int hash = 0;
    hash += this.getIdIstituto();
    return hash;
}

@Override
public boolean equals(Object object) {
    if (!(object instanceof Istituto)) {
        return false;
    }
    Istituto other = (Istituto) object;
    if  (this.getIdIstituto() != other.getIdIstituto()) {
        return false;
    }

    return true;
}

@Override
public String toString() {
    return this.getNome();
}
@Id
@SequenceGenerator(name=“IstitutoGenerator”,sequenceName=“ISTITUTO_SEQ”,allocationSize=1)
@GeneratedValue(策略=GenerationType.SEQUENCE,generator=“IstitutoGenerator”)
@列(name=“ID_istuto”)
私人国际机构;
@NotNull
私有字符串名称;
@NotNull
私人字符串indirizzo;
@NotNull
私有字符串通信;
@NotNull
@模式(regexp=“[0-9][0-9][0-9][0-9][0-9]”,message=“Il CAP deveessere composto da 5 numeri”)
私人线头;
@OneToMany(mappedBy=“istituto”)
私有集合类;
公共研究所(){
}
public int getIdIstituto(){
返回此.idIstituto;
}
公共无效设置idIstituto(内部idIstituto){
this.idIstituto=idIstituto;
}
公共字符串getCap(){
退回这个.cap;
}
公共无效设置上限(字符串上限){
this.cap=cap;
}
公共字符串getComune(){
返回此.comune;
}
public void setComune(字符串comune){
this.comune=comune;
}
公共字符串getIndirizzo(){
把这个还给我;
}
公共无效setIndirizzo(字符串indirizzo){
this.indirizzo=indirizzo;
}
公共字符串getNome(){
归还这个.nome;
}
公共无效集合名称(字符串名称){
this.nome=nome;
}
公共集getClasses(){
将此文件返回。类;
}
公共void集合类(集合类){
这个类=类;
}
@凌驾
公共整数getId(){
返回这个.getIdIstituto();
}
@凌驾
公共int hashCode(){
int hash=0;
hash+=this.getIdIstituto();
返回散列;
}
@凌驾
公共布尔等于(对象){
if(!(Istituto的对象实例)){
返回false;
}
Istituto other=(Istituto)对象;
if(this.getIdIstituto()!=other.getIdIstituto()){
返回false;
}
返回true;
}
@凌驾
公共字符串toString(){
返回这个.getNome();
}

}

您必须将
javax.faces.validator.BeanValidator的实例添加到输入组件中:

input.addValidator(new BeanValidator());
原因是在标记执行期间添加了默认验证器(BeanValidator注册为一个)

@Id
@SequenceGenerator(name="IstitutoGenerator", sequenceName="ISTITUTO_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="IstitutoGenerator")
@Column(name="ID_ISTITUTO")
private int idIstituto;

@NotNull
private String nome;

@NotNull
private String indirizzo;

@NotNull
private String comune;

@NotNull
@Pattern(regexp="[0-9][0-9][0-9][0-9][0-9]", message="Il CAP deve essere composto da 5 numeri")
private String cap;

@OneToMany(mappedBy="istituto")
private Set<Classe> classes;

public Istituto() {
}

public int getIdIstituto() {
    return this.idIstituto;
}

public void setIdIstituto(int idIstituto) {
    this.idIstituto = idIstituto;
}

public String getCap() {
    return this.cap;
}

public void setCap(String cap) {
    this.cap = cap;
}

public String getComune() {
    return this.comune;
}

public void setComune(String comune) {
    this.comune = comune;
}

public String getIndirizzo() {
    return this.indirizzo;
}

public void setIndirizzo(String indirizzo) {
    this.indirizzo = indirizzo;
}

public String getNome() {
    return this.nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

public Set<Classe> getClasses() {
    return this.classes;
}

public void setClasses(Set<Classe> classes) {
    this.classes = classes;
}

@Override
public Integer getId() {
    return this.getIdIstituto();
}

@Override
public int hashCode() {
    int hash = 0;
    hash += this.getIdIstituto();
    return hash;
}

@Override
public boolean equals(Object object) {
    if (!(object instanceof Istituto)) {
        return false;
    }
    Istituto other = (Istituto) object;
    if  (this.getIdIstituto() != other.getIdIstituto()) {
        return false;
    }

    return true;
}

@Override
public String toString() {
    return this.getNome();
}
input.addValidator(new BeanValidator());