FTS Search results opens editor screen by default #2330

Hello,

I followed this question and so far I have similar issue…

https://www.cuba-platform.com/discuss/t/fts-search-results-opens-editor-screen-by-default

I am not using editor screen for my current project, how can I make sure that the FTS search focus on browser screen.

Thanks

Regards
Sanchit

1 Like

Hi Sanchit,

In platform 6.5+ you can extend the search-results.xml : ftsSearchResults screen and override just one specific method of its controller: openEntityWindow()

Hi Konstantin,

I am using the latest version of studio 6.5.5 and I only have the fts-config file (fts.xml)
Can you please provide me the path for the search-result.xml file?

Thanks.

Hi Sanchit,

First, make sure your project is based on the platform 6.5+. See Project properties > Platform version.

Select web package on the Generic UI tab and click New. Select the “Extend an existing screen” template and find “search-results.xml : ftsSearchResults” in the “Extend screen” field (see screenshot attached). Create the extended screen and open its controller in the IDE. Override the openEntityWindow() method as follows:

public class ExtSearchResultsWindow extends SearchResultsWindow {

    @Override
    protected void openEntityWindow(SearchResult.Entry entry, String entityName, WindowManager.OpenType openType) {
        // this is the standard implementation, you can replace it
        WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
        MetaClass metaClass = metadata.getSession().getClass(entityName);
        Entity entity = reloadEntity(metaClass, entry.getId());
        openEditor(windowConfig.getEditorScreenId(metaClass), entity, openType);
    }
}

2017-07-19 09_42_10-sample - CUBA Studio

2 Likes

Hi Konstantin,

Do I have to change something to make it work for browser screen only?
I did the exact same thing but when I search and click on the result it gives me an error saying 'no such editor screen is found’
So, I change it to getBrowserScreenID but it throws the ClassCastException.

What should I do?

Use openWindow() for opening a browse screen.

It opens the browse screen but it does not locate where the search result was found.

openWindow(windowConfig.getBrowseScreenId(metaClass), openType);

Of course it doesn’t, because you just open the screen. Your screen should have some logic to position on a record. But what if there are thousands of records in the database and they do not fit to one page? I see only one reliable way to position on a record - apply a filter by entity ID to show only this single entity. Is it what you want?

Yes, that’s exactly what I want.
Can you please provide an example on it.

I’ve just added an example of programmatic filter creation to this sample project: GitHub - cuba-platform/sample-screen-manipulation: DEPRECATED. See https://github.com/cuba-platform/sample-generic-ui. Now when the product browser is opened for looking up items to be used as order lines, it also creates and applies programmatically a filter to show only products not yet added to the order.

This task is very similar to yours. In your case:

  • Pass a parameter containing entity ID when opening the browser

  • In the browser, inject the parameter with @WindowParam annotation

  • In the ready() method, if the parameter is passed, create and apply a filter. The filter’s XML should like this one:

<filter>
  <and>
    <c name="id" class="java.util.UUID" hidden="true" operatorType="EQUAL" width="1" type="PROPERTY">
        <![CDATA[e.id = :component$filter.id87352]]>
      <param name="component$filter.id87352" javaClass="java.util.UUID">NULL</param>
    </c>
  </and>
</filter>
  • When setting the filter parameter value to the passed ID, use the name from XML: id87352 (it can be arbitrary though).
1 Like