I have an entity with lot of fields and I would like to create a view over a restricted set of fields.
I tried to create a view extending _local, but I cannot untick fields in the editor, which is conform to documentation.
I tried to create a view extending _minimal (defined with “name” property) but when I use this view as a datasource for an editor screen, it does not get populated with data. I suspect that the id is not part of the datasource, so when from the browser I clic on the entity, the editor is not getting populated with entity data.
So I tried to defined the _minimal view with “id” property, same issue.
Alternatively I could use _local in editor screen and define manually each field to display, but I loose the simplicity of using field groups.
What would you recommend in such scenario ?
Addendum : if I defined the restricted view from _minimal (defined with “name” property and not id) and then generate standard editor it works (clicking on an entity in browser opened and editor populated with data).
So I guess there is a hidden stuff when studio generates standard screens/datasources.
The id attribute is always loaded regardless of the view, so it cannot be a cause of the issue. And your view can have no ancestors - just tick the fields that should be loaded.
There is actually no hidden logic in standard screens - Studio just creates them by templates. If a standard editor works but yours doesn’t then something is wrong with your screen definition. If the view does not contain fields used by visual components, you will get an “unfetched attribute” exception.
Can you post the screen XML and the view definition (from views.xml) here?
Attached views.xml, browser and editor screens xml.
“product-base” is the restricted view I’m trying to setup :
<view class="com.busy.busyapp.entity.Product" name="product-base"> <property name="internal_code"/> <property name="serialized"/> <property name="sale_price"/> <property name="sale_margin"/> <property name="sale_margin_rate"/> <property name="last_sale_price"/> <property name="family" view="_minimal"> <property name="internal_code"/> </property> <property name="creation_date"/> <property name="warranty"/> <property name="invoice_unit"/> <property name="comments"/> <property name="designation"/> </view>
I generated standard screens with the full set of fields and then I change the fieldGroup datasource from productDs to productBaseDs which is built on product-base.
And then when I clic on a product in browser, the editor open without being populated with data (no errors though).
I see. The problem is that your new productBaseDs datasource does not contain any entity at all - that’s why you see empty fields.
Single (not collection) datasources do not load data by themselves - an entity instance should be provided via setItem() method. So when you open an editor, the editor screen receives a selected instance from browser (or a new instance), and sets it to the main datasource which is specified in the “datasource” attribute of the editor root element. So in your case the edited instance goes to the productDs datasource.
Important note: the editor screen also reloads the instance with the view which is set for the main datasource.
In order to fix the problem, specify productBaseDs in the “datasource” attribute of the screen, or use your restricted view for productDs.
It means that if I want to have several views/datasources for the same entity behind one editor screen, only the root one will be populated with the entity. Is there a way to propagate the entity to other datasources apart from coding setItem() manually ?
Only the datasource specified in the “datasource” attribute of the editor screen is automatically populated. You can propagate it to another datasource in postInit() method - at that moment getItem() return the reloaded instance located in the main datasource. Or you can load anything through DataManager and set to a datasource.
By the way, why are you using two datasource for the same instance?
I use several datasources for the same instance because I want to segregate fields into sets, and have the possibility to manage set of fields by invididual groups. The purpose is modularity : some set of fields are only available (visible) if the corresponding module is activated. For instance if the module “stock management” is activated then the group of fields related to this feature are visible.
I agree that from a design perspective there may be a better solution. In fact at this stage I just need to hide/show group of fields depending on the condition that the associated module is activated, there may be a way without using a datasource for each group of fields.
I thought about associating each field with its corresponding property one by one, then group them in a boxGroup (for a module) for instance. That would work, but I would like to keep the auto-binding feature of fieldgroup if possible. At least at early development stage for quickness.
But you could create several FieldGroups connected to a single datasource. This is the usual practice, a datasource can serve multiple visual components.
Agreed. In fact, shame on me, I missed the “edit fields” button in studio that allow to select the fields of the fieldgroup, so one datasource will do perfectly fine. Thank you.