How to access the detail field in a master detail screen?

Hi,
How can I access to the detail field “resultval” as below? I tried in controller but it shows nullpointer error. Thank you very much.

  @Named("ipdetailTable.resultval")
    protected TextField resultvalField;
  @Override
    public void ready() {
   resultvalField.addValueChangeListener(this::updateIPResult);
   }
  private void updateIPResult(ValueChangeEvent valueChangeEvent) {

    }

Master-Detail

xml file

<layout expand="scrollBox"
            spacing="true">
        <scrollBox id="scrollBox"
                   spacing="true">
            <fieldGroup id="fieldGroup"
                        datasource="iPHEADERDs">
                <column width="250px">
                    <field property="ipbatch"/>
                    <field property="ipseq"/>
                    <field property="ipdate"/>
                    <field property="ipday"/>
                </column>
            </fieldGroup>
            <groupBox id="ipdetailBox"
                      caption="msg://com.company.mastert.entity/IPHEADER.ipdetail">
                <table id="ipdetailTable"
                       editable="true"
                       height="200px"
                       width="100%">
                    <actions>
                        <action id="create"/>
                        <action id="edit"/>
                        <action id="remove"/>
                    </actions>
                    <columns>
                        <column id="groupnm"/>
                        <column id="testtype"/>
                        <column id="isnum"/>
                        <column id="testname1"/>
                        <column id="target"/>
                        <column id="resultval" editable="true"/>
                    </columns>
                    <rows datasource="ipdetailDs"/>
                    <buttonsPanel>
                        <button action="ipdetailTable.create"/>
                        <button action="ipdetailTable.edit"/>
                        <button action="ipdetailTable.remove"/>
                    </buttonsPanel>
                </table>
            </groupBox>
        </scrollBox>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>

Hi,
You can make your ‘Resultval’ column generated. Then you can get acces to that field (since you creating it by yourself).

public Component columnGenerator(Ipdetail entity){
    TextField field = componentsFactory.createComponent(TextField.class);
    field.setValue(entity.getResultval());
    field.addValueChangeListener(e -> {
        //your logic goes here
    });
    return field
}

Or, if i understend your task right you can use ItemPropertyChangeListener on your datasource.

btw DatasourceListener doc page doesn’t have anchors :disappointed_relieved:

1 Like

Hi,
Thank you. How can I get to know which line is editted by users? The detail is a list not a single instance.

    @Override
    public void init(Map<String, Object> params) {
        ipdetailDs.addItemPropertyChangeListener(this::updateIPResult);;
    }
    private void updateIPResult(Datasource.ItemPropertyChangeEvent itemPropertyChangeEvent) {

    }

I tried below. It works.

    private void updateIPResult(Datasource.ItemPropertyChangeEvent itemPropertyChangeEvent) {
        IPDETAIL ipdetail = (IPDETAIL)itemPropertyChangeEvent.getItem();
        if(ipdetail.getIsnum() == YN.Y)
        {
            double resultVal = Double.parseDouble(ipdetail.getResultval());

        }
    }
1 Like