Enum remove blank row

Hello,

How can I remove the blank row from an Enumeration?
image

Hi,

You can either define the nullOptionVisible="false" attribute declarativelly or set setNullOptionVisible(false) programmatically.

Where should I set nullOptionVisible=“false” attribute ? In Enum.java or in edit.xml?

The same, where should I set setNewOptionAllowed(false)? In controller I don’t have neither payment. (setNewOptionAllowed) nor payment.setStatus(setNewOptionAllowed).
I saw that is present in LookupField interface.

Sorry for the unclear answer, you’re right, this attribute is presented by the LookupField component that is used to display the value of the Entity attribute presented by the enum. In screen XML descriptor you can define the nullOptionVisible attribute for the lookupField element, but since it’s an edit screen then I suppose you have the fieldGroup component within it, so you have no access to this attribute declaratively. So, in the screen controller, you need to inject the corresponding field component and invoke the setNullOptionVisible method. Also, if you define the corresponding entity attribute as a mandatory attribute, then you’’ need no manual tunes for UI components that display this particular entity attribute.

Is something wrong here, doesn’t work.

    @Named("fieldGroup.status")
    private LookupField statusField;

    private boolean blankSpace(){
       statusField.setNewOptionAllowed(false);
       return false;
   }

Do you call the blankSpace method somewhere?

It’s recommended to call statusField.setNullOptionVisible(false); in the init method.

@Named("fieldGroup.status")
private LookupField statusField;

@Override
public void init(Map<String, Object> params) {
    statusField.setNullOptionVisible(false);
}

I’ve tried with init method as well.
Doesn’t work. The blank row is still present.

The right solution (init + statusField.setNullOptionVisible method):

@Named(“fieldGroup.status”)
private LookupField statusField;

@Override
public void init(Map<String, Object> params) {

// statusField.setNewOptionAllowed(false);
statusField.setNullOptionVisible(false);

}

Could you share screnn XML and controller souce code?

web-screen.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<screen-config xmlns="http://schemas.haulmont.com/cuba/screens.xsd">
 <screen id="xxx$Payment.edit"
            template="xxx/payment-edit.xml"/>
</screen-config>

PaymentEdit.java

public class PaymentEdit extends AbstractEditor<Payment> {

    @Named("fieldGroup.status")
    private LookupField statusField;

    @Override
    public void init(Map<String, Object> params) {
        //      statusField.setNewOptionAllowed(false);
        statusField.setNullOptionVisible(false);
   }
}

Could you share payment-edit.xml source code?

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://editorCaption"
datasource="paymentDs"
focusComponent="fieldGroup"
  <layout expand="windowActions"
            spacing="true">
 <fieldGroup id="fieldGroup"
                    border="visible"
                    datasource="paymentDs">
            <column width="250px">
 <field property="status"/>
 </column>
 <column width="100px">
                <field id="separator">
                    <label height="10px"/>
     </column>
        </fieldGroup>

Well, it’s really strange, because the code looks correct. Could you attach a demo project that demonstrates the issue?

Also, I found that in previous replies I pointed the wrong method setNewOptionAllowed instead of setNullOptionVisible. I’ve corrected my replies. Sorry about that. Nevertheless, I see that you use the correct method and it should work.

yes, now it works.