I use a Hibernate validator like @NotEmpty to find out if a specific property is empty or not in a class. The class looks like this:
@Entity
@Table(name="emergency_messages")
public class EmergencyMessages implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id", nullable=false)
private Integer id;
@NotEmpty(message="Home message cannot be empty")
@Column(name="home_page_message")
private String homePageMessage;
@Range(min=0, max=1, message="Please select one of the display announcement value")
@Column(name="messages_enabled")
private Integer messagesEnabled;
}
So far so good. Whenever the "homePageMessage" property is empty, I see that the correct form error message is in the browser.
Now the situation has changed. The new requirement is that the "homePageMessage" property can be empty only if the other "messagesEnabled" property is set to 1. If it is set to 0, then there should be no empty confirmation for "homePageMessage". In simple words, the validation of "homePageMessage" should now depend on the value of "messagesEnabled".
: ? , .