Search in sources :

Example 1 with Expression

use of org.thymeleaf.standard.expression.Expression in project thymeleaf-tests by thymeleaf.

the class AddLocalVariableToNode method processAttribute.

@Override
protected ProcessorResult processAttribute(final Arguments arguments, final Element element, final String attributeName) {
    final String attributeValue = element.getAttributeValue(attributeName);
    final AssignationSequence assignationSequence = StandardExpressionProcessor.parseAssignationSequence(arguments, attributeValue, false);
    for (final Assignation assignation : assignationSequence.getAssignations()) {
        final String varName = assignation.getLeft().getValue();
        final Expression varValueExpr = assignation.getRight();
        final Object varValue = StandardExpressionProcessor.executeExpression(arguments, varValueExpr);
        element.setNodeLocalVariable(varName, varValue);
    }
    element.removeAttribute(attributeName);
    return ProcessorResult.OK;
}
Also used : Expression(org.thymeleaf.standard.expression.Expression) AssignationSequence(org.thymeleaf.standard.expression.AssignationSequence) Assignation(org.thymeleaf.standard.expression.Assignation)

Example 2 with Expression

use of org.thymeleaf.standard.expression.Expression in project thymeleaf-tests by thymeleaf.

the class AddLocalVariableToResult method processAttribute.

@Override
protected ProcessorResult processAttribute(final Arguments arguments, final Element element, final String attributeName) {
    final String attributeValue = element.getAttributeValue(attributeName);
    final AssignationSequence assignationSequence = StandardExpressionProcessor.parseAssignationSequence(arguments, attributeValue, false);
    final Map<String, Object> localVariables = new HashMap<String, Object>();
    for (final Assignation assignation : assignationSequence.getAssignations()) {
        final String varName = assignation.getLeft().getValue();
        final Expression varValueExpr = assignation.getRight();
        final Object varValue = StandardExpressionProcessor.executeExpression(arguments, varValueExpr);
        localVariables.put(varName, varValue);
    }
    element.removeAttribute(attributeName);
    return ProcessorResult.setLocalVariables(localVariables);
}
Also used : HashMap(java.util.HashMap) Expression(org.thymeleaf.standard.expression.Expression) AssignationSequence(org.thymeleaf.standard.expression.AssignationSequence) Assignation(org.thymeleaf.standard.expression.Assignation)

Aggregations

Assignation (org.thymeleaf.standard.expression.Assignation)2 AssignationSequence (org.thymeleaf.standard.expression.AssignationSequence)2 Expression (org.thymeleaf.standard.expression.Expression)2 HashMap (java.util.HashMap)1