-4

I have an ArrayList which contains Object in my ManagedBean like below

List<TargetData> targetList=new ArraList<TargetData>();

i want to take this list in javascript like below

var list = "#{settingsBean.targetist}";

I tried to iterate like

    for(var i=0;i<list.length;i++){
}

But i am unable to iterate list in javascript.Can any one pz help me.How can i iterate the above list in javascript

2
  • 6
    you don't put java into javascript. You serialize your java stuff into JSON, and embed that into javascript. json IS javascript, so essentially you'd be converting your java object into its javascript representation Commented Dec 22, 2014 at 18:08
  • possible duplicate of How to loop through Java List<Object[]> object in JavaScript? Commented Dec 22, 2014 at 23:28

3 Answers 3

0

You need to convert it into a JSON format from the Java end and then read it in on the Javascript side. You can do so through this link here

https://stackoverflow.com/a/20499541/3421811

Sign up to request clarification or add additional context in comments.

Comments

0

Normally, Java and Javascript don't execute on the same machines - Java executes on the server, and Javascript on the client. So your client is never going to be able to interate over your bean unless you send it via web sockets.

Comments

0

You should not be mixing them together as they two are entirely different from each other. Whatever we are doing in javascript we are doing it on the client(browser) and whatever is being done in java its being done in jvm or server. As above posts suggests either convert your list in json and send the json which you can parse in javascript. Or if you are using it on web with some framework like tiles then you can simply return your list to your tile -> iterate it and then return the complete jsp content to your ajax method which you can render on the page .

Hope this be of some help.

Happy Learning :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.