Search code examples
javastruts

How to use struts taglib tag in JavaScript


I am using a struts tag in my JS function i-e

var ptp = "<c:out value='${myFormBean.myVar[0]}'/>";

and it gives me the correct value by taking from appropriate bean, but i have to use it for multiple rows that are being showed there using a loop and that is why i send the index of row in the function, but when i try try to put that variable into the above line like

function myFucn(ind){
var ptp = "<c:out value='${myFormBean.myVar[ind]}'/>";// this does not show any thing
//OR
var ptp = "<c:out value='${myFormBean.myVar['+ind+']}'/>";//This beaks the HTML
//OR
var ptp = "<c:out value='${myFormBean.myVar["+ind+"]}'/>";//This beaks the HTML
}

Please help how to get the value from above tag using index as variable. Thanks in advance.


Solution

  • JavaScript is a code running in the Client side, It will only be functional when the Code is executed, I mean Called using a function or Some.!! So i believe its not possible to get the values in the JavaScript from the struts Tag..!!

    The Possible way to do it is by Passing the values as arguments, you can pass the values using

    myFucn(indValue,'<c:out value='${myFormBean.myVar[ind]}'/>','<c:out value='${myFormBean.myVar['+ind+']}'/>','<c:out value='${myFormBean.myVar["+ind+"]}'/>')
    

    By this your function will receive this values in the Script function.