Query condition in screen xml and date range exception

I have a browser screen where the loading query has conditions as follows:

  <loader id="attendSummaryDailiesDl">
            <query>
                <![CDATA[select e from erp_AttendSummaryDaily e]]>
                <condition>
                    <and>
                        <c:jpql>
                            <c:where>e.company = :component_companyField</c:where>
                        </c:jpql>
                        <c:jpql>
                            <c:where>e.employee.operatingLocation = :component_operatingLocationField</c:where>
                        </c:jpql>
                        <c:jpql>
                            <c:where>e.attenDate between :component_dateFromField AND :component_dateToField </c:where>
                        </c:jpql>

                    </and>
                </condition>
            </query>
        </loader>

The screen looks like below

image

When I enter the date in the field either “Date from” or “Date to” then getting the following exception. The reason is the query is executed immediately after entering either of those two date fields automatically. I tried to initiate date in the controller but getting the same problem. Thanks for suggesting a solution.

DevelopmentException: Parameter 'component_dateFromField' is not used in the query

Hi.

Your screen controller should not have @LoadDataBeforeShow annotation, because loading is triggered explicitly.
Here is an example how it could be implemented:
loader in XML-descriptor:

<loader id="newEntitiesDl">
                <query>
                    <![CDATA[select e from test_NewEntity e]]>
                    <condition>
                        <and>
                            <c:jpql>
                                <c:where>
                                    e.dateAfter between :firstDate AND :secondDate
                                </c:where>
                            </c:jpql>
                        </and>
                    </condition>
                </query>
            </loader>

listeners in screen controller:

    @Inject
    private DateField<Date> firstDate;
    @Inject
    private DateField<Date> secondDate;
    @Inject
    private CollectionLoader<NewEntity> newEntitiesDl;

    @Subscribe("firstDate")
    public void onFirstDateValueChange(HasValue.ValueChangeEvent<Date> event) {
        if (!firstDate.isEmpty() && !secondDate.isEmpty()){
            newEntitiesDl.setParameter("firstDate",firstDate.getValue());
            newEntitiesDl.setParameter("secondDate",secondDate.getValue());
            newEntitiesDl.load();
        }
    }

    @Subscribe("secondDate")
    public void onSecondDateValueChange(HasValue.ValueChangeEvent<Date> event) {
        if (!firstDate.isEmpty() && !secondDate.isEmpty()){
            newEntitiesDl.setParameter("firstDate",firstDate.getValue());
            newEntitiesDl.setParameter("secondDate",secondDate.getValue());
            newEntitiesDl.load();
        }
    }

More information about using screen parameters in loaders

Regards,
Nadezhda.

1 Like