blank == null

This commit is contained in:
Anthony Stirling 2023-10-07 23:35:28 +01:00
parent f4a01884bd
commit d94eca4ee7
4 changed files with 6 additions and 66 deletions

View file

@ -9,17 +9,6 @@ import stirling.software.SPDF.model.ApplicationProperties;
@Configuration @Configuration
public class AppConfig { public class AppConfig {
@Bean
public CustomEditorConfigurer customEditorConfigurer() {
return new CustomEditorConfigurer();
}
@Bean
public PropertyEditorRegistrar propertyEditorRegistrar() {
return registry -> {
registry.registerCustomEditor(String.class, new EmptyStringAsNullEditor());
};
}
@Autowired @Autowired
ApplicationProperties applicationProperties; ApplicationProperties applicationProperties;

View file

@ -1,42 +0,0 @@
package stirling.software.SPDF.config;
import java.beans.PropertyEditor;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.validation.DataBinder;
public class CustomEditorConfigurer implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof PropertyEditorRegistrar) {
((PropertyEditorRegistrar) bean).registerCustomEditors(new PropertyEditorRegistry() {
@Override
public void registerCustomEditor(Class<?> requiredType, String propertyPath, java.beans.PropertyEditor propertyEditor) {
DataBinder dataBinder = new DataBinder(bean);
dataBinder.registerCustomEditor(requiredType, propertyPath, propertyEditor);
}
@Override
public void registerCustomEditor(Class<?> requiredType, java.beans.PropertyEditor propertyEditor) {
DataBinder dataBinder = new DataBinder(bean);
dataBinder.registerCustomEditor(requiredType, propertyEditor);
}
@Override
public PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath) {
return null;
}
});
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}

View file

@ -1,13 +0,0 @@
package stirling.software.SPDF.config;
import java.beans.PropertyEditorSupport;
public class EmptyStringAsNullEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) {
if (text != null && text.trim().isEmpty()) {
setValue(null);
} else {
setValue(text);
}
}
}

View file

@ -232,6 +232,8 @@ public class ApplicationProperties {
private String appNameNavbar; private String appNameNavbar;
public String getAppName() { public String getAppName() {
if(appName != null && appName.trim().length() == 0)
return null;
return appName; return appName;
} }
@ -240,6 +242,8 @@ public class ApplicationProperties {
} }
public String getHomeDescription() { public String getHomeDescription() {
if(homeDescription != null && homeDescription.trim().length() == 0)
return null;
return homeDescription; return homeDescription;
} }
@ -248,6 +252,8 @@ public class ApplicationProperties {
} }
public String getAppNameNavbar() { public String getAppNameNavbar() {
if(appNameNavbar != null && appNameNavbar.trim().length() == 0)
return null;
return appNameNavbar; return appNameNavbar;
} }