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 <[EMAIL PROTECTED]> 写道:
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
>               
> ---------------------------------
> DO YOU YAHOO!?
>   雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to