struts2 - <s:property/> value in JavaScript giving error -
i trying access <s:property value="names"/>
values in javascript getting error. here names list. tried put <s:property value="names"/>
in variable still not converting array. not sure going wrong . have put in javascript in jsp page. evaluated value of <s:property value="names"/>
coming [abc,xyz]
. appreciated! code:
<script type="text/javascript"> $(document).ready(function() { var temp= new array(); temp=<s:property value="names"/>; }); </script>
while debugging shows:
<script type="text/javascript"> $(document).ready(function() { var temp= new array(); temp=[xyz,abc]; }); </script>
its gives error xyz undefined.
you can try this
< script type="text/javascript" > $(document).ready(function() { var temp= new array(); <s:iterator id="names" value="names" status="stat"> temp.push("<s:property/>"); </s:iterator> }); < / script>
in action class
private list<string> names; @override public string execute() throws exception { names=new arraylist<string>(); names.add("xyz"); names.add("abc"); } public void setnames(list<string> names) { this.names = names; } public list<string> getnames() { return names; }
Comments
Post a Comment