Project

General

Profile

« Previous | Next » 

Revision ee53ccf7

Added by Andreas Kohlbecker about 5 years ago

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
29 29

  
30 30
import eu.etaxonomy.cdm.vaadin.component.ButtonFactory;
31 31
import eu.etaxonomy.cdm.vaadin.event.NestedButtonStateUpdater;
32
import eu.etaxonomy.cdm.vaadin.ui.UIMessages;
32 33

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

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

  
......
174 185
        setValue(bean);
175 186
    }
176 187

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

  
188 189
    public UUID getIdForValue(){
189 190
        return filterablePagingProvider.idFor(getValue());
......
248 249
        }
249 250
    }
250 251

  
252

  
253
    @Override
254
    public void setRequired(boolean required) {
255
        super.setRequired(required);
256
        lazySelect.setRequired(required);
257
    }
258

  
259
    @Override
260
    public void setImmediate(boolean immediate){
261
        super.setImmediate(immediate);
262
        lazySelect.setImmediate(immediate);
263
    }
264

  
251 265
    @Override
252 266
    public void updateButtons(){
253 267
        buttonUpdater.updateButtons(getValue());
254 268
    }
255 269

  
270
    @Override
271
    public void commit() throws SourceException, InvalidValueException {
272
        lazySelect.commit();
273
    }
274

  
275
    /**
276
    *
277
    */
278
   public void commitSelect() {
279
       try {
280
           setComponentError(null);
281
           lazySelect.commit();
282
       } catch (InvalidValueException ex){
283
           UserError componentError = new UserError(ex.getHtmlMessage(), ContentMode.HTML, ErrorLevel.ERROR);
284
           lazySelect.setComponentError(componentError);
285
       }
286
   }
287

  
288

  
289

  
256 290
    /**
257 291
     * {@inheritDoc}
258 292
     * @deprecated NestedButtonStateUpdater should rather be instantiated in the RelatedEntityField instead of passing it as property
......
306 340
        }
307 341
    }
308 342

  
309

  
310

  
311 343
}

Also available in: Unified diff