You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Shawn Sohl <SS...@HNTB.com> on 2001/08/08 17:18:29 UTC

Validating errors

I'm having a small problem with displaying my error messages in my .jsp
page.  I'm probably missing something simple, so I'll just post my code and
hopefully someone can help.

   public ActionErrors validate(ActionMapping mapping,HttpServletRequest
req)
        {
            ActionErrors errors = new ActionErrors();

            System.out.println("Your in validate");

            try
              {
                  if((txtSubject == null) || (txtSubject.trim().length() <
1))
                    {
                       System.out.println("Your about to add subject
error");
                       errors.add("txtSubject",new
ActionError("error.subject.required"));
                    }

                  if((txtContentDefault == null) ||
(txtContentDefault.trim().length() < 1))
                    {
                      System.out.println("Your about to add content
default");
                       errors.add("content",new
ActionError("error.content.required"));
                    }
              }
            catch (Exception e)
              {
                  errors.add("exception",new ActionError(e.getMessage()));
              }

            return errors;
        }

.jsp page
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html locale="true">
<head>
<title>Successful Logon</title>
</head>

<body>
	<html:errors property="txtSubject"/>
</body>
</html:html>