SuggestionField / Picker Filed save null value

Hi,
i’ve a problem about the SuggestionField or PickerField when i clear the value.
If i change value, this is saved correctly, but when i try to clear (so i want to set a null value ) and save,
edit entity is not affected by the change.
Any “suggestions” :slight_smile:

My entity property is:

@SystemLevel
@Embedded
@AttributeOverrides({
           @AttributeOverride(name = "codComune", column = @Column(name = "COMUNE_NASCITA_ID_COD_COMUNE")),
            @AttributeOverride(name = "codPv", column = @Column(name = "COMUNE_NASCITA_ID_COD_PV"))
    })
    protected TcT23ComuniCompKey comuneNascitaId;

    @Transient
    @MetaProperty(related = "comuneNascitaId")
    protected TcT23Comuni comuneNascita;

There is a reference to the entity of different store.

Here the suggestion field:

 <suggestionPickerField id="comuneNascitaField"
                                           inputPrompt="Scrivi il comune"
                                           property="comuneNascita" captionProperty="descrComune"
                                           width="100%" minSearchStringLength ="3" dataContainer="componentiDc">
                        <query entityClass="com.ls.smc.entity.TcT23Comuni" escapeValueForLike="true" view="_local"
                               searchStringFormat="%$searchString%">
                            <![CDATA[select e from smc_TcT23Comuni e where e.descrComune like :searchString escape '\']]></query>
                        <actions>
                            <action id="clearNascita" type="picker_clear" visible="true" enable="true" />
                        </actions>
</suggestionPickerField>

Hi @tony.fauzzi,

Can you send the code of screen controller and XML descriptor? What version of the platform are you using? Do you override the clear action in controller?
I tried to play the case and the SuggesterPickerField’s value was reset when I clicked the clear button, i.e. everything worked correctly.

Regards,
Gleb

1 Like

Hi @durygin
Thanks in advance. I’m using cuba 7.1.1 version.
The property comuneNascita is an association with another table TcT23Comuni of another store (not a main store). After various attempts i understand that:

  1. Using dataManager to commit values:
    When i clear value of suggestion field this is not performed.
    I tried with Controller code:
@Subscribe("comuneNascitaField.clearNascita")
        public void onComuneNascitaFieldClearNascita(Action.ActionPerformedEvent event) {
                componentiDc.getItem().setComuneNascitaId(new TcT23ComuniCompKey().withNullValues());
                componentiDc.getItem().setComuneNascita(null);
        }

Or

@Subscribe("comuneNascitaField")
    public void onComuneNascitaFieldValueChange(HasValue.ValueChangeEvent<TcT23Comuni> event) {
            if(event.getValue()==null){
                          componentiDc.getItem().setComuneNascitaId(new TcT23ComuniCompKey().withNullValues());
                    componentiDc.getItem().setComuneNascita(null);

            }
    }

without any success.

  1. Using Entity Manager to save values with Controller code:

@Subscribe(“comuneNascitaField”)
public void onComuneNascitaFieldValueChange(HasValue.ValueChangeEvent event) {
if(event.getValue()!=null){
componentiDc.getItem().setComuneNascitaId(event.getValue().getId());
}else{
componentiDc.getItem().setComuneNascitaId(new TcT23ComuniCompKey().withNullValues());
componentiDc.getItem().setComuneNascita(null);
}
}

And service code on commit (Using Entity Manager):

   if (entityStates.isNew(componente)) {
                        em.persist(componente);
                    } else {
                        em.merge(componente);
                    }
                    em.flush();

It work.

Seems to be a problem of dataManager that don’t update null value on clear.