Created
February 26, 2010 13:25
PropertyEditor implementation used for binding to Grails domain objects by unique property value
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
import java.beans.PropertyEditorSupport | |
import org.apache.commons.lang.StringUtils | |
class DomainClassLookupPropertyEditor extends PropertyEditorSupport { | |
Class domainClass | |
String property | |
String getAsText() { | |
value."$property" | |
} | |
void setAsText(String text) { | |
value = domainClass."findBy${StringUtils.capitalize(property)}"(text) | |
if (!value) { | |
value = domainClass.newInstance((property): text) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment