Filter Component Registration example

Hi,

I try to create a custom filter component so i custom valuesPicker by my SelectValueController, render show ;

image

image

But what do more ValuesPicker :: Jmix Documentation compare Filter Component Registration

Could you provide us a exemple of Filter Component Registration ?

thx

gabriel

Hello!

Could you clarify? Do you want that the filter will generate your custom ValuesPicker component if property has a Collection type?

Hello,

Sorry for late.

ValuesPicker do the job, i provided insight in my first post.

But Filter Component Registeration seen can give more liberty, but i don’t understand it ?
Filter Component Registeration can do same thing?
if yes can provide me simple exemple,

like suggest here AutoComplete in Default Jmix Filter

In ValuesPicker i used a collection of EnumClass ans custom my selector with this :


<condition>
                            <c:jpql>
                                <c:where>e.statutMetadata.statut in ?</c:where>
                            </c:jpql>
                        </condition>
                        <valuesPicker>
                            <actions>
                                <action id="select" type="values_select">
                                    <properties>
                                        <property name="enumClass"
                                                  value="......StatutValue"/>
                                        <property name="selectValueScreenId"
                                                  value="...StatutSelector"/>
                                    </properties>
                                </action>
                            </actions>
                        </valuesPicker>

regards,

gabriel

FilterComponentRegistration is more than just registering a component. It is more like registering a condition with component, state converter and custom UI to editing the condition. Good example of custom filter condition is the Search add-on.

And registration:

@Bean("search_FullTextFilterRegistration")
public FilterComponentRegistration registerFullTextFilter() {
    return FilterComponentRegistrationBuilder.create(FullTextFilter.class,
            FullTextFilterCondition.class,
            FullTextFilterConverter.class)
            .build();
}

If you need only generate your custom component in Property condition or in Jpql condition you can extend the component factories:

AppPropertyFilterComponentGenerationStrategy.java
@org.springframework.stereotype.Component("app_PropertyFilterComponentGenerationStrategy")
public class AppPropertyFilterComponentGenerationStrategy extends PropertyFilterComponentGenerationStrategy {

    public AppPropertyFilterComponentGenerationStrategy(Messages messages,
                                                        UiComponents uiComponents,
                                                        EntityFieldCreationSupport entityFieldCreationSupport,
                                                        Metadata metadata, MetadataTools metadataTools,
                                                        Icons icons, Actions actions,
                                                        DataAwareComponentsTools dataAwareComponentsTools,
                                                        ApplicationContext applicationContext) {
        super(messages, uiComponents, entityFieldCreationSupport, metadata, metadataTools, icons, actions,
                dataAwareComponentsTools, applicationContext);
    }

    @Override
    protected Component createCollectionField(ComponentGenerationContext context, MetaPropertyPath mpp) {
        ValuesPicker valuesPicker = (ValuesPicker) super.createCollectionField(context, mpp);
        ValuesSelectAction selectAction = (ValuesSelectAction) valuesPicker.getAction("values_select");

        // Check some conditions

        // Set custom select screen
        selectAction.setSelectValueScreenClass(MySelectScreenClass.class);

        return valuesPicker;
    }

    @Override
    public int getOrder() {
        return JmixOrder.HIGHEST_PRECEDENCE;
    }
AppJpqlFilterComponentGenerationStrategy.java
@org.springframework.stereotype.Component("app_AppJpqlFilterComponentGenerationStrategy")
public class AppJpqlFilterComponentGenerationStrategy extends JpqlFilterComponentGenerationStrategy {

    public AppJpqlFilterComponentGenerationStrategy(Messages messages, UiComponents uiComponents,
                                                    EntityFieldCreationSupport entityFieldCreationSupport,
                                                    Metadata metadata, MetadataTools metadataTools, Icons icons,
                                                    Actions actions, DatatypeRegistry datatypeRegistry,
                                                    DataAwareComponentsTools dataAwareComponentsTools) {
        super(messages, uiComponents, entityFieldCreationSupport, metadata, metadataTools, icons, actions,
                datatypeRegistry, dataAwareComponentsTools);
    }

    @Override
    protected Component createCollectionField(ComponentGenerationContext context) {
        ValuesPicker valuesPicker = (ValuesPicker) super.createCollectionField(context);
        ValuesSelectAction selectAction = (ValuesSelectAction) valuesPicker.getAction("values_select");

        // check some conditions

        // Set custom select screen
        selectAction.setSelectValueScreenClass(MySelectScreenClass.class);

        return valuesPicker;
    }

    @Override
    public int getOrder() {
        return JmixOrder.HIGHEST_PRECEDENCE;
    }
}

1 Like