public void validate(ValidationContext ctx) { if (ctx.getProperty().getValue() instanceof Integer) { Integer value = (Integer) ctx.getProperty().getValue(); if (value < 0) { ctx.setInvalid(); } } else { ctx.setInvalid(); } }
@Override public void validate(ValidationContext ctx) { for (int i = 0; i < campObligas.length; i++) { String[] f = campObligas[i]; Object field = ctx.getProperties(f[0])[0].getValue(); if (field == null || Strings.isBlank(String.valueOf(field))) { addInvalidMessage(ctx, f[0], f[1]); } } Integer id_marca = 0; Object field = ctx.getProperties("marca")[0].getValue(); MarcasExample me = new MarcasExample(); if (itemSel.getId() != null) { id_marca = itemSel.getId(); } me.createCriteria().andMarcaEqualTo(String.valueOf(field)).andIdNotEqualTo(id_marca); Integer cant = itemsMapper.countByExample(me); if (cant > 0) { addInvalidMessage(ctx, "marca", "La marca introducida ya existe"); } }