You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by MARK NICHOLS <DH...@dhs.state.il.us> on 2002/03/01 22:07:11 UTC

Can't get ActionError back from Action class


I know it must be late on Friday or I would be able to see what is wrong with the following code. I am trying to display the exception error message via <html:errors/> with no luck so far.

====== Action code snippet =====


public final class TestFinishReasonAction extends Action {

	// --------------------------------------------------------- Public Methods

	public ActionForward perform(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws IOException, ServletException {

		// Extract attributes we will need
		Locale locale = getLocale(request);
		MessageResources messages = getResources();
		HttpSession session = request.getSession();
		
		<< snipped >>
		
		// instantiate an ActionError collection to hold any messages
		ActionErrors errors = new ActionErrors();
		
		try {
       			<< snipped >>
       			}
	       		
			}catch(Exception ex) {
				if (servlet.getDebug() >= 1) 
       				servlet.log(" Database Exception : " + ex.getMessage()) ;

                                                      errors.add("dberror", new ActionError("error.database"));
                                                      errors.add("dbException", new ActionError(ex.getMessage())) ;
	   			      return (mapping.findForward("failure"));
				
			}

		// Forward control to the specified success URI
		return (mapping.findForward("success"));

	}

}


===== JSP snippet ====
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html:html>
<head>
	<title><bean:message key="finishReasonTest.title"/></title>
	<html:base/>
</head>
<body bgcolor="white">

<h3><bean:message key="finishReasonTest.heading"/></h3>
<html:link page="/testFinishReason.do">
	<bean:message key="finishReasonTest.testLink"/>
</html:link>

	<!-- show any errors here -->
	<html:errors/>
	
</body>
</html:html>

============================

What dumb stfw-rtfm mistake am I making?

=)

/\/\ark


___________________________________
- mark h. nichols
- dhsv022 at dhs dot state dot il dot us 

"Ooo. They've got the Internet on computers now." - Homer Simpson 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Can't get ActionError back from Action class

Posted by Eddie Bush <ek...@swbell.net>.
you called saveErrors, right? =)  ... snipped that part out, maybe?

If not, that's probably the reason they're not being displayed!

HTH,

Eddie

----- Original Message -----
From: "MARK NICHOLS" <DH...@dhs.state.il.us>
To: <st...@jakarta.apache.org>
Sent: Friday, March 01, 2002 3:07 PM
Subject: Can't get ActionError back from Action class




I know it must be late on Friday or I would be able to see what is wrong
with the following code. I am trying to display the exception error message
via <html:errors/> with no luck so far.

====== Action code snippet =====


public final class TestFinishReasonAction extends Action {

// --------------------------------------------------------- Public Methods

public ActionForward perform(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

// Extract attributes we will need
Locale locale = getLocale(request);
MessageResources messages = getResources();
HttpSession session = request.getSession();

<< snipped >>

// instantiate an ActionError collection to hold any messages
ActionErrors errors = new ActionErrors();

try {
       << snipped >>
       }

}catch(Exception ex) {
if (servlet.getDebug() >= 1)
       servlet.log(" Database Exception : " + ex.getMessage()) ;

                                                      errors.add("dberror",
new ActionError("error.database"));

errors.add("dbException", new ActionError(ex.getMessage())) ;
         return (mapping.findForward("failure"));

}

// Forward control to the specified success URI
return (mapping.findForward("success"));

}

}


===== JSP snippet ====
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html:html>
<head>
<title><bean:message key="finishReasonTest.title"/></title>
<html:base/>
</head>
<body bgcolor="white">

<h3><bean:message key="finishReasonTest.heading"/></h3>
<html:link page="/testFinishReason.do">
<bean:message key="finishReasonTest.testLink"/>
</html:link>

<!-- show any errors here -->
<html:errors/>

</body>
</html:html>

============================

What dumb stfw-rtfm mistake am I making?

=)

/\/\ark


___________________________________
- mark h. nichols
- dhsv022 at dhs dot state dot il dot us

"Ooo. They've got the Internet on computers now." - Homer Simpson


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>