Search code examples
jspstruts2strutsjsp-tagsognl

Correct syntax to convert struts1 logic tag to Struts2 if tag


I am working on migrating struts to struts2 application and I am not sure if I have the correct syntax. I have this struts1 logic tag used:

<logic:equal name="myForm" property="fromWhere"
    scope="request" value="search">
<app:pageBanner/>

And I have converted this to Struts2 as followed:

<s:if test="%{myForm.fromWhere == \"search\"}">

My doubt is in the use of the name="myForm" along with the property="fromWhere" inside the if tag.

I have reviewed most websites that come up in Google when you search for Migrating Struts1 to Struts2, Struts2 tags, and a few more so if anyone knows of sites providing more details on how to work with this tags including examples, or help with migrating from struts1 to struts2, please post them along. I will appreciate it.

Thank you for taking time to respond.


Solution

  • Inside the s:if tag you shouldn't use the name="myForm" along with the property="fromWhere". The correct syntax

    <s:if test="myForm.fromWhere == 'search'">
    

    The myForm should be an action class variable that have a public getter getMyForm() to access this variable from the view and evaluate the OGNL expression in the test attribute.

    Examples you can find here.