Making a component not visible programmatically

I want to turn a component invisible programmatically (based on some conditions. Is it possible?

Something like in controller:


You can use setVisible method of FieldGroup:

fieldGroupEdit.setVisible("productionRework", false);

Thank you, it worked.

The same question regarding Table. How can I hide a column of a table programmatically.

I’m new to CUBA therefore a basic question:

Where do I get the -fieldGroupEdit- Object in my Editor (class XXXEdit extends AbstractEditor)


Hi Alex
If you have generated the Editor screen, you should have the fieldGroup that will hold different component. To order to manipulate in controller, you have to inject the fieldGroup component as follows:

private FieldGroup fieldGroup;

ok, I got it now simply by using getComponent(“fieldGroup”). Or i could Inject it (thanks mortoza). But FieldGroup.setVisible(String, boolean) is now deprecated.

Also I’m rather interested in a way to set any component visible by using it’t setVisible(boolean) method but this doesn’t work as the initial queation describes.

Is there a method “refreshView()” or something i need to run after changing it?

Hi Alex
Try this:

private TextField nameField;

protected void postInit() {

Thanks mortoza,

I’m sorry, Component.setVisible(boolean) wasn’t the problem. It didn’t work because i was trying this for testing purposes in an ItemPropertyChangeListener :

testLabel.setVisible(!testLabel.isVisible()); (any idea why this doesn’t work?)

However, it works if i use a constant argument value.

another Question:
Is there a way to switch between views and editors programmatically?

I wish I could define more views for different cases and then switch between them based on a field value or a button action. Something comparable I could by defining a complete view and setting components visible or invisible but maybe there is a better way??


Hi Alex
I don’t see why testLabel.setVisible(!testLabel.isVisible()); wouldn’t work. May be CUBA team can provide guidance.

An Entity may have different views and depending on what you want to achieve implementation will depend on that. For example we can reload the data based on criteria where we can use different view. Setting fields visible true or false is another option.

1 Like

I know why testLabel.setVisible(!testLabel.isVisible()) it didn’t work in my case. Because in the same Listener i had a Dataset.getItem().setVALUE(…) whichtriggered the PropertyChangeListener again. But I didn’t know it would trigger the Event because then I expected a StackOverflow. But it seems like the event is only triggered if the new value does not equal the last value (which I like).

Thanks mortoza for your help. I’m just testing around as I’m new to CUBA. I’m glad I didn’t open a new thread for this :wink:

Good luck. I’m very happy using this platform and hope you will find here some pretty interesting and productivity features soon.