While migrating Struts 1 to Struts 2, the FormTag class in Struts 2 is missing a getOnsubmit method

300 Views Asked by At

I am doing a Struts 1 to Struts 2 migration. We have Struts 1 code that has extended and customised the org.apache.struts.taglib.html.FormTag. Did some search and found that the org.apache.struts2.views.jsp.ui.FormTag is the equivalent in Struts2.

My current Struts 1 code modifies the onsubmit variable of the FormTag by calling the setOnsubmit(), but it does that by first doing a getOnsubmit() like below.

    if (this.getOnsubmit() == null) {
        this.setOnsubmit(subCmd + subCmdEnd);
    }
    else {
        this.setOnsubmit(subCmd + this.getOnsubmit() + subCmdEnd);
    }

The Struts 2 class has the setOnsubmit(), but not the getOnsubmit(). Do we have any other option available to read the onsubmit value?

1

There are 1 best solutions below

1
Roman C On BEST ANSWER

The <s:form> tag belongs to Struts 2 core tag library. So, if you need to use your own tag that extends this one then you should extend org.apache.struts2.views.jsp.ui.FormTag class and provide your own implementation by overriding public methods, and adding additional methods. The onsubmit field has a protected modifyer.

But before doing any changes to the Struts 2 framework ask an advice from qualifyed experts: why do you need to do it? For carrying the old code to the new one? The code that is written for S1 is incompatible with S2.

onsubmit is a HTML attribute of the HTML <form> tag, and it could be set in the any other ways on the server, i.e. using OGNL, or on the client using JavaScript.

Also when migrating from Struts1 to Struts 2 you should read Struts 1 to Struts 2 migration strategy.