java - javascript error when accesssing flash redirect attribute (thymeleaf, springmvc) -
i'm stuck following problem springmvc, thymeleaf , javascript.
1) server-side: under circumstances add flash redirect attribute in controller before redirecting page.
redirectattributes.addflashattribute("mycondition", true);
2) client-side: in case attribute exists, want javascript function execute additional code.
window.onload = function() { ... if([[${mycondition}]]) { //do } }
this works fine after redirect, on first enter redirect attribute not exist, results in following javascript code being rendered:
window.onload = function() { if() { //do } }
this code not valid , therefore produces javascript error. i'm not sure how check javascript if redirect attribute exists? has run similar problem before?
can try following code , let me know if works declare variable mycondition
var mycondition = [[${mycondition}]]; if(mycondition) { //do }
hope helps
Comments
Post a Comment