3

We have a Struts2 application using Struts2-jQuery framework for Ajax operations. While using the Autocompleter (sj:autocompleter) tag in Struts2-jQuery as follows, it makes an ajax request to the Struts2 Action jsonlanguages.

<s:url var="remoteurl" action="jsonlanguages"/>
<sj:autocompleter
    id="languages"
    href="%{remoteurl}"
    delay="50"
    loadMinimumCount="2"
/>

We have defined a result type ERROR for this action as follows, to trigger an Internal Server error instead of it getting completed as a successful ajax request.

<result name="ERROR" type="httpheader">
  <param name="status">500</param>
  <param name="headers.a">a custom header value</param>
  <param name="headers.b">another custom header value</param>
</result>

Issue: Now this approach triggers the "onErrorTopics" in all other Struts2-jQuery tags like sj:select ..etc, but it does not seem to be triggering the same in an sj:autocompleter. Has anybody faced this issue ? If so, what is the best way to handle exceptions that happen during an ajax request from an autocompleter ?

yathirigan
  • 5,619
  • 22
  • 66
  • 104

1 Answers1

1

I think it will not be possible to do exception handling at view until you yourself check for the validity of json returned.

BTW autocompleter do not return any result but a json object.

You can validate json returned by action in javascript or jquery.

Amit Kumar
  • 2,685
  • 2
  • 37
  • 72