Taglibs increasing the size of JSP.

Hi,
For my internaionalization project i have used taglibs for conversion of property file keys.

Since there is lot of data to be converted, i have to use lot of tags. Excess use of Tag (50-60 in number) has increased the size of my jsp when its parsed to java. And i am getting java.lang.VerifyError: Illegal Jump or branch start

How can i use my tag class effectively so that its not overhead to the JSP
agsinghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

agsinghAuthor Commented:
Here is my Tag Class
========================
import java.io.IOException;

import java.text.MessageFormat;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.ServletContext;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;


public class MessageTag extends BodyTagSupport
{
    // instance variables used during processing
    private String               _key = null;
    private String               _value = null;
    private ResourceBundle       _bundle = null;
    private boolean              _debug = false;

    // these are reused for each message tag; luckily tags are thread-safe
    private MessageFormat  _messageFormat = new MessageFormat("");
    private List           _arguments = new ArrayList();

    /**
     *  sets the key to use when looking up the value in the bundle
     */
    public final void setKey(String key)
    {
        _key = key;
    }

    /**
     *  sets the bundle to an actual ResourceBundle object<br>
     *  defined on the page by the i18n:bundle tag
     */
    public final void setBundle(ResourceBundle aBundle)
    {
        _bundle = aBundle;
    }

    /**
     *  @return the bundle to use
     */
    private ResourceBundle getBundle() throws JspException
    {
            if(_bundle == null)
            {
                  BundleTag bundleTag = (BundleTag)this.findAncestorWithClass(this,BundleTag.class);
                  if (bundleTag != null)
                  {
                        System.out.println("from bundle if");
                        return bundleTag.getBundle();
            }
            }
        return _bundle;
    }

    /**
     * Turn debugging log messages on or off
     */
    public final void setDebug(boolean value)
    {
        _debug = value;
    }

    /**
     *  clears the argument list so that sub tags can call addArgument
     *  clears out any previous key and value in case key is not provided,
     *  or the value is null
     */
    public final void release()
    {
        super.release();
        _key = null;
        _value = null;
        _bundle = null;
    }


      /**
       * To Print debug statements when _debug is true
       */
      private void debugLog(String message)
      {
            if(_debug)
            {
                        ServletContext sc = pageContext.getServletContext();
                        sc.log(message);
            }
      }


  /**
   *  locates the bundle and gets the value
   */
  public final int doStartTag() throws JspException
    {
       // Reset value for resource bundle key
       _value = null;

       // ensure we have a key
        if ( _key == null ) {
            throw new JspTagException("i18n:message tag requires a key attribute.");
        }

        ResourceBundle bundle = this.getBundle();
        if ( bundle == null ) {
            throw new JspTagException(
                "i18n:message tag, no bundle available for use.");
        }


        // see if the bundle has a value, if not, we default to the tag contents
        try {
            _value = bundle.getString(_key);
            debugLog("i18n:message tag: template for " + _key + " is: " + _value);
        } catch (java.util.MissingResourceException e) {
            ServletContext sc = pageContext.getServletContext();
            sc.log("i18n:message tag, value not found for key:" + _key);
        }

        return EVAL_BODY_TAG;
    }

    /**
     *  Performs the proper runtime substitution. If an id attribute was
     *  specified, then it is assumed that this tag is merely defining a
     *  string variable; otherwise output is provided.
     */
    public final int doEndTag() throws JspException
    {
        try {
            // if the value is null, use the body content
            if ( _value == null ) {
                _value = bodyContent.getString();
                bodyContent.clear();
            }
                  // print the value to the JspWriter
                  this.pageContext.getOut().print(_value);

        } catch (java.io.IOException e)
        {
            throw new JspTagException("i18n:message tag IO Error: " + e.getMessage());
        }

        // only process the body once
        return EVAL_PAGE;
    }

}
0
agsinghAuthor Commented:
Here is my Tag Class
========================
import java.io.IOException;

import java.text.MessageFormat;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.ServletContext;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;


public class MessageTag extends BodyTagSupport
{
    // instance variables used during processing
    private String               _key = null;
    private String               _value = null;
    private ResourceBundle       _bundle = null;
    private boolean              _debug = false;

    // these are reused for each message tag; luckily tags are thread-safe
    private MessageFormat  _messageFormat = new MessageFormat("");
    private List           _arguments = new ArrayList();

    /**
     *  sets the key to use when looking up the value in the bundle
     */
    public final void setKey(String key)
    {
        _key = key;
    }

    /**
     *  sets the bundle to an actual ResourceBundle object<br>
     *  defined on the page by the i18n:bundle tag
     */
    public final void setBundle(ResourceBundle aBundle)
    {
        _bundle = aBundle;
    }

    /**
     *  @return the bundle to use
     */
    private ResourceBundle getBundle() throws JspException
    {
            if(_bundle == null)
            {
                  BundleTag bundleTag = (BundleTag)this.findAncestorWithClass(this,BundleTag.class);
                  if (bundleTag != null)
                  {
                        System.out.println("from bundle if");
                        return bundleTag.getBundle();
            }
            }
        return _bundle;
    }

    /**
     * Turn debugging log messages on or off
     */
    public final void setDebug(boolean value)
    {
        _debug = value;
    }

    /**
     *  clears the argument list so that sub tags can call addArgument
     *  clears out any previous key and value in case key is not provided,
     *  or the value is null
     */
    public final void release()
    {
        super.release();
        _key = null;
        _value = null;
        _bundle = null;
    }


      /**
       * To Print debug statements when _debug is true
       */
      private void debugLog(String message)
      {
            if(_debug)
            {
                        ServletContext sc = pageContext.getServletContext();
                        sc.log(message);
            }
      }


  /**
   *  locates the bundle and gets the value
   */
  public final int doStartTag() throws JspException
    {
       // Reset value for resource bundle key
       _value = null;

       // ensure we have a key
        if ( _key == null ) {
            throw new JspTagException("i18n:message tag requires a key attribute.");
        }

        ResourceBundle bundle = this.getBundle();
        if ( bundle == null ) {
            throw new JspTagException(
                "i18n:message tag, no bundle available for use.");
        }


        // see if the bundle has a value, if not, we default to the tag contents
        try {
            _value = bundle.getString(_key);
            debugLog("i18n:message tag: template for " + _key + " is: " + _value);
        } catch (java.util.MissingResourceException e) {
            ServletContext sc = pageContext.getServletContext();
            sc.log("i18n:message tag, value not found for key:" + _key);
        }

        return EVAL_BODY_TAG;
    }

    /**
     *  Performs the proper runtime substitution. If an id attribute was
     *  specified, then it is assumed that this tag is merely defining a
     *  string variable; otherwise output is provided.
     */
    public final int doEndTag() throws JspException
    {
        try {
            // if the value is null, use the body content
            if ( _value == null ) {
                _value = bodyContent.getString();
                bodyContent.clear();
            }
                  // print the value to the JspWriter
                  this.pageContext.getOut().print(_value);

        } catch (java.io.IOException e)
        {
            throw new JspTagException("i18n:message tag IO Error: " + e.getMessage());
        }

        // only process the body once
        return EVAL_PAGE;
    }

}
0
objectsCommented:
what does your jsp look like?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

agsinghAuthor Commented:
pasting a portion of my JSP ..if it help
==========================================

<span id="alert"><center><font size=4 color="red">
<%if(msg!=null && !msg.equals("")) { %>
<i18n:message key='<%="tops.text." + ((String)(cc_abObj.getParams("uc15ErrMsg")))%>' debug="true" ></i18n:message><br>
 <%}%>

<%if(msg1!=null && !msg1.equals("")) { %>
<i18n:message key='<%="tops.text." + ((String)(cc_abObj.getParams("SuccMsg")))%>' debug="true" ></i18n:message>
 <i18n:message key='<%="tops.listbox." + ((String)vecCollectShift.get(vecCollectShift.indexOf(strShiftName)+1))%>' debug="true" ></i18n:message>
 <i18n:message key='tops.text.Successfully' debug="true" ></i18n:message>
<!--%=(cc_abObj.getParams("excludeDays"))%-->
 <i18n:message key='tops.text.From' debug="true" ></i18n:message>  <i18n:formatDate value='<%=((String)(cc_abObj.getParams("startDate")))%>' />
 <i18n:message key='tops.text.To' debug="true" ></i18n:message>  <i18n:formatDate value='<%=((String)(cc_abObj.getParams("endDate")))%>' /><br>
 <%}%>

<%if(msg2!=null && !msg2.equals("")) {
     out.println(msg2+"<br>");
}%>

</font></center></span>

<table id="tableRow" border="1" cellspacing="2" cellpadding="2" align="center">
<tr>
<td><b><i18n:message key="tops.text.SupervisorName" debug="true" ></i18n:message></b></td>
<td>
<select multiple  size="3"  name="strlSupervisor">
<option value = "ALL"><i18n:message key="tops.listbox.SelectAll" debug="true" ></i18n:message></option>
     <%
     if(vecSupverisorList != null)
     {
               for(int i=0;i<vecSupverisorList.size();i++)
                    {
                              strEmpNo=(String)vecSupverisorList.elementAt(i);
                              strEmpName=(String)vecSupverisorList.elementAt(++i);
               %>
               <option value="<%=strEmpNo%>"

               <%
                         if(strlSupervisor != null)
                         {
                              for(int k=0;k<strlSupervisor.length;k++)
                              {
                                   if(strEmpNo.equalsIgnoreCase(strlSupervisor[k]))
                                   {
                                        out.println("selected");
                                   }
                              }
                         }
               %>>
               <%=strEmpName%></option>
               <%
                    }
               }
               %>
</select>
</td>
<td>
<input type="button" id="topsButton" name="collectEmp" value="<i18n:message key="tops.button.GetEmployee" debug="true" >Get Employees</i18n:message>" onClick="callSuperVisor(this.form)";>
</td>
</tr>
</table>

<%
Vector vecWorkerList = (Vector)cc_abObj.getObject("vecWorkerList");
if(vecWorkerList != null)
{
if(vecWorkerList.size() != 0)
{
%>
<table id="tableRow" border="1" cellspacing="2" cellpadding="2" align="center">
<tr>
          <td align="left" >
          <table id="tableRow" border="1" cellspacing="2" cellpadding="2" align="center">
          <tr valign = "top">
          <td valign = "top"><b><i18n:message key="tops.text.EmployeeNameNumber" debug="true" >Employee Name/Number</i18n:message></b></td>
          </tr>
====================================
0
objectsCommented:
Have a look at the generated Java to see what is causing the exception.
0
doddjamesCommented:

Hey,

If your current approach is giving you too much overhead, then what about

<i18n:bundle id="myBundle"/>

<%=myBundle.getString( "myKey" )%>
<%=myBundle.getString( "myOtherKey" )%>

You will need to know about TEI classes for you to write a Tag that will put the bundle in the PageContext so the JSP can use it.

Incidentally, in the past I have found that containers implements Tag re-use and lifecycles differently, so check what yours is doing.  If it calls release() after every invocation then your tag is hugely expensive.  If it doesn't recycle Tags (and I have seen a container that didn't!) then this is also very expensive for you.

Here's some information on TEI classes:

http://www.orionserver.com/taglibtut/5.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
agsinghAuthor Commented:
as a workaround i am using <%=myBundle.getString( "myKey" )%>... But i am getting error in a very unexpected fashion. Same file which is working fine, if it changed a bit and happen to recompile gives me Verify error.

I am pasting converted java file for tag
+++++++++++++++++++++++++++++++++
release() is called for every invocation, apparently its not recycling
=================================
// begin message custom tag block... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
com.gepower.gees.tops.i18n.MessageTag _com_gepower_gees_tops_i18n_MessageTag_0 = null; //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** declare AT_BEGIN TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
try { // begin instantiate/release try/catch/finally block... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0 = new com.gepower.gees.tops.i18n.MessageTag(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setPageContext(pageContext); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setParent(_com_gepower_gees_tops_i18n_BundleTag_0); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setDebug(Boolean.valueOf(weblogic.utils.StringUtils.valueOf("true")).booleanValue()); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setKey(weblogic.utils.StringUtils.valueOf("tops.text.AssignShift")); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
int _int_1 = _com_gepower_gees_tops_i18n_MessageTag_0.doStartTag(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_int_1 == Tag.EVAL_BODY_INCLUDE) { //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    throw new JspTagException("Since tag class com.gepower.gees.tops.i18n.MessageTag implements BodyTag, it cannot return Tag.EVAL_BODY_INCLUDE"); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** sync AT_BEGIN TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_int_1 != Tag.SKIP_BODY) { // begin !SKIP_BODY... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    if (_int_1 != Tag.EVAL_BODY_INCLUDE) { //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      out = pageContext.pushBody(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      _com_gepower_gees_tops_i18n_MessageTag_0.setBodyContent((BodyContent)out); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    } //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    try { // begin pushBody try/finally  //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      _com_gepower_gees_tops_i18n_MessageTag_0.doInitBody(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      do { //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
          /*** declare & sync NESTED TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
          //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
          out.print("Assign Shift");
          //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      } while (_com_gepower_gees_tops_i18n_MessageTag_0.doAfterBody() == BodyTag.EVAL_BODY_TAG); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    } finally { // end pushBody try/finally //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      if (_int_1 != Tag.EVAL_BODY_INCLUDE) //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      out = pageContext.popBody(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    } //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} // end !SKIP_BODY //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_com_gepower_gees_tops_i18n_MessageTag_0.doEndTag() == Tag.SKIP_PAGE) return; //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} catch (java.lang.Exception _java_lang_Exception_0) { // instantiate/release try/catch/finally //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
throw new ServletException("runtime failure in custom tag 'message'", _java_lang_Exception_0); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} finally { // instantiate/release try/catch/finally block... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_com_gepower_gees_tops_i18n_MessageTag_0 != null) _com_gepower_gees_tops_i18n_MessageTag_0.release(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
//end message custom.... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** declare & sync AT_END TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** sync AT_BEGIN TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
0
agsinghAuthor Commented:
I m using weblogic 510 SP 8
0
doddjamesCommented:

The other approach you could use would be to contextualize your i18n lookups, e.g.

<i18n:bundle>
    <i18n:lookup key="myKey"/>
    <i18n:whatever/>
</i18n:bundle>

Your child tags get the loaded bundle from the parent.

As an aside, many people have written i18n libraries, so why not use one?

http://jakarta.apache.org/taglibs/doc/i18n-doc/intro.html
0
agsinghAuthor Commented:
This is what i am doing..
<%@ taglib uri="tops-i18n.tld" prefix="i18n" %>
<i18n:bundle id="_bundle" debug="true" baseName="properties.tops3.i18n.language">
.
.
.

<i18n:message key="myKey" debug="true" >Assign Shift</i18n:message>
.
.


</i18n:bundle>
message tag is getting bundle from the bundle tag

I am using jakarta taglibs, with minor modification
-Ag
0
doddjamesCommented:

Ah, sorry.  I thought you were writing your own.

The verify error must be being caused by a fault in weblogic's jsp compiler.  BEA do make reference to this problem..

"-noTryBlocks

If a JSP file has numerous or deeply nested custom JSP tags and you receive a java.lang.VerifyError exception when compiling, use this flag to allow the JSPs to compile correctly."

According to what I've read on the net, you should be able to configure weblogic.xml to supply this parameter to the compiler:

<jsp-param>
  <param-name>compileFlags</param-name>
  <param-value>"-noTryBlocks"</param-value>
</jsp-param>




0
agsinghAuthor Commented:
thats a relief..!!
I have not deployed my app as a webapplication so not using web.xml, using weblogic.properties
Any idea how to pass -noTryBlocks through it,
Also can u give me a ref where u found this fault in weblogic JSP compiler.

Thanks,
0
doddjamesCommented:

Hmm.. That option won't work with a WL5.1 jspc (need WL6.0+).  They didn't address the problem with a compiler option until 6.0.

http://www.weblogic.com/docs51/classdocs/API_jsp.html#compiler
http://edocs.bea.com/wls/docs60/jsp/reference.html#57794

You could also try finding a different jsp compiler and configuring WL to use that instead.  Maybe it'll produce more efficient code.

The root problem seems to be that your generated class files are too big.  The elimination of all the try/catch blocks generated by the jsp compiler would help (if you could do it with WL5.1, which you don't seem to be able to :-( ), but failing that you're just going to have to slim down or refactor your JSP into more manageable chunks and <jsp:include/> bits and bobs here and there.

http://www.caucho.com/support/resin-interest/0005/0251.html

0
agsinghAuthor Commented:
getting lots of problems when compiling using java weblogic.jspc
[jspc] parsed .\tnl\jsp\calledbackreport.jsp in 661 ms.
[jspc] generated java file c:\abhi\jsp_servlet\__46_\_tnl\_jsp\_calledbackreport.java, invoking java compiler:
Exec failed .. exiting

:(
0
agsinghAuthor Commented:
didnt get my answer..perhaps it was a wrong implementation of Taglibs.
There is lot behind the scenes. Thanks James for clearing out some of them..!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.