Hello,
I am trying to implement Bean validation and integrate it with Editors.

I have following code base:

*DomainConfigComponent.java*

import com.github.gwtbootstrap.client.ui.ValueListBox;
import com.google.gwt.editor.client.HasEditorErrors;
import com.google.gwt.editor.client.IsEditor;
import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor;
import com.google.gwt.user.client.ui.IsWidget;
import com.hat.weevify.client.domain.DomainConfig;

public interface DomainConfigComponent extends IsWidget, 
HasEditorErrors<DomainConfig> {
    
    void setPresenter(Presenter presenter);

    public interface Presenter {
        
    }
    
    @Path("id")
    IsEditor<ValueBoxEditor<Integer>> getId();
    
    @Path("textDirection")
    ValueListBox<String> getTextDirectionEditor();
    
    @Path("name")
    IsEditor<ValueBoxEditor<String>> getSiteNameEditor();
    
    @Path("siteEmail")
    IsEditor<ValueBoxEditor<String>> getSiteEmailEditor();
    
    @Path("contactEmail")
    IsEditor<ValueBoxEditor<String>> getContactEmailEditor();
    
    @Path("favicon")
    IsEditor<ValueBoxEditor<String>> getFaviconEditor();
    
    @Path("host")
    IsEditor<ValueBoxEditor<String>> getHostEditor();
    
    @Path("landingPage")
    IsEditor<ValueBoxEditor<String>> getLandingPage();
    
    @Path("defaultLanguageId")
    public ValueListBox<Integer> getDefaultLanguageEditor();
    
    public void reset();
    public Boolean save();
    
}


*DomainConfigComponentImpl.java*

import java.io.IOException;
import java.util.List;

import com.github.gwtbootstrap.client.ui.FluidRow;
import com.github.gwtbootstrap.client.ui.Form;
import com.github.gwtbootstrap.client.ui.IntegerBox;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.ValueListBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.EditorError;
import com.google.gwt.editor.client.IsEditor;
import com.google.gwt.editor.ui.client.ValueBoxEditorDecorator;
import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor;
import com.google.gwt.text.shared.Renderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Widget;
import com.hat.weevify.client.domain.Language;
import com.hat.weevify.client.system.SystemData;

public class DomainConfigComponentImpl implements DomainConfigComponent {

    interface DomainConfigComponentImplUiBinder extends UiBinder<FluidRow, 
DomainConfigComponentImpl> {
    }

    private static DomainConfigComponentImplUiBinder    uiBinder    = 
GWT.create(DomainConfigComponentImplUiBinder.class);

    private Presenter                                    presenter;

    private final FluidRow                                settingsContainer;

    @UiField
    Form                                                siteConfigForm;

    @UiField
    IntegerBox                                            id;

    @UiField(provided = true)
    ValueListBox<String>                                textDirection;
    @UiField(provided = true)
    ValueListBox<Integer>                                defaultLanguage;

    @UiField
    TextBox                                                siteName;
    @UiField
    TextBox                                                host;
    @UiField
    TextBox                                                siteEmail;
    @UiField
    TextBox                                                contactEmail;

    @UiField
    ValueBoxEditorDecorator<String>                        favicon;

    @UiField
    TextBox                                                landingPage;

    public DomainConfigComponentImpl() {

        textDirection = new ValueListBox<String>(new Renderer<String>() {

            public void render(String object, Appendable appendable) throws 
IOException {
                appendable.append(render(object));
            }

            public String render(String object) {
                return object;
            }
        });

        defaultLanguage = new ValueListBox<Integer>(new Renderer<Integer>() 
{

            public String render(Integer object) {
                for (Language lang : 
SystemData.getInstance().getLanguageList()) {
                    if (lang.getId() == object) {
                        return lang.getName();
                    }
                }
                return null;
            }

            public void render(Integer object, Appendable appendable) 
throws IOException {
                String s = render(object);
                appendable.append(s);
            }

        });

        settingsContainer = uiBinder.createAndBindUi(this);
    }

    public Widget asWidget() {
        return settingsContainer;
    }

    public void setPresenter(Presenter presenter) {
        this.presenter = presenter;
    }

    public void reset() {
        // TODO implement reset method
    }

    public Boolean save() {
        // TODO Auto-generated method stub
        return null;
    }

    public IsEditor<ValueBoxEditor<Integer>> getId() {
        return id;
    }

    public ValueListBox<String> getTextDirectionEditor() {
        return textDirection;
    }

    public ValueListBox<Integer> getDefaultLanguageEditor() {
        return defaultLanguage;
    }

    public IsEditor<ValueBoxEditor<String>> getSiteNameEditor() {
        return siteName;
    }

    public IsEditor<ValueBoxEditor<String>> getSiteEmailEditor() {
        return siteEmail;
    }

    public IsEditor<ValueBoxEditor<String>> getContactEmailEditor() {
        return contactEmail;
    }

    public IsEditor<ValueBoxEditor<String>> getFaviconEditor() {
        return favicon;
    }

    public IsEditor<ValueBoxEditor<String>> getHostEditor() {
        return host;
    }

    public IsEditor<ValueBoxEditor<String>> getLandingPage() {
        return landingPage;
    }

    public void showErrors(List<EditorError> errors) {
        if (!errors.isEmpty()) {
            favicon.showErrors(errors);
        }
    }
}


And in activity I have declared interface

    interface DomainEditorDriver extends 
> SimpleBeanEditorDriver<DomainConfig, DomainConfigComponent> {
>     }
>

and snippet that is actually performing validations

        Validator validator = 
> Validation.buildDefaultValidatorFactory().getValidator();
>         Set<ConstraintViolation<DomainConfig>> violations = 
> validator.validate(currentDomainEditor.flush());
>
>         if (!violations.isEmpty()) {
>             @SuppressWarnings({ "rawtypes", "unchecked" })
>             Iterable<ConstraintViolation<?>> violations2 = 
> (Iterable<ConstraintViolation<?>>) (Set) violations;
>             currentDomainEditor.setConstraintViolations(violations2);
>             
>             return;
>         }
>


If I don't put

        if (!errors.isEmpty()) {
            favicon.showErrors(errors);
        }

in DomainConfigComponentImpl showErrors method, favicon editor decorator 
does not display errors even if there are errors with favicon property. So 
basicaly constraint violations does not propagate to other editors.

Any help is  welcome.

Thanks,
Milan


-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/QocoMLACZQAJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to