Hallo, I have implemented a tag lib with some cases of nested cooperating tags.

For ex:

    <wall:img src="pix/cinema.gif" alt="Cinema" >
     <wall:alternate_img src="pix/cinema_big.gif" test="${bool}" />
    </wall:img>

    <wall:img src="pix/games.gif" alt="Games" >
     <wall:alternate_img src="pix/games_big.gif" test="${bool}" />
    </wall:img>

(complete example of usage: http://wurfl.sourceforge.net/java/coolmenu.php)

My big problem is that I just found out this doesn't work
on Weblogic 8.1 and, what's worse it does not produce
any significant diagnostics in the weblogic logs.

The JSP starts rendering and fails as soon as the second instance of the
img tag is encountered. Error msg (in the browser window):

{Exception in myjsp.jsp] null

On Tomcat 4 it works no problem.

Of course, I suspect that the problem could be due to different
strategies that the two appserver employ to reuse tag instances,
but I am not sure how I can fix this.
I do have some instance variables (necessary to allow the two tags too
cooperate), but I make sure they are initialized by doStartTag().

I attach the code of the two tags, if this can help...

thanks

Luca




/*
 ***************************************************************************
 * Copyright 2004 Luca Passani                                             *
 * Distributed under the Mozilla Public License                            *
 *   http://www.mozilla.org/NPL/MPL-1.1.txt                                *
 ***************************************************************************
 */

package net.sourceforge.wurfl.wall;

import net.sourceforge.wurfl.wurflapi.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;

/** The body-less wall:img
 */


public class WallImg extends TagSupport {
    
    HttpServletRequest request = null;
    private static CapabilityMatrix cm = null;
    private static UAManager uam = null;
    
    //locals
    WallDocument document = null;

    String warning = "";
    String UA = "";
    String device_id = "";
    String capability_value = "";
    String mark_up = "";

    String render_as =""; //valid values: "nothing","icon","image"    

    boolean inside_cool_menu = false;
    String imode_table_support = "";
    String xhtml_br = "";
    String css_hook = "";
    String chtml_br = "";
    String opwv_icon_space = "";

    String imode_eu_icon = "";
    String imode_ja_icon = "";
    String opwv_icon_localsrc = "";

    //cooperation methods (just a tiny bit of encapsulation)
    protected void setRender_as(String ra) {
        render_as = ra;
    }
    protected void setImode_eu_icon(String iei) {imode_eu_icon = iei;}
    protected void setImode_ja_icon(String iji) {imode_ja_icon = iji;}
    protected void setOpwv_icon_localsrc(String oil) {opwv_icon_localsrc = oil;}

    //maybe one day I'll understand why setSrc was not good enough for doing 
the same thing...
    protected void setSrc2(String s) {this.src = s;}

    //Attributes 
    String src = ""; 
    String alt = ""; 

    //accessors
    public void setSrc(String s) {this.src = s;}
    public void setAlt(String a) {this.alt = a;}


    /**
     * goStartTag
     * will be called when we see the "img" tag
     * there is one major difference between this tag and most other tags.
     * The rendering is done by doEndTag(), since the 'alernate_img' tag
     * nested inside the image tag can actually modify how the tag is rendered.
     */
    public int doStartTag() throws JspException {

        render_as ="image";
        xhtml_br = "";
        css_hook = "";
        chtml_br = "&nbsp;";
        imode_eu_icon = "";
        imode_ja_icon = "";
        opwv_icon_localsrc = "";

        WallCool_menu coolmenu = (WallCool_menu) findAncestorWithClass(this, 
WallCool_menu.class);
        if (coolmenu != null) {          
            inside_cool_menu = true;
            xhtml_br = "<br/>";
            css_hook = " class=\"coolmenu\"";
            opwv_icon_space = " ";
        }
 
        document = (WallDocument) findAncestorWithClass(this, 
WallDocument.class);
        if (document == null) {
            throw new JspTagException("Error in 'img' tag. No top 'document' 
tag found!");
        }
        cm = ObjectsManager.getCapabilityMatrixInstance();
        uam = ObjectsManager.getUAManagerInstance();
        request = (HttpServletRequest) pageContext.getRequest();
        
        //Check the capability string
        warning = TagUtil.checkCapability("preferred_markup");
        if (warning.length() > 0) {
            throw new JspException(warning);
        }
        
        //get the user agent
        UA = TagUtil.getUA(this.request);
        device_id = uam.getDeviceIDFromUALoose(UA);
        capability_value = cm.getCapabilityForDevice(device_id, 
"preferred_markup");
        mark_up = TagUtil.getWallMarkup(capability_value);       

        if (inside_cool_menu) {
               imode_table_support = cm.getCapabilityForDevice(device_id, 
"chtml_table_support");
               if (imode_table_support.equals("true")) {
                   chtml_br = "<br>";
               }
        }

        return(EVAL_BODY_INCLUDE);
            
    }
    
    public int doEndTag()  throws JspException {
        
        try {
            JspWriter out = pageContext.getOut();

            //XHTML first
            //out.println(device_id+"  "+mark_up+"  "+render_as);
            if ( mark_up.indexOf("xhtmlmp") != -1) { 
                if ( render_as.equals("image") ) {
                    out.print("<img"+css_hook+" src=\""+src+"\" alt=\""+alt+"\" 
/>"+xhtml_br); 
                }
                if ( render_as.equals("icon") && 
document.getUseXHTMLExtensions()) {
                    //only do something if device supports OPWV buil-in icons
                    out.print("<img src=\"\" alt=\""+alt+"\"");
                    out.print(" 
localsrc=\""+opwv_icon_localsrc+"\"/>"+xhtml_br); 
                }
                // if render_as == nothing, do nothing ;)
            }   

            //WML
            if ( mark_up.indexOf("wml") != -1) { 
                if ( render_as.equals("image") ) 
{
                     out.print(opwv_icon_space+"<img src=\""+src+"\" 
alt=\""+alt+"\" /> "); 
                }
                if ( render_as.equals("icon") && 
document.getUseWMLExtensions()) {
                    //only do something if device supports OPWV buil-in icons
                    out.print(opwv_icon_space+"<img src=\"\" alt=\""+alt+"\"");
                    out.print(" localsrc=\""+opwv_icon_localsrc+"\"/> "); 
                }
                // if render_as == nothing, do nothing ;)
            }   
            //CHTML
            if ( mark_up.indexOf("chtml") != -1) { 
                if ( render_as.equals("image") ) {
                     out.print("<img src=\""+src+"\" 
alt=\""+alt+"\">"+chtml_br); 


                }
                if ( render_as.equals("icon")) {
                       warning = TagUtil.checkCapability("imode_region");
                       if (warning.length() > 0) {
                           throw new JspException(warning);
                       }                       
                       String region = cm.getCapabilityForDevice(device_id, 
"imode_region");
                       if (region.equals("ja")) {
                           out.print(imode_ja_icon+chtml_br);              
                       }
                       if (region.equals("eu")) {
                           out.print(imode_eu_icon+chtml_br);              
                       }

                }
                // if render_as == nothing, do nothing ;)
            }   
        }
        catch(IOException ioe) {
            System.out.println("Error in Tag img: " + ioe);
        }
        return(EVAL_PAGE); // Continue with rest of JSP page
    }


    public void release() {

        render_as =null;
        
        inside_cool_menu = false;
        imode_table_support = null;
        xhtml_br = null;
        css_hook = null;
        chtml_br = null;
        opwv_icon_space = null;
        
        imode_eu_icon = null;
        imode_ja_icon = null;
        opwv_icon_localsrc = null;
    }
}

/*
 ***************************************************************************
 * Copyright 2004 Luca Passani                                             *
 * Distributed under the Mozilla Public License                            *
 *   http://www.mozilla.org/NPL/MPL-1.1.txt                                *
 ***************************************************************************
 */

package net.sourceforge.wurfl.wall;

import net.sourceforge.wurfl.wurflapi.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.*;

/** The body-less wall:alternate_img
 */


public class WallAlternate_img extends TagSupport {

    HttpServletRequest request = null;
    private static CapabilityMatrix cm = null;
    private static UAManager uam = null;
    
    //locals
    String warning = "";
    String UA = "";
    String device_id = "";
    String capability_value = "";
    String mark_up = "";

    //Attributes 
    boolean test = false;
    boolean nopicture = false;

    String src = ""; 
    String opwv_icon = "";
    String eu_imode_icon = "";
    String ja_imode_icon = "";


    //accessors

    public void setTest(boolean t) {
        this.test = t;
    }
    public void setTest(String t) {
        if(t.equalsIgnoreCase("true")){
           this.test  = true;
        } else {
           this.test  = false;
        }
    }

    public void setNopicture(boolean np) {
        this.nopicture = np;
    }
    public void setNopicture(String np) {
        if(np.equalsIgnoreCase("true")){
           this.nopicture  = true;
        } else {
           this.nopicture  = false;
        }
    }

    public void setSrc(String s) {this.src = s;}
    public void setOpwv_icon(String oi) {this.opwv_icon = oi;}
    public void setEu_imode_icon(String eii) {this.eu_imode_icon = eii;}
    public void setJa_imode_icon(String jii) {this.ja_imode_icon = jii;}
    
    /**
     * goStartTag
     * will be called when we see the "alternate_img" tag
     */
    public int doStartTag() throws JspException {
        
        cm = ObjectsManager.getCapabilityMatrixInstance();
        uam = ObjectsManager.getUAManagerInstance();
        request = (HttpServletRequest) pageContext.getRequest();
        
        //one and only one attribute at the time (apart from 'test' which is 
compulsory)
        int c = 0;
        if (!src.equals("")) c++;  
        if (!eu_imode_icon.equals("")) c++;  
        if (!ja_imode_icon.equals("")) c++;  
        if (!opwv_icon.equals("")) c++;  
        if (nopicture) c++;

        if (c == 0) {
            throw new JspTagException("tag 'alternate_img' must use one of the 
following attributes:\nsrc,opwv_icon,eu_imode_icon,ja_imode_ico or nopicture");
        }
        if (c > 1) {
            throw new JspTagException("tag 'alternate_img' must use one and 
only one of the following attributes:\nsrc,opwv_icon,eu_imode_icon,ja_imode_ico 
or nopicture");
        }


        //let's go for the root img. We'll need it later
        WallImg img = (WallImg) findAncestorWithClass(this, WallImg.class);
        if (img == null) {
            throw new JspTagException("tag 'alternate_img' must be nested 
inside an 'img' tag");
        } 
        
        //Check the capability string
        warning = TagUtil.checkCapability("preferred_markup");
        if (warning.length() > 0) {
            throw new JspException(warning);
        }
        
        //get the user agent
        UA = TagUtil.getUA(this.request);           
        device_id = uam.getDeviceIDFromUALoose(UA);
            
        capability_value = cm.getCapabilityForDevice(device_id, 
"preferred_markup");
        mark_up = TagUtil.getWallMarkup(capability_value);


        if ( test && nopicture ) {
            img.setRender_as("nothing");
            return (SKIP_BODY);
        }


        if (test && !src.equals("")) {
            img.setSrc2(src);      
            return (SKIP_BODY);
        }

        if ( mark_up.indexOf("chtml") != -1) { 
                       
            String region = cm.getCapabilityForDevice(device_id, 
"imode_region");
            if (test && region.equals("ja") && !ja_imode_icon.equals("")) {
                img.setRender_as("icon");
                img.setImode_ja_icon(ja_imode_icon);
                return (SKIP_BODY);
            }
            if (test && region.equals("eu") && !eu_imode_icon.equals("")) {
                img.setRender_as("icon");
                img.setImode_eu_icon(eu_imode_icon);
                return (SKIP_BODY);
            }
        }
        

        if ( mark_up.indexOf("xhtmlmp") != -1 || mark_up.indexOf("wml") != -1 ) 
{ 
                       
            if (test && !opwv_icon.equals("")) {
                img.setRender_as("icon");
                img.setOpwv_icon_localsrc(opwv_icon);
            }       
            return (SKIP_BODY);
        }
        
        return (SKIP_BODY);
    }


    public void release() {

        this.test = false;
        this.nopicture = false;

        this.src = null; 
        this.opwv_icon = null;
        this.eu_imode_icon = null;
        this.ja_imode_icon = null;
    }
}

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

Reply via email to