All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.wicket.ErrorAttributeAppender Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy