i'm following thymeleaf documentation create processor , dialect change css of component when not filled. if not filled, add css class has error, not working.
i'm using spring boot
look class tagerrorattributeprocessor
public class tagerrorattributeprocessor extends abstracttextchildmodifierattrprocessor { public tagerrorattributeprocessor() { super("fielderror"); } @override public int getprecedence() { return 12000; } @override protected string gettext(final arguments arguments, final element element, final string attributename) { final configuration configuration = arguments.getconfiguration(); // obtém o analisador de expressões padrão thymeleaf final istandardexpressionparser parser = standardexpressions.getexpressionparser(configuration); // analisa o valor atributo com uma expressão padrão thymeleaf final istandardexpression expression = parser.parseexpression(configuration, arguments, element.getattributevalue(attributename)); if (fieldutils.haserrors(arguments, element.getattributevalue(attributename))) { element.setattribute("class", element.getattributevalue("class") + " has-error"); } // executar expressão apenas para analisar final string execute = (string) expression.execute(configuration, arguments); return execute; } }
class tagerrorattributedialect
public class tagerrorattributedialect extends abstractdialect { @override public string getprefix() { return "rwfield"; } @override public set<iprocessor> getprocessors() { final set<iprocessor> processors = new hashset<iprocessor>(); processors.add(new tagerrorattributeprocessor()); return processors; } }
html
<!doctype html> <html lang="pt" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:rwfield="http://filedserros" layout:decorator="'model/layout/default'"> <div class="form-group" rwfield:fielderror="nome"> <label for="lbusuario">nome:</label> <input id="nomusr" type="text" th:field="*{nome}" class="form-control"/> </div> </html>
Comments
Post a Comment