简体   繁体   中英

Redirect attribute of actionforward does not work in struts portlet bridge based portlet (JSR-168)

I did a lot of researching on the matter but cannot seem to find the answer to my question, so I hope you guys can help me out.

We have a struts 1.2.7 web app that we converted to a JSR-168 portlet using the Apache Struts Portlet Bridge.

This is all working very well except for one thing: the actionforwards that specify a redirect do not actually redirect to the specified action. These redirects DO work when running the app as a normal struts web app. Hence, we have a double submit problem in the portlet variant.

We make use of action chaining that ends with an action forwarding to a tile definition. For example:

<action path="/CreateIdmAccountSubmit"  validate="true"   input="catalog.createaccount.page" type="com.konakart.actions.login.CreateIdmAccountSubmitAction" name="CreateIdmAccountForm">
        <forward name="FillRegistrationData" path="/FillRegistrationData.do" redirect="true"/>
    </action>

<action path="/FillRegistrationData" validate="false" type="com.konakart.actions.registration.FillRegistrationDataAction" name="FillRegistrationDataForm">
        <forward name="FillRegistrationDataPage" path="/FillRegistrationDataPage.do" redirect="false"/>
    </action>

<action path="/FillRegistrationDataPage" forward="order.registrationdata.page"/> (tiles-def)

In this example the action /CreateIdmAccountSubmit processes a submitted form (POST) and creates an account in the db. After successfull creation the user is redirected to another action ( /FillRegistrationData ) which inits an order object and, on its turn, forwards to the orderregistration page which layout is defined in the tiles-defs.xml.

As I said this all works very well, form a functional perspective, but when a user hits f5 on the rendered order-registration-page the action /CreateIdmAccountSubmit is again invoked causing the account to be created double. As I said also this is not happening when running the app as a normal web app. Here, the mechanism works perfectly :)

I think that the problem is being caused by the fact that the redirect is done in the wrong phase but i am really not sure as why this does not work :)

Based on what I read I tried the fowllowing things to fix the redirect problem: * specified the action that does the form submit as "actionUrl" in struts-portlet-config.xml (hoping that redirect is done in wrong phase?) * replaced the normal html tag library by the struts-portlet variant (hoping that a valid url actionUrl was produced by my html:form that in some way made the redirect possible?)

These two steps did not seem to help and I am lost at how to accomplish a simple redirect in the portlet so that we can prevent the double submit problem.

Hope you guys can help me out!

I found the answer: the mechanism is dependent on the portal implementation. We use Liferay which does not work with redirects by default.

However, you can switch this on by declaring an element in liferay-portlet.xml called

<action-url-redirect>true</action-url-redirect>

This fixed the problem for us!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM