I have the following
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://editorCaption"
class="com.dtc.callbook.web.address.AddressEdit"
datasource="addressDs"
focusComponent="userInput"
messagesPack="com.dtc.callbook.web.address">
<dsContext>
<datasource id="addressDs"
class="com.dtc.callbook.entity.Address"
view="_local"/>
</dsContext>
<dialogMode height="600"
width="800"/>
<layout spacing="true">
<vbox margin="false,false,false,true"
spacing="true">
<hbox expand="userInput"
width="100%">
...
<hbox expand="addressField"
width="100%">
<label value="msg://chosenAddress"/>
<textField id="addressField"
datasource="addressDs"
editable="false"
property="name"
required="true"/>
</hbox>
...
</vbox>
<hbox id="windowActions"
height="100%"
spacing="true"
width="100%">
<button id="windowCommit"
action="windowCommit"
invoke="onSaveBtnClick"/>
<button id="windowClose"
action="windowClose"/>
</hbox>
</layout>
</window>
But there was no validation by default for addressField
Why?
So you see I added my function but onSaveBtnClick
isn’t called. Why?
so if I change it to
...
<button id="windowCommit"
invoke="onSaveBtnClick"/>
then onSaveBtnClick
gets called but validation doesn’t happen…
package com.dtc.callbook.web.address;
import com.haulmont.cuba.gui.components.AbstractEditor;
//...
import static java.util.Collections.singletonList;
public class AddressEdit extends AbstractEditor<Address> {
@Inject
private TextField addressField;
//...
public void onFindBtnClick() {
//...
}
@Override
public void init(Map<String, Object> params) {
super.init(params);
//...
addressField.addValidator(value -> {
//debugger doesn't get into here! WHY?!
if (value.equals("")) {
throw new ValidationException("You cannot select admin user");
}
});
}
public void onSaveBtnClick() {
validate(singletonList(addressField));
}
}
As far as I can see it doesn’t work because in com.haulmont.cuba.web.gui.components.WebAbstractField
isEditableWithParent()
returns false
…
I will try to replace custom fields with fieldGroup but why doesn’t it work currently?