Open jpsturla opened 10 years ago
Return an empty list and provide some user feedback using component.error("...")?
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.
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
}
}
}
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.
Hmm, let me think about that. @ivaynberg : You have a better idea?
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.
See my pull request in issue #90 as simple example.
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.