Skip to content

Instantly share code, notes, and snippets.

@dstarh
Created April 15, 2011 13:09
Show Gist options
  • Save dstarh/921661 to your computer and use it in GitHub Desktop.
Save dstarh/921661 to your computer and use it in GitHub Desktop.
package util.validation;
import java.lang.reflect.InvocationTargetException;
import models.bpo.SubjectMarketability;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.converters.BooleanConverter;
import org.apache.commons.lang.StringUtils;
import play.data.validation.Check;
public class RequiredIfOtherEqualsTrue extends Check {
@Override
public boolean isSatisfied(Object validatedObject, Object value) {
BooleanConverter b = new BooleanConverter();
checkWithCheck.getMessage();
try {
String trueFalseValue = BeanUtils.getSimpleProperty(validatedObject, checkWithCheck.getMessage());
boolean isTrue = (Boolean) b.convert(Boolean.class, trueFalseValue);
if (isTrue && StringUtils.isBlank((String)value)) {
setMessage("validation.required");
return false;
}
else {
return true;
}
}
catch (IllegalAccessException e) {
return false;
}
catch (InvocationTargetException e) {
return false;
}
catch (NoSuchMethodException e) {
return false;
}
}
}
public boolean other;
@CheckWith(value=RequiredIfOtherEqualsTrue.class, message="other")
public String other_value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment