You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2003/04/26 16:12:42 UTC

DO NOT REPLY [Bug 19346] New: - Errors and Messages should be easier to manage

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19346>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19346

Errors and Messages should be easier to manage

           Summary: Errors and Messages should be easier to manage
           Product: Struts
           Version: 1.1 RC1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Controller
        AssignedTo: struts-dev@jakarta.apache.org
        ReportedBy: David.Holscher@nav-international.com


It would be very useful if Action and ActionForm had a common interface for 
registering messages and errors. As it stands there is common setup that has to 
be done in every validate and execute method. For example most of the following 
from the example application is just extra syntax:

   public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();

	if ((host == null) || (host.length() < 1))
            errors.add("host",
                       new ActionError("error.host.required"));
	if ((username == null) || (username.length() < 1))
            errors.add("username",
                       new ActionError("error.username.required"));
	if ((password == null) || (password.length() < 1))
            errors.add("password",
                       new ActionError("error.password.required"));
	if ((type == null) || (type.length() < 1))
            errors.add("type",
                       new ActionError("error.type.required"));
	else if (!"imap".equals(type) && !"pop3".equals(type))
            errors.add("type",
                       new ActionError("error.type.invalid", type));

	return (errors);

    }

Why not get rid of the error return and add some convenience methods to 
ActionForm like

  protected void addError(HttpServletRequest request, ActionError error);
  protected void addError(HttpServletRequest request, String property, String 
key);
  protected void addError(HttpServletRequest request, String property, 
ActionError error);
  protected void addMessage(HttpServletRequest request, ActionMessage message);
  protected void addMessage(HttpServletRequest request, String property, 
ActionMessage message);
  protected void addMessage(HttpServletRequest request, String property, String 
key);
(Add more with some optional message parameters)
These methods could look to see if there was already a set of errors or message 
s registered with the request and add it if not and then add to the set of 
errors or messages. An identical pattern could be used for Actions. This would 
make the method look like:

   public void validate(ActionMapping mapping,
                                 HttpServletRequest request) {

	if ((host == null) || (host.length() < 1))
            addError("host", "error.host.required");
	if ((username == null) || (username.length() < 1))
            addError("username", "error.username.required");
	if ((password == null) || (password.length() < 1))
            addError("password", "error.password.required");
	if ((type == null) || (type.length() < 1))
            addError("type", "error.type.required");
	else if (!"imap".equals(type) && !"pop3".equals(type))
            addError("type", "error.type.invalid", type);
    }

This common stuff ought to be easy.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org