ivaynberg / wicket-select2

Provides integration between Apache Wicket and Select2
64 stars 50 forks source link

Error handling and user feedback #75

Open jpsturla opened 10 years ago

jpsturla commented 10 years ago

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.

tgoetz commented 10 years ago

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

jpsturla commented 10 years ago

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.

tgoetz commented 10 years ago

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
    }
  }
}
jpsturla commented 10 years ago

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.

tgoetz commented 10 years ago

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

d2a-raudenaerde commented 10 years ago

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.

RobAu commented 10 years ago

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