Project

General

Profile

« Previous | Next » 

Revision 98a2455f

Added by Andreas Kohlbecker over 5 years ago

fix #7245 fixing validation of ToOneRelatedEntityCombobox and re-enabling TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE

View differences:

src/main/java/eu/etaxonomy/vaadin/component/ToOneRelatedEntityCombobox.java
12 12
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
13 13

  
14 14
import com.vaadin.data.Property;
15
import com.vaadin.data.Validator.InvalidValueException;
15 16
import com.vaadin.data.fieldgroup.FieldGroup;
16 17
import com.vaadin.data.util.converter.Converter.ConversionException;
18
import com.vaadin.server.AbstractErrorMessage.ContentMode;
19
import com.vaadin.server.ErrorMessage;
20
import com.vaadin.server.ErrorMessage.ErrorLevel;
21
import com.vaadin.server.UserError;
17 22
import com.vaadin.ui.Button;
18 23
import com.vaadin.ui.Button.ClickListener;
19 24
import com.vaadin.ui.Component;
......
50 55
        this.type = type;
51 56
        setCaption(caption);
52 57
        lazySelect = new ReloadableLazyComboBox<V>(type);
58
        lazySelect.setValidationVisible(false); // validation is to be shown for the ToOneRelatedEntityCombobox
59
        lazySelect.setRequiredError("Must be given");
60
        setRequiredError("Must be given");
53 61
        addStyledComponents(lazySelect, addButton, editButton);
54 62
        addSizedComponents(lazySelect, container);
63
        // lazySelect.setImmediate(true); // should cause immediate validation, however,
64
        // it does not work here, therefore we validate in the commitSelect() method during the commit
55 65
        lazySelect.addValueChangeListener(e -> {
56 66
            // update the itemContainer immediately so that the edit button acts on the chosen item
57
            lazySelect.commit();
67
            commitSelect();
58 68
        });
59 69
    }
60 70

  
......
169 179
     */
170 180
    @Override
171 181
    public V getValue() {
172
        lazySelect.commit();
182
        commitSelect();
173 183
        return lazySelect.getValue();
174 184
    }
175 185

  
176 186

  
187

  
188

  
189
    /**
190
     *
191
     */
192
    public void commitSelect() {
193
        try {
194
            setComponentError(null);
195
            lazySelect.commit();
196
        } catch (InvalidValueException ex){
197
            UserError componentError = new UserError(ex.getHtmlMessage(), ContentMode.HTML, ErrorLevel.ERROR);
198
            setComponentError(componentError);
199
        }
200
    }
201

  
202

  
177 203
    /**
178 204
     * {@inheritDoc}
179 205
     */
......
222 248
    }
223 249

  
224 250

  
251
    @Override
252
    public void validate() throws InvalidValueException {
253
        super.validate();
254
        lazySelect.validate();
255
    }
256

  
257

  
258
    @Override
259
    public ErrorMessage getErrorMessage() {
260
        ErrorMessage errorMessage = lazySelect.getErrorMessage();
261
        return errorMessage;
262
    }
263

  
264

  
265
    @Override
266
    public boolean isValid() {
267
        return lazySelect.isValid();
268
    }
269

  
270
    @Override
271
    public void setRequired(boolean required) {
272
        super.setRequired(required);
273
        lazySelect.setRequired(required);
274
    }
275

  
276

  
277
    @Override
278
    public boolean isRequired() {
279
        return lazySelect.isRequired();
280
    }
281

  
282
    @Override
283
    public void setImmediate(boolean immediate) {
284
        super.setImmediate(immediate);
285
        lazySelect.setImmediate(immediate);
286
    }
287

  
288

  
289
    @Override
290
    public void commit() throws SourceException, InvalidValueException {
291
        lazySelect.commit(); // we must not use the commitSelect() here to allow InvalidValueException to be handled by the caller
292
        super.commit();
293
    }
294

  
295

  
296
    @Override
297
    public void setComponentError(ErrorMessage componentError) {
298
        lazySelect.setComponentError(componentError);
299
        super.setComponentError(componentError);
300
    }
301

  
302

  
303

  
225 304
}

Also available in: Unified diff