0

I use next code to generate chart :

source:
<s:url  var="chart" action="resultChart">
    <s:param name = "paramBean" value="#request.paramBean"/>
</s:url>

<img src="<s:property value="%{chart}"/>"/> 

struts.xml
<package name="struts2-tiles-exception" extends="struts-default" namespace="/">
    <result-types>
        <result-type name="tiles"
            class="org.apache.struts2.views.tiles.TilesResult" />
    </result-types>

    <global-results>
        <result name="error" type="tiles">/error.tiles</result>
    </global-results>

    <global-exception-mappings>
        <exception-mapping exception="java.lang.Exception" result="error" />
    </global-exception-mappings>        
</package>  

<package name="chart" extends="jfreechart-default, struts2-tiles-exception" namespace="/">
    <action name="resultChart" class="com.ChartAction">
        <result name="success" type="chart"> 
            <param name="width"> 1200 </param> 
            <param name="height"> 600 </param>
        </result>
    </action>
</package>

java code
The execute() method of ChartAction has next signature :
  public String execute() throws Exception {
  ...
  }

I see empty image instead of redirect to error page in my tiles application, but if i run resultChart?... in the browser command line - i see succesfull redirect to the error page

How can I handle exception with redirect to error page if i execute action inside "src" of "img"?

Sincerely yours, Evgenii

evgenii ershenko
  • 489
  • 1
  • 5
  • 14
  • I don't understand the question. What is happening? What is an empty image? Why do you _want_ to see a redirect to the error page... you really want the end result to be an error page? Or do you want to see the chart? – Quaternion Aug 31 '13 at 06:19
  • to draw Chart - "chart" action retrieve data from database, if connection with database lost I want to redirect to "error" page.How can I make this?Problem arise because action inside IMG tag – evgenii ershenko Sep 08 '13 at 18:33
  • 1
    Well the action isn't exactly inside the image tag. The url to the action is in the image tag. If the url produces an image (in the normal case, assuming no error) in the browser if you visit that link then you should be seeing the image on that page. – Quaternion Sep 08 '13 at 23:14
  • 1
    The chart returns a stream and so can not redirect you. You'll need to use javascript for this. One method, on error return a 1 pixel image. Using canvas you can determine this image does not meet your minimum size requirements for the image and have it redirect you to the correct page. Another easier way would be to have the chart action return an image that you created that contains the text "Chart is currently inaccessible". Possibly the DB is not inaccessible but there could have been an exception for another reason, at least the rest of the report would be available. – Quaternion Sep 08 '13 at 23:23

0 Answers0