Access to current item in ComponentGenerationStrategy class


Is there any way to have access to current item in class which implements ComponentGenerationStrategy ?

I explain clearly my problem. I’d like to have access to current entity values.
In this example query is simple, but sometimes I need create more complication.
query, then in where condition I need to have access to current entity values. In this case I use setParameter method. How I may to reach my functionality ?

public class SuggestionPickerComponentGenerationStrategy implements ComponentGenerationStrategy, Ordered {

    public static final String NAME = "SuggestionPickerComponentGenerationStrategy";

    private ComponentsFactory factory;

    private DataManager dataManager;

        public Component createComponent(ComponentGenerationContext context) {
            String property = context.getProperty();
            if (context.getXmlDescriptor() == null)
                return null;
            String search = context.getXmlDescriptor().attributeValue("suggestionpicker");
            if ((search != null) && context.getComponentClass() != null) {
                SuggestionPickerField searchPickerField = factory.createComponent(SuggestionPickerField.class);
                searchPickerField.setDatasource(context.getDatasource(), property);

                String query = "select e from erp$DocTypes e where  e.code like :xfind";
                searchPickerField.setSearchExecutor((searchString, searchParams) -> {
                    SuggestionPickerField.LookupAction action = (SuggestionPickerField.LookupAction) searchPickerField
                    searchString = QueryUtils.escapeForLike(searchString);
                    if (!searchString.isEmpty()) {
                        QueryParser parser = QueryTransformerFactory.createParser(query);
                        String entityName = parser.getEntityName();
                        MetaClass metaClass = getMetaClassByName(entityName);
                        return dataManager.loadList(LoadContext.create(metaClass.getJavaClass())
                                .setQuery(LoadContext.createQuery(query).setParameter("xfind", "%" + searchString + "%")));
                    } else {
                        return Collections.emptyList();
                return searchPickerField;
            return null;


By design, ComponentGenerationStrategy is called when instance is not set to the datasource. That’s why you cannot use the current item there. I’d better set a custom component right in the screen than implement a strategy.

Why do you need to implement a custom generation strategy? Do you really need a custom system-wide component generation rule?

Hi Yuriy

First of all I’d like replace PickerField on SuggestionPickerField. I add attribute
suggestionpicker to section other related to field in XML file in that I may simple
replace component. I find in documentation that I have to create SearchExecutor for SuggestionPickerField. I select implementation with dataManager, but some queries need acccess to field from current entity e.g
select e from erp$DocTypes e where :register and e.code like :searchString param :register. I find some way for do it. In edit controller I add

PickerField.LookupAction action = (PickerField.LookupAction) spf
action.setLookupScreenParams(ParamsMap.of("entity", getItem()));

in ComponentGenerationStrategy
I get this value byaction.getLookupScreenParams().