0

in jsp file.

    <% java.util.Vector <HighlightVO> conditions = bean.getPropVector("HighlightVOList");%>

    <script language="JavaScript">
    var conditions = []; 
        <% for(HighlightVO highlightVO : conditions){ %>
        conditions.push(<%=highlightVO%>); // not working.
        <%}%>

</script>

i am not able to add the highlighVO in conditions[].

Can any one help to do this operations.

  • Define `not working`. Is an error shown in your console ? – Weedoze Apr 12 '17 at 07:21
  • 1
    Refer the below link,this might helps [http://stackoverflow.com/questions/6577246/how-to-access-a-java-object-in-javascript-from-jsp](http://stackoverflow.com/questions/6577246/how-to-access-a-java-object-in-javascript-from-jsp) – Porkko M Apr 12 '17 at 07:24
  • Invalid or unexpected token – Maulin Patel Apr 12 '17 at 07:58

1 Answers1

1

The parameters of javascript push must be understanded by javascript. If you look at the javascript code generated, you will probably see something like :

    conditions.push(HighlightVO@6d06d69c)

which is not understanded by javascript.

A solution is to implement the toString() method of HighlightVO in order to return the object in json format.

Adding toString method in HighlightVO class :

  public String toString()
  {
    return '{'+
           'field1:'+field1+','+
           'field2:'+field2+','+
           ...
           '}';
  }

will generate :

conditions.push({field1:1,
                 field2:'2', ...})
L. Carbonne
  • 471
  • 5
  • 10