wicket-select2 icon indicating copy to clipboard operation
wicket-select2 copied to clipboard

Error handling and user feedback

Open jpsturla opened this issue 11 years ago • 7 comments

I need to catch an exception in "query" method of TextChoiceProvider (i.e. database connection error) and show a message to the user. But I don't know how to do this and if it's possible.

  • If I don't catch the exception the select2 remains showing "Searching...".
  • If I set null to response the select shows "No matches found" that it's not true.

jpsturla avatar Dec 20 '13 14:12 jpsturla

Return an empty list and provide some user feedback using component.error("...")?

tgoetz avatar Jan 22 '14 12:01 tgoetz

I understand your idea Tom, but I don't know how it's possible. Because I can return an empty list but it's in method "query" of TextChoiceProvider, and TextChoiceProvider doesn't know which panel or page is using it.

In other words, "component" is undefined in TextChoiceProvider.

jpsturla avatar Jan 24 '14 11:01 jpsturla

Hm, you could do the following:

public class MySelect2Choice extends Select2Choice<String>
{
  public MySelect2Choice(String id, IModel<String> model, ChoiceProvider<String> provider)
  {
    super(id, model, provider);
  }

  @Override
  public void onResourceRequested()
  {
    try {
      super.onResourceRequested();
    } catch (Exception e) {
      // exception handling
    }
  }
}

tgoetz avatar Jan 24 '14 11:01 tgoetz

Tom I followed your suggestion and effectively I could catch de exception. But I still have a problem to show a notifier to the user. The problem is that in onResourceRequested doesn't exist an AjaxRequestTarget.

If I check for "getRequestCycle().find(AjaxRequestTarget.class)" it has null value.

jpsturla avatar Jan 24 '14 12:01 jpsturla

Hmm, let me think about that. @ivaynberg : You have a better idea?

tgoetz avatar Jan 24 '14 12:01 tgoetz

Any hints? I also would like to notify the user. I think it should be possible to catch the exception in the onResourceSelected() and then add an 'error' field to the resulting JSON. I tried to see how that could be incorporated in the select2.js, but that seemed to complicated for the moment.

d2a-raudenaerde avatar Jul 02 '14 15:07 d2a-raudenaerde

See my pull request in issue #90 as simple example.

RobAu avatar Jul 03 '14 07:07 RobAu