Question

Pretty much everything in the title. The documentation isn't clear about the consequences of this call.

My particular situation is that this method is called with null passed in parameter and there is code before and after. I don't get the purpose of this call...
Note that the context is a class extending SimpleTagSupport ( I'm doing taglib stuff).

Thanks for any pointer. Here is the javadoc :

invoke

public abstract void invoke(java.io.Writer out)
                     throws JspException,
                            java.io.IOException

    Executes the fragment and directs all output to the given Writer, or the JspWriter returned by the getOut() method of the JspContext associated with the fragment if out is null.

    Parameters:
        out - The Writer to output the fragment to, or null if output should be sent to JspContext.getOut(). 
    Throws:
        JspException - Thrown if an error occured while invoking this fragment. 
        SkipPageException - Thrown if the page that (either directly or indirectly) invoked the tag handler that invoked this fragment is to cease evaluation. The container must throw this exception if a Classic Tag Handler returned Tag.SKIP_PAGE or if a Simple Tag Handler threw SkipPageException. 
        java.io.IOException - If there was an error writing to the stream.
Was it helpful?

Solution

Well, it allows for a tag to receive a JSP fragment (the body of the tag) to execute when the tag wants to. For example, you could design an if tag which receives a condition argument, and has a tag body. If the condition is false, the tag doesn't do anything. If it's true, the tag invokes the fragment. A loop tag could invoke its fragment (executes the JSP code that is in its body) as many times as its iterationCount argument asks for.

Since the fragment is probably used to generate some HTML code to include in the response, the out argument of the method is where the fragment's output is generated. You might want to pass another writer if you want to postprocess what the fragment generates, for example, rather than letting the fragment write directly to the JSP writer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top