tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kin-man Chung <Kin-Man.Ch...@Sun.COM>
Subject Re: tag plugin
Date Mon, 22 Aug 2005 17:52:10 GMT
The body content of a tag is a runtime entity, and you cannot
generally get it during compilation time, since it may contain
non-template texts.  You need to achieve what you want in another way,
such as the use of JSP fragments.

-Kin-man

On Sat, 2005-08-20 at 00:26, wing lee wrote:
> I think it's ok in the "if" tag. When the following code
>  
> ctxt.generateJavaSource("if (" + condV + "){");
> >>>> ctxt.generateBody();
> ctxt.generateJavaSource("}");
> 
> is executed, the generated code is supposed to be:
> 
> if(temp_name_of_condV){
> 
> out.write(body_content);
> 
> }
> 
> the generateBody method not generates the code "body_content", but the "out.write(body_content)".
so I can not write the code to get the value of the body like following:
> 
> String tempName = ctxt.getTemporaryVariable();
> 
> ctxt.generateJavaSource("Object "+tempName+"=");
> 
> ctxt.generateBody();
> 
> ctxt.generateJavaSource(";");
> 
> because the generated code will be like this:
> 
> Object temp_name = out.write(body_content);
> not this:
> Object temp_name = body_content;
> 
> so this is what confuses me.
> 
> Remy Maucherat <remm@apache.org> 写道:
> 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
> 
> 
> 		
> ---------------------------------
> DO YOU YAHOO!?
>   雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 


---------------------------------------------------------------------
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