Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » My getDataByText() filter for a Smartfield is not working(Filter for a SmartField's LookuoCall does not filter the data using a predicate at all)
My getDataByText() filter for a Smartfield is not working [message #1854789] Sat, 10 September 2022 10:51 Go to next message
J D is currently offline J DFriend
Messages: 99
Registered: February 2021
Member
Hi there everyone,

I have a lookup service I created to retrieve job titles from a remote REST server.

public class JobTitleLookupService extends AbstractLookupService<Integer>
    implements IJobTitleLookupService {

  @Override
  public List<? extends ILookupRow<Integer>> getDataByKey(ILookupCall<Integer> call) {
    JobTitleLookupCall c = (JobTitleLookupCall) call;

    if (c.getKey() == null) {
      return CollectionUtility.emptyArrayList();
    }
    Object key = c.getKey();
    List<? extends ILookupRow<Integer>> rows = getRows();
    if (rows == null) {
      return CollectionUtility.emptyArrayList();
    }
    List<ILookupRow<Integer>> list = new ArrayList<>(rows.size());
    for (ILookupRow<Integer> row : rows) {
      if (key.equals(row.getKey())) {
        list.add(row);
      }
    }
    return list;
  }

  @SuppressWarnings("unchecked")
  @Override
  public List<? extends ILookupRow<Integer>> getDataByText(ILookupCall<Integer> call) {
    JobTitleLookupCall c = (JobTitleLookupCall) call;

    List<CategoryLabelEntityDo> labels = prepareList();

    Predicate<CategoryLabelEntityDo> byText = label -> label.getString("description").toLowerCase()
        .matches(c.getText().substring(0, c.getText().length() - 1).toLowerCase());
     
    return (List<? extends ILookupRow<Integer>>) labels.stream().filter(byText)
        .collect(Collectors.toList());
  }

  @Override
  public List<? extends ILookupRow<Integer>> getDataByAll(ILookupCall<Integer> call) {
    return getRows();
  }

  @Override
  public List<? extends ILookupRow<Integer>> getDataByRec(ILookupCall<Integer> call) {
    // return null;
    return getDataByAll(call);
  }

  private List<? extends ILookupRow<Integer>> getRows() {
    List<CategoryLabelEntityDo> labels = prepareList();

    ArrayList<ILookupRow<Integer>> rows = new ArrayList<>();
    labels.forEach((label) -> {
      rows.add(new LookupRow<>(Integer.parseInt(label.getString("id")),
          label.getString("description")));
    });
    return rows;
  }

  private List<CategoryLabelEntityDo> prepareList() {
    CategoryLabelResponseEntityDo response =
        BEANS.get(CategoryLabelResourceClient.class).getJobTitleList(TEXTS.get("No"));
    List<CategoryLabelEntityDo> labels = response.result().get().get(0);

    return labels;
  }
}


My problem is that my getDataByText() function is not working at all, and it does not present me with propositions as I type into the JobTitle smart field.

What am I doing wrong?

Thanks a lot for your kind assistance.

Cheers,

JD
Re: My getDataByText() filter for a Smartfield is not working [message #1854790 is a reply to message #1854789] Sat, 10 September 2022 11:24 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
Hi JD

I assume your client produces a ClassCastException at runtime, because you're trying to cast a List of CategoryLabelEntityDo to a List of ILookupRow. I don't know how your CategoryLabelEntityDo looks like, but I assume it does not implement ILookupRow (and should not, in my opinion).

Instead you should transform the CategoryLabelEntityDo to a LookupRow with the .map() Stream-method. You do something similar in your getDataByRec() method already.

Cheers, André


Eclipse Scout Homepage | Documentation | GitHub

[Updated on: Sat, 10 September 2022 11:40]

Report message to a moderator

Re: My getDataByText() filter for a Smartfield is not working [message #1854799 is a reply to message #1854789] Mon, 12 September 2022 09:15 Go to previous message
J D is currently offline J DFriend
Messages: 99
Registered: February 2021
Member
Hi there Andre,

Thanks a lot for the tips. It is working properly now.

Cheers,

JD
Previous Topic:Maven Error in Eclipse
Next Topic:scout.application.version for development
Goto Forum:
  


Current Time: Fri Apr 26 17:54:50 GMT 2024

Powered by FUDForum. Page generated in 0.02708 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top