Search code examples
jspstruts2struts-1

What is the equivalent Struts 2 tag for the following Struts 1 tag?


I'm migrating from Struts 1 to Struts 2. I don't know what is the equivalent Struts2 tag for the following struts1 tag

 <logic:equal value="1234" name="custDetail" property="ackMsg">
      <% String str = valid %>
 </logic:equal>

The custDetail attribute that is set in the request should have the value 1234. if so the script variable str assigned 'valid' as its value. what is the equivalent JSP code using Struts2 tags


Solution

  • Struts 1:

    <logic:equal value="1234" name="custDetail" property="ackMsg">
        <% String str = "valid" %>
    </logic:equal>
    

    Struts 2 :

    <s:if test="custDetail.ackMsg == '1234'">
        <% String str = "valid" %>
    </s:if>
    

    Struts 2 refactored to remove the scriptlet:

    <s:if test="custDetail.ackMsg == '1234'">
        <s:set var="str" value="%{'valid'}"/>
    </s:if>
    

    , and get the str value later with:

    <s:property value="%{#str}" />