Project

General

Profile

« Previous | Next » 

Revision ddb31e64

Added by Andreas Kohlbecker about 5 years ago

  • ID ddb31e64c51be1fd555999535863cebe68a6bd8d
  • Parent 77056dda

fix #8214 fixing required validation for WeaklyRelatedEntityCombobox and centralizing related messages

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/ui/UIMessages.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.ui;
10

  
11
/**
12
 * @author a.kohlbecker
13
 * @since Mar 29, 2019
14
 *
15
 */
16
public class UIMessages {
17

  
18
    public static final String REQUIRED_SELECT_MISSING = "This field is required. Please select a value.";
19

  
20
    public static final String REQUIRED_TEXT_MISSING = "This field is required. Please enter a value.";
21

  
22
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
47 47
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
48 48
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
49 49
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
50
import eu.etaxonomy.cdm.vaadin.ui.UIMessages;
50 51
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
51 52
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
52 53
import eu.etaxonomy.vaadin.component.NameRelationField;
......
767 768
                            );
768 769
                        }
769 770
                    });
771
                    combobox.getSelect().setRequiredError(UIMessages.REQUIRED_SELECT_MISSING);
770 772
                    genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, combobox, 0, genusOrUninomialRow, 1, genusOrUninomialRow);
771 773
                }
772 774
            } else {
773 775
                if(WeaklyRelatedEntityCombobox.class.isAssignableFrom(genusOrUninomialField.getClass())) {
774 776
                    genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, new TextFieldNFix(), 0, genusOrUninomialRow, 1, genusOrUninomialRow);
777
                    genusOrUninomialField.setRequiredError(UIMessages.REQUIRED_TEXT_MISSING);
775 778
                }
776 779
            }
777 780
        }
......
781 784
                if(TextField.class.isAssignableFrom(specificEpithetField.getClass())) {
782 785
                    WeaklyRelatedEntityCombobox<TaxonName> combobox = new WeaklyRelatedEntityCombobox<TaxonName>("-> this caption will be replaced <-", TaxonName.class);
783 786
                    specificEpithetField = replaceComponent("specificEpithet", specificEpithetField, combobox, 0, specificEpithetFieldRow, 1, specificEpithetFieldRow);
787
                    combobox.getSelect().setRequiredError(UIMessages.REQUIRED_SELECT_MISSING);
784 788
                    combobox.addClickListenerAddEntity(e -> getViewEventBus().publish(
785 789
                            this,
786 790
                            new TaxonNameEditorActionStrRep(EditorActionType.ADD, e.getButton(), combobox, this)
......
801 805
            } else {
802 806
                if(WeaklyRelatedEntityCombobox.class.isAssignableFrom(specificEpithetField.getClass())) {
803 807
                    specificEpithetField = replaceComponent("specificEpithet", specificEpithetField, new TextFieldNFix(), 0, specificEpithetFieldRow, 1, specificEpithetFieldRow);
808
                    specificEpithetField.setRequiredError(UIMessages.REQUIRED_TEXT_MISSING);
804 809
               }
805 810
            }
806 811
        }
......
820 825
        specificEpithetField.setRequired(isSpeciesOrBelow);
821 826
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
822 827
        infraSpecificEpithetField.setRequired(rank.isInfraSpecific());
828
        infraSpecificEpithetField.setRequiredError(UIMessages.REQUIRED_TEXT_MISSING);
823 829
        infraGenericEpithetField.setVisible(rank.isInfraGeneric());
824 830
        infraGenericEpithetField.setRequired(rank.isInfraGeneric());
831
        infraSpecificEpithetField.setRequiredError(UIMessages.REQUIRED_TEXT_MISSING);
825 832

  
826 833
        basionymsComboboxSelect.setVisible(withBasionymSection);
827 834

  
src/main/java/eu/etaxonomy/vaadin/component/ToOneRelatedEntityCombobox.java
27 27

  
28 28
import eu.etaxonomy.cdm.vaadin.component.ButtonFactory;
29 29
import eu.etaxonomy.cdm.vaadin.event.NestedButtonStateUpdater;
30
import eu.etaxonomy.cdm.vaadin.ui.UIMessages;
30 31

  
31 32
/**
32 33
 * @author a.kohlbecker
......
55 56
        this.type = type;
56 57
        setCaption(caption);
57 58
        lazySelect = new ReloadableLazyComboBox<V>(type);
58
        lazySelect.setRequiredError("Must be given");
59
        setRequiredError("Must be given");
59
        lazySelect.setRequiredError(UIMessages.REQUIRED_SELECT_MISSING);
60 60
        addStyledComponents(lazySelect, addButton, editButton);
61 61
        addSizedComponents(lazySelect, container);
62 62
        // lazySelect.setImmediate(true); // should cause immediate validation, however,
src/main/java/eu/etaxonomy/vaadin/component/WeaklyRelatedEntityCombobox.java
14 14
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
15 15

  
16 16
import com.vaadin.data.Property;
17
import com.vaadin.data.Validator.InvalidValueException;
17 18
import com.vaadin.data.fieldgroup.FieldGroup;
18 19
import com.vaadin.data.util.converter.Converter.ConversionException;
20
import com.vaadin.server.AbstractErrorMessage.ContentMode;
21
import com.vaadin.server.ErrorMessage.ErrorLevel;
22
import com.vaadin.server.UserError;
19 23
import com.vaadin.ui.Button;
20 24
import com.vaadin.ui.Button.ClickListener;
21 25
import com.vaadin.ui.Component;
......
63 67
        addSizedComponents(lazySelect, container);
64 68
        buttonUpdater = new WeaklyRelatedEntityButtonUpdater(this);
65 69
        lazySelect.addValueChangeListener(buttonUpdater);
70
        lazySelect.setValidationVisible(true);
66 71
        lazySelect.addValueChangeListener(e -> {
67 72
            // update the itemContainer immediately so that the edit button acts on the chosen item
73
            // TODO compare with ToOneRelatedEntityCombobox where getValue() is overwritten to call
74
            //  commitSelect();; would this help in this class also?
75
            try {
68 76
            lazySelect.commit();
77
            } catch (InvalidValueException ie){
78
                /* Ignore here */
79
            }
69 80
        });
70 81
    }
71 82

  
......
172 183
        setValue(bean);
173 184
    }
174 185

  
175
    /**
176
     * Returns always currently selected item by
177
     *
178
     * {@inheritDoc}
179
     */
180
    @Override
181
    public String getValue() {
182
        lazySelect.commit();
183
        return lazySelect.getValue();
184
    }
185 186

  
186 187
    public UUID getIdForValue(){
187 188
        return filterablePagingProvider.idFor(getValue());
......
235 236
        }
236 237
    }
237 238

  
239

  
240
    @Override
241
    public void setRequired(boolean required) {
242
        super.setRequired(required);
243
        lazySelect.setRequired(required);
244
    }
245

  
246
    @Override
247
    public void setImmediate(boolean immediate){
248
        super.setImmediate(immediate);
249
        lazySelect.setImmediate(immediate);
250
    }
251

  
238 252
    @Override
239 253
    public void updateButtons(){
240 254
        buttonUpdater.updateButtons(getValue());
241 255
    }
242 256

  
257
    @Override
258
    public void commit() throws SourceException, InvalidValueException {
259
        lazySelect.commit();
260
    }
261

  
262
    /**
263
    *
264
    */
265
   public void commitSelect() {
266
       try {
267
           setComponentError(null);
268
           lazySelect.commit();
269
       } catch (InvalidValueException ex){
270
           UserError componentError = new UserError(ex.getHtmlMessage(), ContentMode.HTML, ErrorLevel.ERROR);
271
           lazySelect.setComponentError(componentError);
272
       }
273
   }
274

  
275

  
276

  
243 277
    /**
244 278
     * {@inheritDoc}
245 279
     * @deprecated NestedButtonStateUpdater should rather be instantiated in the RelatedEntityField instead of passing it as property
......
293 327
        }
294 328
    }
295 329

  
296

  
297

  
298 330
}

Also available in: Unified diff