tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remy Maucherat <r...@apache.org>
Subject Re: tag plugin
Date Thu, 18 Aug 2005 07:55:38 GMT
wing lee wrote:
> I've tried the generateBody method, but it just generate such code 
> "write.out(body content)", don't return the value of the body content. 

That's odd: it's supposed to continue evaluation and code generation for
the body, not consider nested stuff as static text. There's a good
example with the "if" tag plugin (although, as I said, I didn't test it
at all, so maybe it's broken).

public final class If implements TagPlugin {

    public void doTag(TagPluginContext ctxt) {
	String condV = ctxt.getTemporaryVariableName();
	ctxt.generateJavaSource("boolean " + condV + "=");
	ctxt.generateAttribute("test");
	ctxt.generateJavaSource(";");
	if (ctxt.isAttributeSpecified("var")) {
	    String scope = "PageContext.PAGE_SCOPE";
	    if (ctxt.isAttributeSpecified("scope")) {
		String scopeStr = ctxt.getConstantAttribute("scope");
		if ("request".equals(scopeStr)) {
		    scope = "PageContext.REQUEST_SCOPE";
		} else if ("session".equals(scopeStr)) {
		    scope = "PageContext.SESSION_SCOPE";
		} else if ("application".equals(scopeStr)) {
		    scope = "PageContext.APPLICATION_SCOPE";
		}
	    }
	    ctxt.generateJavaSource("_jspx_page_context.setAttribute(");
	    ctxt.generateAttribute("var");
	    ctxt.generateJavaSource(", new Boolean(" + condV + ")," + scope +
");");
	}
	ctxt.generateJavaSource("if (" + condV + "){");
>>>>	ctxt.generateBody();
	ctxt.generateJavaSource("}");
    }
}

Rémy

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


Mime
View raw message