In my current project I would like to be able to create new objects when searching for a reference object. This happens in several places of the application.
For example, let's assume we have a City Entity and a Country Entity. The City entity has a mandatory reference to the Country entity.
In my use case, I would like to create a new City. When I do this, I will have to assign a Country to the new City. When I click on the lookup icon, I get the selection dialog with all existent countries. But if I don't have the Country I want, I have to abort the operation, get back to the countries list and create the new one I'd like to assign to my new city.
- Would it be possible to create that new Country from the selection dialog with all countries?
 - If it is possible, is the country being added to the list right after it has been created?
 - Would it be possible to one define a range for the countries list? For example, showing only countries in Europe, if the user is in Europe.
 
I could imagine, that this would be a lot to ask from the framework. But I am just giving a shot and perhaps also giving a new feature idea, which would be nice to have.
                        
Customization of the LOV dialog :
You can easily customize the LOV dialog by creating your own class of the LOV action that is installed next to the reference fields.
The key point is to override the
feedContextWithDialogmethod in order to install the new action into the dialog.Next step is to install your new LOV action. You can either do it globally for whole application or per reference view :
'lovAction'into your applicationfrontend.groovy, i.e. :referencePropertyView(in aformor in atable) and its 'lovAction' property, e.g. :Creating an entity in the LOV dialog :
In the next step, we create the action that will be responsible for opening an extra dialog in order to create the new entity, persist it and, if successful, add it to the LOV result view. This is a little more complicated but not that much.
For doing this, we will inherit the built-in
EditComponentAction. The goal of this action is to edit a model in a modal dialog. The only difficulty here is that our model is only known at runtime. No problem though as we will use the dynamic nature of Jspresso.If you look at the code above, our new action takes care of the following :
Points 1 and 2 are handled by the
getComponentToEditmethod and point 3 by thegetViewDescriptormethod.Ok, we have to save the entity, add it to the LOV result list and close the creation dialog.For this, we will create a new action and chain it to the
saveActionandcloseDialogActionbuilt-in actions.frontend.groovy:A long answer for less than 100 lines of code, but now you have a fully generic LOV action where the user can create any missing master data without leaving his current screen.
Presetting some data in the LOV filter depending on the user context :
For this, we generally use the initialization mapping that allows for setting some restrictions (either static or dynamic) on a reference property when it is queried in a LOV. For instance, let's consider the following use case :
ContractandTariff, that are linked together through a 1-N relationship, i.e. aContractis linked to 1Tariff.ContractandTariffboth have acountryproperty and aTariffcan be assigned to aContractif and only if they belong to the same country.Tarrifhas astatusproperty and can only be used in aContractif itsstatusisACTIVE.You can simply enforce these rules in the LOV by setting the initialization mapping on the reference property the following way :
Thinking about it, this kind of behavior might very well find its way to the framework, so please, feel free to ope an enhancement request in the Jspresso GitHub.