Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 829225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:50:54+00:00 2026-05-15T03:50:54+00:00

I have a jsp which uses a lot of javascript and it’s just not

  • 0

I have a jsp which uses a lot of javascript and it’s just not fast enough. I would like to optimize it so first, here’s a part of the code:

In the jsp I have the initialization:

window.onload = function () {
        formCollection.pageSize.value = "<%= pagingSize%>";
        elemCollection = iDom3.Table.all["spis"].XML.DOM;
        <%  if (resultList != null) { %>
        elementsNumber = <%= resultList.size() %>;
        <%} else { %>
        elementsNumber = 0;
        <% } %> 
        contextPath = "<%= request.getContextPath() %>";
    }

In my js file I have two types of js functions:

// gets the first element and sets it's value to all the other; 
//the selectSingleNode function is used because I use XSLT transformation 
//to generate the table

_setTehJed = function(){    
        var resultId = formCollection.elements["idTehJedinice_spis_1"].value;
        var resultText = formCollection.elements["tehnicka_spis_1"].value;
        if (resultId != ""){
            var counter = 1;
            while (counter<elementsNumber){
                counter++;
                if(formCollection.elements["idTehJedinice_spis_"+counter] != null){
                    formCollection.elements["idTehJedinice_spis_"+counter].value=resultId;
                    formCollection.elements["tehnicka_spis_"+counter].value=resultText;
                }
                var node=elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'tehnicka']/title");
                node.text=resultText;
                var node2=elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'idTehJedinice']/title");
                node2.text=resultId;
            }
        }

    }

// sets the elements checkbox to checked or unchecked
_SelectCheckRokCuvanja = {
        all : [],

        Item : function (oItem, sId) {
                this.all["spis_"+sId] = oItem.value;
                if (oItem.checked) {
                    elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "true");
                }else{
                    elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "false");
                }
        }
    }

I’ve used these tips:

  • https://web.archive.org/web/20151029015752/http://blogs.msdn.com:80/b/ie/archive/2006/08/28/728654.aspx
  • http://code.google.com/speed/articles/optimizing-javascript.html

but I still think something could be done like defining the functions like this:

In the jsp:

window.onload = function () {
        iDom3.DigitalnaArhivaPrihvat.formCollection=document.forms["controller"];
        iDom3.DigitalnaArhivaPrihvat.formCollection.pageSize.value = "<%= pagingSize%>";
        iDom3.DigitalnaArhivaPrihvat.elemCollection = iDom3.Table.all["spis"].XML.DOM;
        <%  if (resultList != null) { %>
        iDom3.DigitalnaArhivaPrihvat.elementsNumber = <%= resultList.size() %>
        <%} else { %>
        iDom3.DigitalnaArhivaPrihvat.elementsNumber = 0;
        <% } %> 
}

in the js:

iDom3.DigitalnaArhivaPrihvat = {
        
    formCollection:null,
    elemCollection:null,
    elementsNumber:null,


_setTehJed : function(){    
        var resultId = this.formCollection.elements.idTehJedinice_spis_1.value;
        var resultText = this.formCollection.elements.tehnicka_spis_1.value;
        if (resultId != ""){
            var counter = 1;
            while (counter<this.elementsNumber){
                counter++;
                if(this.formCollection.elements["idTehJedinice_spis_"+counter] !== null){
                    this.formCollection.elements["idTehJedinice_spis_"+counter].value=resultId;
                    this.formCollection.elements["tehnicka_spis_"+counter].value=resultText;
                }
                var node=this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'tehnicka']/title");
                node.text=resultText;
                var node2=this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'idTehJedinice']/title");
                node2.text=resultId;
            }
        }

    },

_SelectCheckRokCuvanja = {
        all : [],

        Item : function (oItem, sId) {
                this.all["spis_"+sId] = oItem.value;
                if (oItem.checked) {
                    this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "true");
                }else{
                    this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "false");
                }
        }
    }

but the problem is scoping (if I do it like this, the second function does not execute properly). Any suggestions?

Edit: Data structure of the table:

<row id="spis_3">
    <data col="rokCheck" type="check" default="false" onchange="_ChangeTypeRokCuvanje(this,'3')" >
    <title>false</title>
    <description>Tehnička jedinica</description>
</data>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:50:55+00:00Added an answer on May 15, 2026 at 3:50 am

    selectSingleNode() is a pretty expensive operation. You should try to avoid it. There are two solutions:

    1. Iterate over the data structure yourself (so you don’t have to search the DOM for the table but you can directly modify row by row).

    2. Since you assign every row an ID, you should be able to use document.getElementById() without the expensive XPath lookup.

    3. Use a framework like jquery to get all relevant nodes at once (-> only 1 expensive lookup) and then iterate over the list.

    [EDIT] See Traversing an HTML table with JavaScript and DOM Interfaces for an example how to implement #1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSP which attaches a XSL to an XML document pulled from
I have a web application (Java, Websphere, JSP) which allows co-workers to register visitors
We have the usual web.xml for our web application which includes some jsp and
I am changing a GET to a POST. Currently I have .jsp?id=a,b,c,d. When changing
I have a jsp page with two radio tags. The page contains a struts2
I have a JSP that is using Spring:form tags to bind controls to a
Right now I have a JSP page that allows to sort some items, when
I'm running tomcat and have some jsp pages that display a subset of a
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =
I have done Java and JSP programming in the past, but I am new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.