You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Paul Benedict (JIRA)" <ji...@apache.org> on 2007/09/01 05:55:34 UTC
[jira] Updated: (STR-1418) Errors and Messages should be easier to
manage
[ https://issues.apache.org/struts/browse/STR-1418?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Benedict updated STR-1418:
-------------------------------
Fix Version/s: Future
Assignee: (was: Struts Developers)
> Errors and Messages should be easier to manage
> ----------------------------------------------
>
> Key: STR-1418
> URL: https://issues.apache.org/struts/browse/STR-1418
> Project: Struts 1
> Issue Type: Improvement
> Components: Core
> Affects Versions: 1.1 RC1
> Environment: Operating System: All
> Platform: All
> Reporter: David Holscher
> Priority: Minor
> Fix For: Future
>
>
> 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.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.