I have a address entity like this:
@Entity
public class Address implements java.io.Serializable {
@Id @GeneratedValue(strategy = IDENTITY)
private Long id;
@Size(max = 100)
private String street;
@Size(max = 15)
private String nr;
@Field
@Size(min = 1, max = 20) @NotBlank
private String city;
}
This is part of several other entities. For one such entity the address is optional. I have a view where our users can edit the whole entity via several form inputs, including several address fields.
To be able to edit the address, I initialize the parent entity with an empty address entity.
Now the problem is: I don't want to persist an Address
on the entity when all address fields are empty. For that to work, I need to skip validation for the entity if (and only if) all fields of Address
are empty. How do I do that in the most elegant way?
What I'm currently doing is to skip bean validation altogether with <o:validateBean disabled="true" />
for the submit button, setting the address to null
if it comes out empty. But this sounds like a total hack as it disables all validation in all cases. How can I do better?
param
value worked just fine I had to use the string value of the id (I control the naming container and theid
s of the inputs), usingclientId
gave me a NullPointerException when trying to evaluate the EL. Could this be because the values are in a conditionally rendered popup? – Curvature