Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf @NotNull不处理对象,但处理字段_Jsf_Bean Validation - Fatal编程技术网

Jsf @NotNull不处理对象,但处理字段

Jsf @NotNull不处理对象,但处理字段,jsf,bean-validation,Jsf,Bean Validation,我使用@NotNull来定义一些属性,但我也希望在关系上使用。 所以我做了 就像我会做的一样 @NotNull(message="O nome não pode ser nulo") @Size(min = 1, max = 10) @Column(name = "nome") private String nome; 在字符串上使用它可以很好地工作,但在我的关系对象上不起作用,所以我最终不得不用if(foo.regiaoId()!=null)之类的东西进行验证,我不能在这种情况下也使用@No

我使用@NotNull来定义一些属性,但我也希望在关系上使用。 所以我做了

就像我会做的一样

@NotNull(message="O nome não pode ser nulo")
@Size(min = 1, max = 10)
@Column(name = "nome")
private String nome;
在字符串上使用它可以很好地工作,但在我的关系对象上不起作用,所以我最终不得不用if
(foo.regiaoId()!=null)
之类的东西进行验证,我不能在这种情况下也使用@NotNull吗

为了便于理解,我有一个xhtml表单,不希望我的selectOneMenu为空

我的xhtml

            <p:outputLabel value="Região:" for="regiaoCombo" />
            <p:selectOneMenu id="regiaoCombo" value="#{equipamentoBean.equipamento.regiaoId}" converter="omnifaces.SelectItemsConverter">
                <f:selectItem itemLabel="Selecione" itemValue="#{null}"></f:selectItem>
                <f:selectItems value="#{equipamentoBean.regioes}"></f:selectItems>
            </p:selectOneMenu>
            <p:message for="regiaoCombo"/>

既然我不想在我的jsf上添加以验证null值,那么最好的方法是什么?有没有办法在属于持久性类的对象上使用@NotNull

使用javax.validation.constraints.NotNull引用


尝试与@NotNull结合使用

@Basic(可选=false)@Column(nullable=false)


这里有一个链接,指向一个清晰简单的JPA文档,它可能也会帮助您

并没有真正做到我想要的,我想使用@NotNull作为验证bean,我尝试了这两种方法,但结果仍然相同。。。
            <p:outputLabel value="Região:" for="regiaoCombo" />
            <p:selectOneMenu id="regiaoCombo" value="#{equipamentoBean.equipamento.regiaoId}" converter="omnifaces.SelectItemsConverter">
                <f:selectItem itemLabel="Selecione" itemValue="#{null}"></f:selectItem>
                <f:selectItems value="#{equipamentoBean.regioes}"></f:selectItems>
            </p:selectOneMenu>
            <p:message for="regiaoCombo"/>