Announcement Announcement Module
Collapse
No announcement yet.
Wrapping ErrorsTag, overriding renderDefaultContent Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wrapping ErrorsTag, overriding renderDefaultContent

    I'm using Spring 2.0.x. I can't upgrade to 2.5.x on this project.

    I'm using validators, and create an error as follows:
    Code:
    String args[] = { "a.second.message.properties.key" };
    errors.rejectValue("field", "message.properties.key", args, "default error message.");
    In message.properties:
    Code:
    message.properties.key={0} works really well.
    a.second.message.properties.key=This
    I want the error displayed to be "This works really well.", but instead, get "a.second.message.properties.key works really well." I've decided to make a relatively dirty hack around this; put delimiters around that second message properties key, wrap the ErrorsTag, and do the substitution myself.

    Problem is that Spring 2.0 ErrorsTag extends TagSupport; Spring 2.5 ErrorsTag extends BodyTagSupport, which would make this *much* easier. I tried various things, and finally gave up on wrapping BodyTagSupport around ErrorsTag in Java. What I've come to is this:

    Code:
    public class HcaErrorsTag extends ErrorsTag {
    
    	private static final long serialVersionUID = 3L;
    
    	public HcaErrorsTag() {
    		setCssClass("errors");
    		setPath("*");
    	}
    	
    	protected void renderDefaultContent(TagWriter tagWriter) throws JspException {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		OutputStreamWriter osw = new OutputStreamWriter(baos);
    		TagWriter tempTagWriter = new TagWriter(osw);
    		super.renderDefaultContent(tempTagWriter);
    		
    		try {
    			String contentString = baos.toString();
    			if (contentString != null) {
    				pageContext.getOut().write(contentString);
    			}
    		} catch (IOException ioe) {
    			throw new JspException(ioe);
    		}
    	}
    }
    except that this method doesn't seem to get called.

    What additional debugging steps should I take? Did I go wrong somewhere obvious? Can I go back away from this dirty hack and do the same thing in a much more straightforward manner?

  • #2
    Well, that didn't take long.

    Ding. It wasn't getting called because I hadn't called setPath.
    Code:
    setPath("*")
    Also, I forgot a
    Code:
    osw.flush();
    , or this doesn't actually ever have any output.

    Comment

    Working...
    X