title: Struts 2 dynamic variables
body: <p>I'm trying to create a dynamic variable in Struts2 using set tag </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:set var="myNum" value="numConst" /&gt;
  &lt;s:set var="number" value="%{getText('@xxx.CommonConstant@'+#myNum)}" /&gt;
  </code></pre>
  
  <p><code>numConst</code> will return a dynamic value that retrieved from database. For example, if the value is NINE then number should be <code>@xxx.CommonConstant@NINE</code></p>
  
  <p>I have set the value in my java class so that <code>@xxx.CommonConstant@NINE</code> will return <code>9</code>.</p>
  
  <p>So far, the value can be displayed with no problem in text tag if I use</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:text name="%{getText(#number)}" /&gt; 
  </code></pre>
  
  <p>It will return <code>9</code> but it displayed incorrectly when I tried using property tag</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:property value="%{getText(#number)}" /&gt; 
  &lt;s:property value="%{#number}" /&gt;
  &lt;s:property value="#number" /&gt;
  &lt;s:property value="%{getText('%{getText(#number)}')}" /&gt;
  </code></pre>
  
  <p>Which all of the above examples will give me the value as <code>@xxx.CommonConstant@NINE</code>. The reason I try to get the value from property tag is because I want to copy the correct way on how to display the value so I can use them in if tag like below examples:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:if test="#number == 9"&gt;
     do something
  &lt;/s:if&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:if test="%{getText(#number)} == 9"&gt;
     do something
  &lt;/s:if&gt;
  </code></pre>
  
  <p><strong>CommonConstant:</strong></p>
  
  <pre><code>package xxx;
  
  public abstract class CommonConstant {
      public static final int NINE = 9;
      public static final int NINEONE = 91;
      public static final double ADMIN_PGM = 1.4;
      // ... omitted ... 
  }
  </code></pre>
  
  <p>Can anybody help me?</p>