Hi,
Working with an older version of Cuba (6.10) and have minimal experience with Cuba and Java.
I would like to auto populate a date field based on another date field. So that when someone enters a date in fieldA the entry for fieldA120 is populated with fieldA’s date + 120 days.
I modified this version - How to update fieldgroup property using a Datasource? - CUBA.Platform
The app builds, but entering a date value in field A no other fields update.
I hope someone can point me in the right direction or another approach.
Here is my edit.xml
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://editorCaption"
class="com.company.dateadditionexample.web.datetest.DateTestEdit"
datasource="dateTestDs"
focusComponent="fieldGroup"
messagesPack="com.company.uhsdateadditionexample.web.datetest">
<dsContext>
<datasource id="dateTestDs"
class="com.company.uhsdateadditionexample.entity.DateTest"
view="_local"/>
</dsContext>
<dialogMode height="600"
width="800"/>
<layout expand="windowActions"
spacing="true">
<fieldGroup id="fieldGroup"
datasource="dateTestDs">
<column width="250px">
<field property="dateA"/>
<field property="dateA120"/>
<field property="dateb"/>
<field property="dateb120"/>
</column>
</fieldGroup>
<frame id="windowActions"
screen="editWindowActions"/>
</layout>
</window>
Here is my current Controller
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.uhsdateadditionexample.entity.DateTest;
import com.haulmont.cuba.gui.components.DateField;
import javax.inject.Named;
import java.util.Date;
public class DateTestEdit extends AbstractEditor<DateTest> {
@Named("fieldGroup.dateA")
private DateField dateAField;
@Named("fieldGroup.dateA120")
private DateField dateA120Field;
@Override
public void ready() {
dateAField.addValueChangeListener(this::updatedateA120);
}
private void updatedateA120(ValueChangeEvent ignored) {
if (dateAField.getValue() == null || dateA120Field.getValue() == null) {
return;
}
Date dateA = dateAField.getValue();
Date dateA120 = dateA120Field.getValue();
getItem().setDateA120(dateA);
}
}
Thank you for taking a look!