I'm using @NotNull to define some atributes, but i want to use on relations as well. So i did
@NotNull(message = "Região não pode ser nula")
@JoinColumn(name = "regiao_id", referencedColumnName = "regiao_id")
@ManyToOne(optional = false)
private Regiao regiaoId;
Just like i would do
@NotNull(message="O nome não pode ser nulo")
@Size(min = 1, max = 10)
@Column(name = "nome")
private String nome;
Using on a String it works fine, but it doesn't work on my relation objects, so i end up having to validate whit something like if(foo.regiaoId() != null)
, can't i just make use of the @NotNull on situations like this as well?
To make it easy to understand i have an xhtml form where i dont want my selectOneMenu to be null
my 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"/>
Since i don't want to add to validate the nullable on my jsf, what would be the best way? Is there a way to use @NotNull on a object that belongs to a persistence class?
REFs using javax.validation.constraints.NotNull
Best way to add a "nothing selected" option to a selectOneMenu in JSF