Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Replace groovy template engine with java template engine #20

Closed
GlebDurygin opened this issue Aug 17, 2020 · 0 comments
Closed

Replace groovy template engine with java template engine #20

GlebDurygin opened this issue Aug 17, 2020 · 0 comments
Assignees
Milestone

Comments

@GlebDurygin
Copy link
Contributor

Description of the bug or enhancement

AbstractValidator.getTemplateErrorMessage method throws NotImplementedException.

    protected String getTemplateErrorMessage(@Nullable String errorMessage, Map<String, Object> values) {
// todo VM
        throw new NotImplementedException("");

//        if (!Strings.isNullOrEmpty(errorMessage)) {
//            StringWriter writer = new StringWriter();
//            try {
//                GStringTemplateEngine engine = new GStringTemplateEngine();
//                engine.createTemplate(errorMessage).make(values).writeTo(writer);
//                return writer.toString();
//            } catch (ClassNotFoundException | IOException e) {
//                throw new IllegalStateException(e);
//            }
//        }
//        return errorMessage;
    }
  • Minimal reproducible example
  1. Define a validator with default validation message for TextField component.
@UiController("textfield-validator")
@UiDescriptor("textfield-validator.xml")
public class TextFieldValidatorSample extends ScreenFragment {

    @Autowired
    protected TextField<Integer> integerTextField;
    @Autowired
    protected TextField<Double> doubleTextField;
    @Autowired
    protected Notifications notifications;

    @Subscribe("validate")
    protected void onValidateClick(Button.ClickEvent event) {
        try {
            doubleTextField.validate();
            notifications.create()
                    .withCaption("Validation successful")
                    .show();
        } catch (ValidationException e) {
            notifications.create()
                    .withCaption("Validation failed: " + e.getMessage())
                    .withType(Notifications.NotificationType.ERROR)
                    .show();
        }
    }
}
<window xmlns="http://jmix.io/schema/ui/window">
    <layout>
        <hbox spacing="true">
            <textField id="doubleTextField"
                       caption="msg://doubleTextField"
                       datatype="double">
                <validators>
                    <doubleMin value="1.0" inclusive="true"/>
                    <doubleMax value="100.0" inclusive="true"/>
                </validators>
            </textField>
            <button id="validate" caption="msg://validateBtn"/>
        </hbox>
    </layout>
</window>
  1. Enter a "0" in the doubleTextField
  • Actual behavior
    NotImplementedException org.apache.commons.lang3.NotImplementedException: at io.jmix.ui.component.validation.AbstractValidator.getTemplateErrorMessage(AbstractValidator.java:68) at io.jmix.ui.component.validation.DoubleMinValidator.fireValidationException(DoubleMinValidator.java:188) at io.jmix.ui.component.validation.DoubleMinValidator.accept(DoubleMinValidator.java:172) at io.jmix.ui.component.impl.WebV8AbstractField.triggerValidators(WebV8AbstractField.java:226) at io.jmix.ui.component.impl.WebV8AbstractField.validate(WebV8AbstractField.java:219) at io.jmix.sampler.screen.ui.components.textfield.validator.TextFieldValidatorSample.onValidateClick(TextFieldValidatorSample.java:28) at io.jmix.core.common.event.EventHub.publish(EventHub.java:170) at io.jmix.ui.component.impl.WebAbstractComponent.publish(WebAbstractComponent.java:85) at io.jmix.ui.component.impl.WebButton.buttonClicked(WebButton.java:68)
@GlebDurygin GlebDurygin added this to the M2 milestone Aug 17, 2020
@knstvk knstvk modified the milestones: M2, 0.1.0 Aug 24, 2020
@web-devel web-devel assigned glebfox and unassigned web-devel Sep 17, 2020
@glebfox glebfox assigned GlebDurygin and unassigned glebfox Sep 21, 2020
@GlebDurygin GlebDurygin changed the title Implement AbstractValidator.getTemplateErrorMessage method Replace groovy template engine with java template engine Sep 25, 2020
GlebDurygin pushed a commit to jmix-projects/jmix-translations that referenced this issue Oct 1, 2020
GlebDurygin pushed a commit to jmix-framework/jmix-ui-samples that referenced this issue Oct 1, 2020
GlebDurygin pushed a commit to jmix-projects/jmix-dynattr that referenced this issue Oct 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants