How to put default values in screens?

In a application composed by many screens, I need to populate some fileds with default values.
The same also as Search parameters.

For example take a CRM application: A the begin of the User session, he/she put in an entity some values, as for exampe Customer code, Agreement data, etc.

Next, every screen that he/she open, at the begin the program get the default values for Customer code, Agreement data, etc from the above entity and puts the data in the appropiate fields.

If there is a browser screen, before to show the screen, in the Search fields the program puts Customer code, Agreement data, etc. in the filter fields.

Please, anyone can address me to some example to do that ?

Thank you in advance for any support.

Ivano C.

1 Like

HI Ivano

I think that the easyest way is to popup a screen after user login and save default values in user session. Than, in other screens check if values are set în usersession and populate fields în current screen.

I am writing from my mobile, look for get usersession source and set parameters în the forum.



Do you always just want to set default values for a single entity, but for all instances that get created, or do you have multiple entities that have similar attributes where all of them should be populated with the default vaules?

Perhaps you cab share a sample domain model that illustrates the situation better.


Dear George, thank you for your suggest.

I’m new in Cuba development, so cause I think to use the User session can be a good path, now I’l to start how put the Java code in my screens …

Ivano C.

Dear Mario,

Thank you for your reply.

Yes, I have multiple entities that have the same attributes the User choice at the begin of the session.

Then I need to populate the other entities with the same values.

Ivano C.


I think this should be possible through the session attributes. Ill try to create an example for you in the next days.


You may assign the attribute like below:

userSessionSource.getUserSession().setAttribute("defaultCompany", company);

and use it when needed (anytime later during the session):

Company defaultCompany = userSessionSource.getUserSession().getAttribute("defaultCompany");


so I created an example for you that shows how to do the default values. It can be found here: GitHub - mariodavid/cuba-example-session-default-values: CUBA example that shows how to set session wide variables and use them as default values

I made it quite a complete example because it seems there is potential to create an application component out of it.

CUBA example: Default Values for session

This example shows how to define default values for a given user. Those default values will be used in other screens where those values can be placed into.


A Customer has an attribute name. In the default values screen a global name attribute value can be entered (e.g. “Fred”). For every invocation of the customer editor screen, the name field of the Customer will be set to the value “Fred”.

The Order and an Invoice entities both have values for dueDate and customer. In the default values screen a global dueDate and customer attribute value can be entered (e.g. “01/02/2019” & “Customer: Fred”). For every invocation of the invoice and order editor screen, the dueDate field will be set to the value “01/02/2019” and the customer field will be set to the value “Customer: Fred” .

How it looks in action


How to use it

In order to use it the following steps have to be taken:

  1. In the DefaultValues interface an additional field has to be registered: `String ASSIGNED_TO = “defaultValue-assignedTo”;

  2. add an additional field to default-values-screen.xml defines which default values are possible for the application: <pickerField width="100%" id="assignedToField" metaClass="sec$User" caption="msg://user"/>

  3. register new field in ApplicationDefaultValuesScreen in the init method like this:

  protected PickerField assignedToField;

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

    // ...
    addToDefaultValues(assginedToField, DefaultValues.ASSIGNED_TO);`

  1. In the destination screen (e.g. OrderEdit) the fields that should be populated with a default value need the annotation:
  protected PickerField assignedToField;

With those changes in place, a user can be set as the default assigned to person for every new Order that is created.

If you have any question - don’t hestitate to ask :slight_smile:


Thank you Mortoza !

Basically I understood the code.
Now I ned to understand where to put it in my project, using Cuba IDE or Java IDE.

Thank you !
Ivano C.

Hello Mario,

Thank you for the complete and exaustive example.

Yes, I think that it can be a good thing to create an application component.

Now I’ll try to use it in my application but it seems the perfect solution to my case.

Thank you for your invaluable support !

Ivano C.

Hello Mario,

Other tahn populate edit screens in the application, my use case require also that if there is a browser screen in the Search fields I need to put default values.

So the subseguent searches are limitated by the parameters setup as default vaues.

What do you think about it ?

Thank you,
Ivano C.

Hi @icarrara,

If I understand you right you need to set default filter with some values in it. It is possible to do with the Generic Filter component in no-code way - learn more about features of the Generic Filter here.

In your case follow the steps:

  1. 0 - setup required filter
  2. 1 - save the filters with values
  3. 2 - make it default



1 Like

Thank you Aleksey !

Please could you suggest me also how to do that programmatically ?

Best regards,
Ivano C.