indexing a JSTL object array

indexing a JSTL object array

soenisoeni Posts: 2Questions: 1Answers: 0

I have passed an IPL_LIST (this is an array of objects that I use to populate my datatable i am not displaying all the information from the rows just some of it ) to my JSP page list-ipls.jsp

        request.setAttribute("IPL_LIST", ipls);

        //Send to JSP page (view) JSP page is called list-ipls.jsp
        RequestDispatcher dispatcher = request.getRequestDispatcher("/list-ipls.jsp");
        dispatcher.forward(request, response);

On the list-ipls.jsp page I am monitoring for a user clicking on a datatable and I grab the row clicked and load a Modal with data from the table row. However I am not displaying all the information in the Table that I require in the Modal and hence I am wanting to read that information from my IPL_LIST. I want to index the the IPL_LIST with the row that the user has clicked on which is the variable indexNo in the JS below. However "${IPL_LIST[indexNo].sensor}"; just does not work. If for example I put a number in place of indexNo ie. "${IPL_LIST[2].sensor}" everything works fine.

How can I set indexNo inside of IPL_LIST[ ] to indicate what row I want to read .sensor from?

var table = $('#example').DataTable();
$('#example tbody').on('click', 'tr', function () {
    var data = table.row( this ).data();
var indexNo = data[0];
    alert( 'You clicked on '+data[0]+'\'s row' );
    document.getElementById('iplId').value= data[0] ; 
    document.getElementById('tagName').value= data[2] ; 
   
   document.getElementById('sensor').value= "${IPL_LIST[indexNo].sensor}"; *** This will not work ***

    $("#modalScrollableCenter").modal();
} );

Appreciate any help. Thanks

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    "${IPL_LIST[indexNo].sensor}"; just does not work.

    What happens? Do you get an error? Is the wrong sensor info retrieved?

    ITs hard to say what the problem might be without actually seeing an example of your data. What is indexNo? Is it . a string or a number? Does it need to be a string or a number? Is the value actually correct for ${IPL_LIST[indexNo].sensor?

    Kevin

  • soenisoeni Posts: 2Questions: 1Answers: 0

    ${IPL_LIST[2]} returns the following data

    Ipl [iplId=3, Type=PCS, tagName=56789, description=Nitrogen, sensor=we1234, sysNumber=5678]

    ${IPL_LIST[2].sensor} returns the following data

    we1234

    However, i need to enter the the number (2 above) based on the actual datatable row that is clicked. The row that is clicked is stored in integer variable indexNo

    var indexNo = 2;
    ${IPL_LIST[indexNo].sensor}

    Does not return anything

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    Seems odd that ${IPL_LIST[2].sensor} works but this doesn't:

    var indexNo = 2;
    ${IPL_LIST[indexNo].sensor}
    

    I gather from this that var indexNo = data[0]; results in indexNo being an integer not a string?

    Can you provide a link to your page or a test case so we can take a look? Without actually being able to see it and look at things it will be hard to diagnose.

    Kevin

This discussion has been closed.