title: Dynamic javascript variables using struts property
body: <p>How can I achieve something like mentioned below?</p>
  
  <pre><code>     var filterValues_&lt;s:property value="moduleid"&gt; = {
                  "books" :
                      [
                       ["All","All"]
                       &lt;s:if test="bookNames != null &amp;&amp; bookNames.size != 0"&gt;
                       ,
                           &lt;s:iterator value="bookNames" status="state" &gt;
                               ["&lt;s:property/&gt;", "&lt;s:property/&gt;"]
                               &lt;s:if test="!#state.last"&gt;,&lt;/s:if&gt;
                           &lt;/s:iterator&gt;
                       &lt;/s:if&gt;    
                      ]
       }
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>var tmp = {};
  var tmp["filterValues_&lt;s:property value="moduleid"&gt;"] = {
              "books" :
                  [
                   ["All","All"]
                   &lt;s:if test="bookNames != null &amp;&amp; bookNames.size != 0"&gt;
                   ,
                       &lt;s:iterator value="bookNames" status="state" &gt;
                           ["&lt;s:property/&gt;", "&lt;s:property/&gt;"]
                           &lt;s:if test="!#state.last"&gt;,&lt;/s:if&gt;
                       &lt;/s:iterator&gt;
                   &lt;/s:if&gt;    
                 ]
      }
  </code></pre>
  
  <p>This works but is there any other way where i can have the name of the variable created dynamically using struts property tag?</p>
  
  <p>I am displaying multiple gadget in my web page. UI code for each gadget goes into separate files. Each gadget can be added to the page multiple times and every gadgets gets a moduleid. using a normal variable name like "filterValues" causes the variable to be shared across gadgets, which i don't want. (how the script is loaded is a third party thing. I just fill in a template with code and rest is done by third party wars)</p>