com.databasesandlife.util.wicket.ErrorAttributeAppender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
package com.databasesandlife.util.wicket;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.model.Model;
import java.io.Serializable;
/**
*
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
public class ErrorAttributeAppender extends AttributeAppender {
private static final long serialVersionUID = 1L;
private Boolean componentHasError;
public ErrorAttributeAppender() {
super("class", Model.of(" error"));
}
@Override
protected Serializable newValue(String currentValue, String appendValue) {
if (componentHasError) {
return super.newValue(currentValue, appendValue);
}else{
if(currentValue!=null){
return currentValue.replaceAll(appendValue, "");
}else{
return "";
}
}
}
@Override
public void onConfigure(Component component) {
componentHasError = component.hasErrorMessage();
super.onConfigure(component);
}
}