1

i have a bean class WordBean with the following structure

public class WordBean 
{
    public WordList getWordList() 
    {
        return wordList;
    }
    public void setWordList(WordList wordList) 
    {
        this.wordList= wordList;
    }
}

WordList class with the following structure

public class WordList 
        {
            private List itemList = new ArrayList();

            public void setItemList(List itemList ) 
            {
               this.itemList = itemList ;
            }   

            public List getItemList() 
            {
              return itemList;
            }
         }

In my javascript , i need to get the retrieve the list itemList to do some validations

var items = document.WordBean.WordList.itemList;

But i am not getting any values here ?

so kindly suggest on the better syntax to retrieve the List?

3
  • Things on the server-side are not accessible from the client side - you'll need to print them to the client. You also shouldn't be doing validations on the client side. Commented Apr 21, 2015 at 7:03
  • 1
    @EvanKnowles Well, he shouldn't be doing validations ONLY on the client side. Commented Apr 21, 2015 at 7:06
  • Indeed. @meskobalazs's answer is what you're looking for. Just look up EL. Commented Apr 21, 2015 at 7:10

1 Answer 1

2

You can't just use a Java variable in JavaScript! However you can print the variable in the rendering phase of JSP, and it becomes a literal from the perspective of JavaScript. So e.g. with Spring EL, you can do this:

var items = ${wordBean.wordList.itemList};

And this would render as something like this:

var items = ['wordOne', 'wordTwo'];
Sign up to request clarification or add additional context in comments.

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.