Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionError not getting displayed

I want to load my Error.jsp in my ErrorDiv if Action class returns error. I am doing an AJAX call.

JS:

success: function(result){    
    if(result === 'success')
        alert('Database Updated Successfully!');
    else{
         $('#ErrorDiv').load('/gma/pages/Error.jsp');
    }
}

                

Error.jsp:

<body>

<%
    request.setAttribute("decorator", "none");
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<s:if test="hasActionErrors()">
       <s:actionerror />
</s:if>

</body>

However, action errors are not getting displayed. In firebug I checked, response to GET Error.jsp in that the <body> </body> part comes empty.

Why are actionError not getting displayed?

EDIT:

Action Class:

try{
slsConfigureTspThresholdRemote.setThresholdParameters(circleId, tspId, thresholdTypeFlag, thresholdParametersList);

}
catch (Exception e){    
    addActionError(e.getMessage());
    e.printStackTrace();
    
    result = "error";
    return ERROR;
}

struts.xml:

<action name="updateThresholdParameters"
class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction" method="updateThresholdParameters">

<result name="success" type="json">
    <param name="root">result</param>
</result> 

<result name="error">pages/Error.jsp</result>

Presently, I am doing $('#ErrorDiv').html(result); so that my JSP get loaded in div instead of

$('#ErrorDiv').load('/gma/pages/Error.jsp');!
like image 516
Siddharth Trikha Avatar asked Mar 12 '26 08:03

Siddharth Trikha


1 Answers

The validation errors are available only to the same request. Also direct access to the JSPs might be handled by the web container where the Struts tags will not work.

You should use an action to render a JSP and the action should run a store interceptor if you want to keep the validation errors from the previous request.

If you want to use the same response to return a different result you can set the different status code with each result.

On the client you could check the status code returned by the Ajax response and do corresponding things.

success: function(data, textStatus, jqXHR){
    if(jqXHR.status == 200) {                      
      alert('Database Updated Successfully!'); 
    }
}
error: function(data, textStatus, jqXHR){
    if(jqXHR.status == 400) {
      $('#ErrorDiv').html(data);        
    }     
}

To show errors in the JSP add the following to the scriptlet code

response.setStatus(400);
like image 72
Roman C Avatar answered Mar 13 '26 20:03

Roman C