String nullOption value for the LookupPickerField causes the exception #1132

This commit is contained in:
Gleb Gorelov 2018-09-13 19:06:51 +04:00
parent 38bd1034a1
commit 5e22c79133
7 changed files with 67 additions and 7 deletions

View File

@ -33,9 +33,34 @@ public interface LookupField<V> extends OptionsField<V, V>, HasInputPrompt, Buff
return new TypeToken<LookupField<T>>() {}; return new TypeToken<LookupField<T>>() {};
} }
/**
* @deprecated Use {@link #getNullSelectionCaption()} instead
*/
@Deprecated
V getNullOption(); V getNullOption();
/**
* @deprecated Use {@link #setNullSelectionCaption(String)} instead
*/
@Deprecated
void setNullOption(V nullOption); void setNullOption(V nullOption);
/**
* @return the null selection caption, not {@code null}
*/
String getNullSelectionCaption();
/**
* Sets the null selection caption.
* <p>
* The empty string {@code ""} is the default null selection caption.
* <p>
* If null selection is allowed then the null item will be shown with the given caption.
*
* @param nullOption the caption to set, not {@code null}
*/
void setNullSelectionCaption(String nullOption);
FilterMode getFilterMode(); FilterMode getFilterMode();
void setFilterMode(FilterMode mode); void setFilterMode(FilterMode mode);

View File

@ -58,7 +58,7 @@ public class LookupFieldLoader extends AbstractFieldLoader<LookupField> {
String nullName = element.attributeValue("nullName"); String nullName = element.attributeValue("nullName");
if (StringUtils.isNotEmpty(nullName)) { if (StringUtils.isNotEmpty(nullName)) {
resultComponent.setNullOption(loadResourceString(nullName)); resultComponent.setNullSelectionCaption(loadResourceString(nullName));
} }
String pageLength = element.attributeValue("pageLength"); String pageLength = element.attributeValue("pageLength");

View File

@ -90,6 +90,10 @@ public class CubaComboBoxPickerField<T> extends CubaPickerField<T> {
getFieldInternal().setItems(captionFilter, items); getFieldInternal().setItems(captionFilter, items);
} }
public String getEmptySelectionCaption() {
return getFieldInternal().getEmptySelectionCaption();
}
public void setEmptySelectionCaption(String caption) { public void setEmptySelectionCaption(String caption) {
getFieldInternal().setEmptySelectionCaption(caption); getFieldInternal().setEmptySelectionCaption(caption);
} }

View File

@ -92,6 +92,10 @@ public class CubaSearchSelectPickerField<T> extends CubaPickerField<T> {
getFieldInternal().setItems(captionFilter, items); getFieldInternal().setItems(captionFilter, items);
} }
public String getEmptySelectionCaption() {
return getFieldInternal().getEmptySelectionCaption();
}
public void setEmptySelectionCaption(String caption) { public void setEmptySelectionCaption(String caption) {
getFieldInternal().setEmptySelectionCaption(caption); getFieldInternal().setEmptySelectionCaption(caption);
} }

View File

@ -85,7 +85,7 @@ public class WebLookupField<V> extends WebV8AbstractField<CComboBox<V>, V, V>
attachValueChangeListener(component); attachValueChangeListener(component);
setNewOptionAllowed(false); setNewOptionAllowed(false);
component.setItemCaptionGenerator(this::generateDefaultItemCaption); component.setItemCaptionGenerator(this::generateItemCaption);
/* vaadin8 move to new item handler /* vaadin8 move to new item handler
component.setNewItemHandler(newItemCaption -> { component.setNewItemHandler(newItemCaption -> {
@ -238,8 +238,17 @@ public class WebLookupField<V> extends WebV8AbstractField<CComboBox<V>, V, V>
@Override @Override
public void setNullOption(V nullOption) { public void setNullOption(V nullOption) {
this.nullOption = nullOption; this.nullOption = nullOption;
setNullSelectionCaption(generateItemCaption(nullOption));
}
component.setEmptySelectionCaption(generateItemCaption(nullOption)); @Override
public String getNullSelectionCaption() {
return component.getEmptySelectionCaption();
}
@Override
public void setNullSelectionCaption(String nullOption) {
component.setEmptySelectionCaption(nullOption);
setInputPrompt(null); setInputPrompt(null);
} }

View File

@ -106,7 +106,7 @@ public class WebLookupPickerField<V extends Entity> extends WebPickerField<V>
@Override @Override
protected void initComponent(CubaPickerField<V> component) { protected void initComponent(CubaPickerField<V> component) {
((CubaComboBoxPickerField<V>) component) ((CubaComboBoxPickerField<V>) component)
.setItemCaptionGenerator(this::generateDefaultItemCaption); .setItemCaptionGenerator(this::generateItemCaption);
component.addShortcutListener(new ShortcutListenerDelegate("clearShortcut", component.addShortcutListener(new ShortcutListenerDelegate("clearShortcut",
ShortcutAction.KeyCode.DELETE, new int[]{ShortcutAction.ModifierKey.SHIFT}) ShortcutAction.KeyCode.DELETE, new int[]{ShortcutAction.ModifierKey.SHIFT})
@ -148,8 +148,17 @@ public class WebLookupPickerField<V extends Entity> extends WebPickerField<V>
@Override @Override
public void setNullOption(V nullOption) { public void setNullOption(V nullOption) {
this.nullOption = nullOption; this.nullOption = nullOption;
setNullSelectionCaption(generateItemCaption(nullOption));
}
getComponent().setEmptySelectionCaption(generateItemCaption(nullOption)); @Override
public String getNullSelectionCaption() {
return getComponent().getEmptySelectionCaption();
}
@Override
public void setNullSelectionCaption(String nullOption) {
getComponent().setEmptySelectionCaption(nullOption);
setInputPrompt(null); setInputPrompt(null);
} }

View File

@ -112,7 +112,7 @@ public class WebSearchPickerField<V extends Entity> extends WebPickerField<V>
Messages messages = applicationContext.getBean(Messages.NAME, Messages.class); Messages messages = applicationContext.getBean(Messages.NAME, Messages.class);
setInputPrompt(messages.getMainMessage("searchPickerField.inputPrompt")); setInputPrompt(messages.getMainMessage("searchPickerField.inputPrompt"));
getComponent().setItemCaptionGenerator(this::generateDefaultItemCaption); getComponent().setItemCaptionGenerator(this::generateItemCaption);
getComponent().setFilterHandler(this::executeSearch); getComponent().setFilterHandler(this::executeSearch);
} }
@ -258,8 +258,17 @@ public class WebSearchPickerField<V extends Entity> extends WebPickerField<V>
@Override @Override
public void setNullOption(V nullOption) { public void setNullOption(V nullOption) {
this.nullOption = nullOption; this.nullOption = nullOption;
setNullSelectionCaption(generateItemCaption(nullOption));
}
getComponent().setEmptySelectionCaption(generateItemCaption(nullOption)); @Override
public String getNullSelectionCaption() {
return getComponent().getEmptySelectionCaption();
}
@Override
public void setNullSelectionCaption(String nullOption) {
getComponent().setEmptySelectionCaption(nullOption);
setInputPrompt(null); setInputPrompt(null);
} }