NoNaMe
NoNaMe

Reputation: 6232

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.

Upvotes: 1

Views: 3860

Answers (2)

Dileep
Dileep

Reputation: 5440

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.

Upvotes: 1

Felix
Felix

Reputation: 269

I guess you mixed the client-side code and server-side code. The "tag" is like you go shopping but there's no shopkeeper, you have to explicitly pick the one you want, not the way you ask for one item based on some criteria you provided.

If I understand your problem correctly, I would suggest create a function with ajax to retrieve desired data and set them on your HTML page.

Upvotes: 0

Related Questions