You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/02/14 06:42:07 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/html MessagesTag.java

dgraham     2003/02/13 21:42:07

  Modified:    src/share/org/apache/struts/taglib/html MessagesTag.java
  Log:
  Added debug log for missing resource key.  PR# 17050.
  
  Revision  Changes    Path
  1.9       +51 -32    jakarta-struts/src/share/org/apache/struts/taglib/html/MessagesTag.java
  
  Index: MessagesTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/MessagesTag.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MessagesTag.java	30 Jan 2003 06:22:01 -0000	1.8
  +++ MessagesTag.java	14 Feb 2003 05:42:07 -0000	1.9
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -66,9 +66,12 @@
   import javax.servlet.jsp.JspException;
   import javax.servlet.jsp.tagext.BodyTagSupport;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.struts.Globals;
   import org.apache.struts.action.ActionMessage;
   import org.apache.struts.action.ActionMessages;
  +import org.apache.struts.action.ActionServlet;
   import org.apache.struts.util.MessageResources;
   import org.apache.struts.util.RequestUtils;
   import org.apache.struts.util.ResponseUtils;
  @@ -94,6 +97,12 @@
          MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
   
       /**
  +     * Commons Logging instance.
  +     * @since Struts 1.1
  +     */
  +    protected static Log log = LogFactory.getLog(MessagesTag.class);
  +
  +    /**
        * Iterator of the elements of this error collection, while we are actually
        * running.
       */
  @@ -224,8 +233,9 @@
           // Were any messages specified?
           ActionMessages messages = null;
   
  -        if (message != null && "true".equalsIgnoreCase(message))
  -           name = Globals.MESSAGE_KEY;
  +        if (message != null && "true".equalsIgnoreCase(message)) {
  +            name = Globals.MESSAGE_KEY;
  +        }
   
           try {
               messages = RequestUtils.getActionMessages(pageContext, name);
  @@ -235,36 +245,45 @@
           }
   
           // Acquire the collection we are going to iterate over
  -        if (property == null)
  +        if (property == null) {
               iterator = messages.get();
  -        else
  +        } else {
               iterator = messages.get(property);
  +        }
   
  -    // Store the first value and evaluate, or skip the body if none
  -    if (iterator.hasNext()) {
  -           ActionMessage report = (ActionMessage)iterator.next();
  -           String msg = RequestUtils.message(pageContext, bundle,
  -                                             locale, report.getKey(),
  -                                             report.getValues());
  -
  -       pageContext.setAttribute(id, msg);
  -
  -           if (header != null && header.length() > 0) {
  -              String headerMessage = RequestUtils.message(pageContext, bundle,
  -                                                             locale, header);
  -              if (headerMessage != null) {
  -                 // Print the results to our output writer
  -                 ResponseUtils.write(pageContext, headerMessage);
  -              }
  -           }
  -
  -           // Set the processed variable to true so the
  -           // doEndTag() knows processing took place
  -           processed = true;
  +        // Store the first value and evaluate, or skip the body if none
  +        if (iterator.hasNext()) {
  +            ActionMessage report = (ActionMessage) iterator.next();
  +            String msg =
  +                RequestUtils.message(
  +                    pageContext,
  +                    bundle,
  +                    locale,
  +                    report.getKey(),
  +                    report.getValues());
  +
  +            // log missing key to ease debugging
  +            if (msg == null && log.isDebugEnabled()) {
  +                log.debug(messageResources.getMessage("messageTag.resources", report.getKey()));
  +            }
  +
  +            pageContext.setAttribute(id, msg);
  +
  +            if (header != null && header.length() > 0) {
  +                String headerMessage = RequestUtils.message(pageContext, bundle, locale, header);
  +                if (headerMessage != null) {
  +                    // Print the results to our output writer
  +                    ResponseUtils.write(pageContext, headerMessage);
  +                }
  +            }
  +
  +            // Set the processed variable to true so the
  +            // doEndTag() knows processing took place
  +            processed = true;
   
  -       return (EVAL_BODY_TAG);
  +            return (EVAL_BODY_TAG);
           } else {
  -           return (SKIP_BODY);
  +            return (SKIP_BODY);
           }
   
       }
  
  
  

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


Re: cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/html MessagesTag.java

Posted by Robert Leland <rl...@apache.org>.
dgraham@apache.org wrote:
>        /**
>   +     * Commons Logging instance.
>   +     * @since Struts 1.1
>   +     */
>   +    protected static Log log = LogFactory.getLog(MessagesTag.class);


By sharing thge logger errors will look like they are coming
from MessageTag instead of any derived class. Additionally,
there is no way to selectively show the logging only for
the derived class.

-Rob


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