0

I have model which represents an Employee. It has a field(let's say salary) which is also a model. So basically it is a nested property. I use Hibernate, JPAcontainer and MasterDetailEditor to visualize the data. So I extended the FieldFactory to be able to add a value change listener to the select field of salary. This change sets the tax field of the salary.

It is working, the data is updated in the DB but on the UI, not. I tried it with Push enabled, with pollInterval, none of them seems to work. I set the value through its property.

code:

This is in the overridden createField

    final AbstractField field = (AbstractField) super.createField(container, itemId, propertyId, uiContext);
        field.setImmediate(true);

        field.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {

                final Item item = container.getItem(itemId);
                final String salaryTypeSelectorValue =
                        item.getItemProperty(propertyName).getValue().toString() != null ? item.getItemProperty(propertyName).getValue()
                                .toString() : REGULAR;

                                if (REGULAR.equals(salaryTypeSelectorValue)) {

                                    final SalaryHistory salaryHistory = ((JPAContainer<SalaryHistory>) container).getItem(itemId).getEntity();

                                    JPAContainer<SalaryHistory> salaryHistoryContainer = (JPAContainer<SalaryHistory>) container;

                                    salaryHistoryContainer.getItem(itemId).getItemProperty("socialTax").setValue(new BigDecimal("28.5"));                                     
                                }
            }
        });         

        return field; 

Update

I managed to achieve what I want, maybe it is a bit hacky, because I had to put a tiny logic into the salary model: In the setter of salary type I set the tax too and the UI updates immediately.

user3511545
  • 71
  • 1
  • 6
  • my guess would be, that jpacontainer holds a cache and changing a value somewhere in it will propagate into the table. have you tried marking the table dirty? – cfrick Feb 24 '15 at 16:29
  • I'll try. Thanks. I forgot to mention that JPAContainerFactory.makeNonCached is used and immediate mode is true and buffering is disabled. – user3511545 Feb 24 '15 at 16:32
  • If you solve your problem yourself, please add an answer to the post (and accept it later). It's much easier for other users to identify possible solutions and see that the problem is solved. Thanks! – Jan Galinski Feb 26 '15 at 10:21

1 Answers1

0

Thanks for notifying me Jan :) I managed to achieve what I want, maybe it is a bit hacky, because I had to put a tiny logic into the salary model: In the setter of salary type I set the tax too and the UI updates immediately.

user3511545
  • 71
  • 1
  • 6