jpaoletti.jpm.validator.NotNull Maven / Gradle / Ivy
The newest version!
package jpaoletti.jpm.validator;
import jpaoletti.jpm.core.PMContext;
import jpaoletti.jpm.core.message.MessageFactory;
/**Validate that the specified field is not null
*
* Simple entity configuration file
*
* {@code
*
* some_id
* ....
*
*
* }
*
* @author jpaoletti
* */
public class NotNull extends ValidatorSupport {
/**The validation method*/
@Override
public ValidationResult validate(PMContext ctx) {
final ValidationResult res = new ValidationResult();
final Object fieldvalue = ctx.getFieldValue();
res.setSuccessful(fieldvalue != null);
if (!res.isSuccessful()) {
res.getMessages().add(MessageFactory.error(
ctx.getEntity(), ctx.getField(),
get("msg", "pm.validator.not.null"),
ctx.getField().getId()));
}
return res;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy