Author: tchemit Date: 2010-09-11 22:18:14 +0200 (Sat, 11 Sep 2010) New Revision: 2087 Url: http://nuiton.org/repositories/revision/jaxx/2087 Log: fix NPE due to inheritence + improve code Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java 2010-09-11 19:39:49 UTC (rev 2086) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java 2010-09-11 20:18:14 UTC (rev 2087) @@ -33,6 +33,7 @@ import jaxx.compiler.tags.TagHandler; import jaxx.compiler.tags.validator.BeanValidatorHandler.CompiledBeanValidator; import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Element; @@ -47,8 +48,6 @@ public static final String COMPONENT_ATTRIBUTE = "component"; - public static final String EXTERNAL_COMPONENT_ATTRIBUTE = "externalComponent"; - /** Logger */ static private Log log = LogFactory.getLog(FieldValidatorHandler.class); @@ -79,14 +78,15 @@ (CompiledBeanValidator) compiler.getOpenComponent(); String name = tag.getAttribute(NAME_ATTRIBUTE); - String component = tag.getAttribute(COMPONENT_ATTRIBUTE); - if (name == null || name.trim().isEmpty()) { + if (StringUtils.isEmpty(name)) { compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute"); return; } name = name.trim(); - if (component == null || component.trim().isEmpty()) { + + String component = tag.getAttribute(COMPONENT_ATTRIBUTE); + if (StringUtils.isEmpty(component)) { // try to use the name as component if (!compiler.checkReference(tag, name, false, name)) { compiler.reportError( Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2010-09-11 19:39:49 UTC (rev 2086) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2010-09-11 20:18:14 UTC (rev 2087) @@ -206,8 +206,13 @@ super.setContextName(contextName); - // must reinstall ui - installUIs(); + // install uis only when fieldRepresentation is not null + // this case is possible since we come here from parent in constructor. + if (fieldRepresentation != null) { + + // must reinstall ui + installUIs(); + } } /** @@ -251,11 +256,11 @@ /** install ui on required components */ public void installUIs() { -// if (fieldRepresentation == null) { -// throw new NullPointerException( -// "fieldRepresentation is null, must init before " + -// "invoking installUIs method..."); -// } + if (fieldRepresentation == null) { + throw new NullPointerException( + "fieldRepresentation is null, must init before " + + "invoking installUIs method..."); + } SwingUtilities.invokeLater(new Runnable() { @Override