Created
April 15, 2011 13:09
-
-
Save dstarh/921661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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